Skip to content

Commit 7b64d5c

Browse files
committed
some cleanup per PR 515 comments
1 parent c8869dc commit 7b64d5c

File tree

6 files changed

+88
-44
lines changed

6 files changed

+88
-44
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let excludeFiles: String = []
1414
let package = Package(
1515
name: "Web3swift",
1616
platforms: [
17-
.macOS(.v10_12), .iOS(.v15)
17+
.macOS(.v12), .iOS(.v15)
1818
],
1919
products: [
2020
.library(name: "web3swift", targets: ["web3swift"])

Sources/Linting.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/web3swift/Web3/Web3+HttpProvider.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public class Web3HttpProvider: Web3Provider {
3030
}()
3131
public init?(_ httpProviderURL: URL, network net: Networks? = nil, keystoreManager manager: KeystoreManager? = nil) async {
3232
do {
33-
guard httpProviderURL.scheme == "http" || httpProviderURL.scheme == "https" else {return nil}
33+
guard httpProviderURL.scheme == "http" || httpProviderURL.scheme == "https" else {
34+
return nil
35+
}
3436
url = httpProviderURL
3537
if net == nil {
3638
let request = JSONRPCRequestFabric.prepareRequest(.getNetwork, parameters: [])
@@ -43,7 +45,9 @@ public class Web3HttpProvider: Web3Provider {
4345
}
4446
guard let result: String = response.getValue(), let intNetworkNumber = Int(result) else {return nil}
4547
network = Networks.fromInt(intNetworkNumber)
46-
if network == nil {return nil}
48+
if network == nil {
49+
return nil
50+
}
4751
} else {
4852
network = net
4953
}

Tests/web3swiftTests/localTests/web3swiftBasicLocalNodeTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class web3swiftBasicLocalNodeTests: XCTestCase {
4949
}
5050

5151
func testEthSendExampleWithRemoteSigning() async throws {
52-
let web3 = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
52+
let web3 = try await Web3.new(URL(string: "http://127.0.0.1:8545")!)
5353
let allAddresses = try await web3.eth.getAccounts()
5454
let sendToAddress = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")!
5555
let contract = web3.contract(Web3.Utils.coldWalletABI, at: sendToAddress, abiVersion: 2)!
Lines changed: 72 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,74 @@
1-
//// web3swift
2-
////
3-
//// Created by Alex Vlasov.
4-
//// Copyright © 2018 Alex Vlasov. All rights reserved.
5-
////
1+
// web3swift
62
//
7-
//import XCTest
3+
// Created by Alex Vlasov.
4+
// Copyright © 2018 Alex Vlasov. All rights reserved.
85
//
9-
//@testable import web3swift
10-
//
11-
//class web3swiftEventloopTests: XCTestCase {
12-
//
13-
// func testBasicEventLoop() async throws {
14-
// let expectation = self.expectation(description: "Waiting")
15-
// @Sendable func getBlockNumber(_ web3: web3) async {
16-
// do {
17-
// let blockNumber = try await web3.eth.getBlockNumber()
18-
// print("Block number = " + String(blockNumber))
19-
// expectation.fulfill()
20-
// } catch {
21-
// print(error)
22-
// }
23-
// }
24-
//
25-
// let web3main = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
26-
// async let functionToCall: web3.Eventloop.EventLoopCall = getBlockNumber
27-
// let monitoredProperty = await web3.Eventloop.MonitoredProperty.init(name: "onNewBlock", calledFunction: functionToCall)
28-
// web3main.eventLoop.monitoredProperties.append(monitoredProperty)
29-
// web3main.eventLoop.start(5)
30-
//
31-
// await waitForExpectations(timeout: 60, handler: nil)
32-
// }
33-
//
34-
// func getKeystoreData() -> Data? {
35-
// let bundle = Bundle(for: type(of: self))
36-
// guard let path = bundle.path(forResource: "key", ofType: "json") else {return nil}
37-
// guard let data = NSData(contentsOfFile: path) else {return nil}
38-
// return data as Data
39-
// }
40-
//
41-
//}
6+
7+
import XCTest
8+
9+
@testable import web3swift
10+
//TODO: refactor me
11+
class web3swiftEventloopTests: XCTestCase {
12+
13+
func testBasicEventLoop() async throws {
14+
var ticksToWait = 5
15+
let expectation = self.expectation(description: "Waiting")
16+
func getBlockNumber(_ web3: web3) async {
17+
do {
18+
let blockNumber = try await web3.eth.getBlockNumber()
19+
print("Block number = " + String(blockNumber))
20+
ticksToWait = ticksToWait - 1
21+
if ticksToWait == 0 {
22+
expectation.fulfill()
23+
}
24+
} catch {
25+
print(error)
26+
}
27+
}
28+
29+
let web3main = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
30+
let functionToCall: web3.Eventloop.EventLoopCall = getBlockNumber
31+
let monitoredProperty = web3.Eventloop.MonitoredProperty.init(name: "onNewBlock", calledFunction: functionToCall)
32+
web3main.eventLoop.monitoredProperties.append(monitoredProperty)
33+
web3main.eventLoop.start(5)
34+
35+
await waitForExpectations(timeout: 60, handler: nil)
36+
}
37+
38+
// func testNonceMiddleware() throws {
39+
// let web3 = try Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
40+
// let middleware = Web3.Utils.NonceMiddleware()
41+
// middleware.attach(web3)
42+
43+
// let sendToAddress = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")!
44+
// let ksData = getKeystoreData()
45+
// FIXME: Ganache crash here
46+
// let tempKeystore = EthereumKeystoreV3(ksData!)
47+
// let keystoreManager = KeystoreManager([tempKeystore!])
48+
// web3.addKeystoreManager(keystoreManager)
49+
50+
// var tx = web3.eth.sendETH(to: sendToAddress, amount: 1000)
51+
// tx!.transactionOptions.from = tempKeystore!.addresses!.first!
52+
// var result = try! tx!.send(password: "web3swift")
53+
// let newNonce = result.transaction.nonce
54+
// sleep(1)
55+
// let hookNewNonce = middleware.nonceLookups[tempKeystore!.addresses!.first!]!
56+
// XCTAssertEqual(newNonce, hookNewNonce)
57+
58+
// tx = web3.eth.sendETH(to: sendToAddress, amount: 1000)
59+
// tx!.transactionOptions.from = tempKeystore!.addresses!.first!
60+
// result = try! tx!.send(password: "web3swift")
61+
// sleep(1)
62+
// let newNonce2 = result.transaction.nonce
63+
// let hookNewNonce2 = middleware.nonceLookups[tempKeystore!.addresses!.first!]!
64+
// XCTAssert(newNonce2 == hookNewNonce2)
65+
// }
66+
67+
func getKeystoreData() -> Data? {
68+
let bundle = Bundle(for: type(of: self))
69+
guard let path = bundle.path(forResource: "key", ofType: "json") else {return nil}
70+
guard let data = NSData(contentsOfFile: path) else {return nil}
71+
return data as Data
72+
}
73+
74+
}

Tests/web3swiftTests/localTests/web3swiftPromisesTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class web3swiftPromisesTests: XCTestCase {
119119
}
120120

121121
func testSendETHPromise() async throws {
122-
let web3 = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
122+
let web3 = try await Web3.new(URL(string: "http://127.0.0.1:8545")!)
123123
let allAddresses = try await web3.eth.getAccounts()
124124
let gasPrice = try await web3.eth.getGasPrice()
125125
let sendToAddress = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")!

0 commit comments

Comments
 (0)