Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add previewnet #17

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,7 +1,7 @@
//
// FlowChainID
//
// Copyright 2022 Outblock Pty Ltd

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

View workflow job for this annotation

GitHub Actions / lint

File Header Violation: Header comments should be consistent with project patterns (file_header)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,12 +37,16 @@
/// Canarynet enviroment
/// Default node is `access.canary.nodes.onflow.org:9000`
case canarynet

Check warning on line 40 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)
/// Canarynet enviroment
/// 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 @@
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 @@
return "testnet"
case .crescendo:
return "crescendo"
case .previewnet:
return "previewnet"
case .canarynet:
return "canarynet"
case .emulator:
Expand Down Expand Up @@ -98,6 +104,8 @@
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 @@
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
Loading