@@ -11,38 +11,28 @@ class LocalTestCase: XCTestCase {
1111
1212 static let url = URL ( string: " http://127.0.0.1:8545 " ) !
1313
14- static var isSetUp = false
14+ override func setUp( ) async throws {
15+ let web3 = try ! await Web3 . new ( LocalTestCase . url)
1516
16- override class func setUp ( ) {
17- super . setUp ( )
17+ let block = try ! await web3 . eth . blockNumber ( )
18+ if block >= 25 { return }
1819
19- Task {
20- // check to see if we need to run the one-time setup
21- if isSetUp { return }
22- isSetUp = true
20+ print ( " \n ****** Preloading Ganache ( \( 25 - block) blocks) ***** \n " )
2321
24- let web3 = try ! await Web3 . new ( LocalTestCase . url)
22+ let allAddresses = try ! await web3. eth. ownedAccounts ( )
23+ let sendToAddress = allAddresses [ 0 ]
24+ let contract = web3. contract ( Web3 . Utils. coldWalletABI, at: sendToAddress, abiVersion: 2 )
25+ let value = Utilities . parseToBigUInt ( " 1.0 " , units: . eth)
2526
26- let block = try ! await web3. eth. blockNumber ( )
27- if block >= 25 { return }
27+ let from = allAddresses [ 0 ]
28+ let writeTX = contract!. write ( " fallback " ) !
29+ writeTX. transactionOptions. from = from
30+ writeTX. transactionOptions. value = value
31+ writeTX. transactionOptions. gasLimit = . manual( 78423 )
32+ writeTX. transactionOptions. gasPrice = . manual( 20000000000 )
2833
29- print ( " \n ****** Preloading Ganache ( \( 25 - block) blocks) ***** \n " )
30-
31- let allAddresses = try ! await web3. eth. ownedAccounts ( )
32- let sendToAddress = allAddresses [ 0 ]
33- let contract = web3. contract ( Web3 . Utils. coldWalletABI, at: sendToAddress, abiVersion: 2 )
34- let value = Utilities . parseToBigUInt ( " 1.0 " , units: . eth)
35-
36- let from = allAddresses [ 0 ]
37- let writeTX = contract!. write ( " fallback " ) !
38- writeTX. transactionOptions. from = from
39- writeTX. transactionOptions. value = value
40- writeTX. transactionOptions. gasLimit = . manual( 78423 )
41- writeTX. transactionOptions. gasPrice = . manual( 20000000000 )
42-
43- for _ in block..< 25 {
44- let _ = try ! await writeTX. send ( password: " " )
45- }
34+ for _ in block..< 25 {
35+ let _ = try ! await writeTX. send ( password: " " )
4636 }
4737 }
4838}
0 commit comments