Skip to content

Commit cc3d1ed

Browse files
LocalTestCase async fix
1 parent 4ff063c commit cc3d1ed

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

Tests/web3swiftTests/localTests/LocalTestCase.swift

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,38 @@ import web3swift
88
// while this class does show up in the navigator, it has no associated tests
99
class LocalTestCase: XCTestCase {
1010
static let url = URL.init(string: "http://127.0.0.1:8545")!
11-
let ganache = try! Web3.new(LocalTestCase.url)
1211
static var isSetUp = false
1312

1413
override class func setUp() {
1514
super.setUp()
1615

17-
// check to see if we need to run the one-time setup
18-
if isSetUp { return }
19-
isSetUp = true
16+
Task {
17+
// check to see if we need to run the one-time setup
18+
if isSetUp { return }
19+
isSetUp = true
2020

21-
let web3 = try! Web3.new(LocalTestCase.url)
21+
let web3 = try! await Web3.new(LocalTestCase.url)
2222

23-
let block = try! web3.eth.getBlockNumber()
24-
if block >= 25 { return }
23+
let block = try! await web3.eth.getBlockNumber()
24+
if block >= 25 { return }
2525

26-
print("\n ****** Preloading Ganache (\(25 - block) blocks) *****\n")
26+
print("\n ****** Preloading Ganache (\(25 - block) blocks) *****\n")
2727

28-
let allAddresses = try! web3.eth.getAccounts()
29-
let sendToAddress = allAddresses[0]
30-
let contract = web3.contract(Web3.Utils.coldWalletABI, at: sendToAddress, abiVersion: 2)
31-
let value = Web3.Utils.parseToBigUInt("1.0", units: .eth)
28+
let allAddresses = try! await web3.eth.getAccounts()
29+
let sendToAddress = allAddresses[0]
30+
let contract = web3.contract(Web3.Utils.coldWalletABI, at: sendToAddress, abiVersion: 2)
31+
let value = Web3.Utils.parseToBigUInt("1.0", units: .eth)
3232

33-
let from = allAddresses[0]
34-
let writeTX = contract!.write("fallback")!
35-
writeTX.transactionOptions.from = from
36-
writeTX.transactionOptions.value = value
37-
writeTX.transactionOptions.gasLimit = .manual(78423)
38-
writeTX.transactionOptions.gasPrice = .manual(20000000000)
33+
let from = allAddresses[0]
34+
let writeTX = contract!.write("fallback")!
35+
writeTX.transactionOptions.from = from
36+
writeTX.transactionOptions.value = value
37+
writeTX.transactionOptions.gasLimit = .manual(78423)
38+
writeTX.transactionOptions.gasPrice = .manual(20000000000)
3939

40-
for _ in block..<25 {
41-
let _ = try! writeTX.sendPromise(password: "").wait()
40+
for _ in block..<25 {
41+
let _ = try! await writeTX.send(password: "")
42+
}
4243
}
4344
}
4445
}

0 commit comments

Comments
 (0)