Skip to content

Commit

Permalink
Merge pull request #17 from Outblock/feature/preview
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcmz authored Mar 28, 2024
2 parents ac9b3f5 + 48bdd68 commit 123c01a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ https://outblock.github.io/flow-swift/
This is a Swift Package, and can be installed via Xcode with the URL of this repository:

```swift
.package(name: "Flow", url: "https://github.com/outblock/flow-swift.git", from: "0.3.4")
.package(name: "Flow", url: "https://github.com/outblock/flow-swift.git", from: "0.3.6")
```

## Config
Expand Down
14 changes: 12 additions & 2 deletions Sources/Models/FlowChainId.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public extension Flow {
/// Default node is `access.crescendo.nodes.onflow.org:9000`
/// HTTP node `https://rest-crescendo.onflow.org/`
case crescendo


Check warning on line 45 in Sources/Models/FlowChainId.swift

View workflow job for this annotation

GitHub Actions / lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
/// Previewnet enviroment
/// Default node is `access-previewnet.onflow.org/:9000`
/// HTTP node `https://rest-previewnet.onflow.org/`
case previewnet
/// Emulator enviroment
/// Default node is `127.0.0.1:9000`
case emulator
Expand All @@ -51,7 +55,7 @@ public extension Flow {
case custom(name: String, transport: Flow.Transport)

/// List of other type chain id exclude custom type
public static var allCases: [Flow.ChainID] = [.mainnet, .testnet, .canarynet, .crescendo, .emulator]
public static var allCases: [Flow.ChainID] = [.mainnet, .testnet, .canarynet, .crescendo,.previewnet, .emulator]

Check warning on line 58 in Sources/Models/FlowChainId.swift

View workflow job for this annotation

GitHub Actions / lint

Comma Spacing Violation: There should be no space before and one after any comma (comma)

/// Name of the chain id
public var name: String {
Expand All @@ -62,6 +66,8 @@ public extension Flow {
return "testnet"
case .crescendo:
return "crescendo"
case .previewnet:
return "previewnet"
case .canarynet:
return "canarynet"
case .emulator:
Expand Down Expand Up @@ -98,6 +104,8 @@ public extension Flow {
return .HTTP(URL(string: "http://127.0.0.1:8888/")!)
case .crescendo:
return .HTTP(URL(string: "https://rest-crescendo.onflow.org/")!)
case .previewnet:
return .HTTP(URL(string: "https://rest-previewnet.onflow.org/")!)
case let .custom(_, transport):
return transport
default:
Expand All @@ -116,6 +124,8 @@ public extension Flow {
return .gRPC(.init(node: "access.canary.nodes.onflow.org", port: 9000))
case .crescendo:
return .gRPC(.init(node: "access.crescendo.nodes.onflow.org", port: 9000))
case .previewnet:
return .gRPC(.init(node: "access-previewnet.onflow.org", port: 9000))
case .emulator:
return .gRPC(.init(node: "127.0.0.1", port: 9000))
case let .custom(_, endpoint):
Expand Down
15 changes: 12 additions & 3 deletions Sources/Network/UserAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
//

import Foundation
#if os(iOS)
import UIKit

#elseif os(macOS)
import AppKit
#endif
// eg. Darwin/16.3.0
var DarwinVersion: String {
var darwinVersion: String {
var sysinfo = utsname()
uname(&sysinfo)
let dv = String(bytes: Data(bytes: &sysinfo.release, count: Int(_SYS_NAMELEN)), encoding: .ascii)!.trimmingCharacters(in: .controlCharacters)
Expand All @@ -25,8 +28,14 @@ var CFNetworkVersion: String {

// eg. iOS/10_1
var deviceVersion: String {
#if os(iOS)
let currentDevice = UIDevice.current
return "\(currentDevice.systemName)/\(currentDevice.systemVersion)"
#elseif os(macOS)
let info = ProcessInfo.processInfo
return "macOS/\(info.operatingSystemVersion.majorVersion).\(info.operatingSystemVersion.minorVersion).\(info.operatingSystemVersion.patchVersion)"
#endif

}

// eg. iPhone5,2
Expand All @@ -46,4 +55,4 @@ var appNameAndVersion: String {
return "\(name)/\(version)"
}

let userAgent = "\(appNameAndVersion) \(deviceName) \(deviceVersion) \(CFNetworkVersion) \(DarwinVersion)"
let userAgent = "\(appNameAndVersion) \(deviceName) \(deviceVersion) \(CFNetworkVersion) \(darwinVersion)"
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import CryptoKit
import Foundation
import XCTest

final class FlowAccessAPIOnSandboxTests: XCTestCase {
final class FlowAccessAPIOnPreviewnetTests: XCTestCase {
var flowAPI: FlowAccessProtocol!

override func setUp() {
super.setUp()
flowAPI = flow.createHTTPAccessAPI(chainID: .sandboxnet)
flow.configure(chainID: .sandboxnet)
flowAPI = flow.createHTTPAccessAPI(chainID: .previewnet)
flow.configure(chainID: .previewnet)
}

func testFlowPing() async throws {
Expand All @@ -27,7 +27,7 @@ final class FlowAccessAPIOnSandboxTests: XCTestCase {

func testNetworkParameters() async throws {
let chainID = try await flowAPI.getNetworkParameters()
XCTAssertEqual(chainID, Flow.ChainID.sandboxnet)
XCTAssertEqual(chainID, Flow.ChainID.previewnet)
}

func testFlowAccount() async throws {
Expand Down
8 changes: 4 additions & 4 deletions Tests/FlowAddressTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ final class FlowAddressTest: XCTestCase {
XCTAssertEqual(true, isVaild)
}

func testAddressHexTypeSandboxnet() async throws {
let isVaild = await flow.isAddressVaildate(address: "0x4e8e130b4fb9aee2", network: .sandboxnet)
XCTAssertEqual(true, isVaild)
}
// func testAddressHexTypeSandboxnet() async throws {
// let isVaild = await flow.isAddressVaildate(address: "0x4e8e130b4fb9aee2", network: .sandboxnet)
// XCTAssertEqual(true, isVaild)
// }

func testAddressHexTypeTestnet() async throws {
let isVaild = await flow.isAddressVaildate(address: "0xc6de0d94160377cd", network: .testnet)
Expand Down

0 comments on commit 123c01a

Please sign in to comment.