@@ -46,9 +46,9 @@ class web3swift_promises_Tests: XCTestCase {
46
46
guard let writeTX = contract? . write ( " fallback " ) else { return XCTFail ( ) }
47
47
writeTX. transactionOptions. from = tempKeystore!. addresses? . first
48
48
writeTX. transactionOptions. value = BigUInt ( " 1.0 " , . eth)
49
- let esimate = try writeTX. estimateGasPromise ( ) . wait ( )
50
- print ( esimate )
51
- XCTAssert ( esimate == 21000 )
49
+ let estimate = try writeTX. estimateGasPromise ( ) . wait ( )
50
+ print ( estimate )
51
+ XCTAssert ( estimate == 21000 )
52
52
} catch {
53
53
print ( error)
54
54
XCTFail ( )
@@ -58,19 +58,44 @@ class web3swift_promises_Tests: XCTestCase {
58
58
func testEstimateGasFixPromise( ) {
59
59
do {
60
60
let web3 = Web3 . InfuraMainnetWeb3 ( )
61
- let sendToAddress = EthereumAddress ( " 0xe22b8979739D724343bd002F9f432F5990879901 " )
62
61
let tempKeystore = try ! EthereumKeystoreV3 ( password: " " )
63
62
let keystoreManager = KeystoreManager ( [ tempKeystore!] )
64
63
web3. addKeystoreManager ( keystoreManager)
65
- let contract = web3. contract ( Web3 . Utils. coldWalletABI, at: sendToAddress, abiVersion: 2 )
66
- guard let writeTX = contract? . write ( " fallback " ) else { return XCTFail ( ) }
67
- writeTX. transactionOptions. from = tempKeystore!. addresses? . first
68
- writeTX. transactionOptions. value = BigUInt ( " 1.0 " , . eth)
69
- writeTX. transactionOptions. gasPrice = . manual( BigUInt ( 100000000 ) )
70
- let esimate = try writeTX. estimateGasPromise ( ) . wait ( )
71
- print ( esimate)
72
- XCTAssert ( esimate == 21000 )
73
- } catch {
64
+
65
+ guard let contractAddress = EthereumAddress ( " 0x28a958cD020efeA3734a0bb36DDdc5F9B872cEa8 " ) ,
66
+ let contract = web3. contract ( Web3 . Utils. estimateGasTestABI,
67
+ at: contractAddress,
68
+ abiVersion: 2 ) else {
69
+ return
70
+ }
71
+
72
+ var options = TransactionOptions . defaultOptions
73
+ let fromAddress = tempKeystore!. addresses? . first
74
+ options. from = fromAddress
75
+
76
+ let amount1 = Web3 . Utils. parseToBigUInt ( " 0.000000000000000001 " , units: . eth) // 1 wei
77
+
78
+ guard let tx1 = contract. write ( " test " ,
79
+ parameters: [ amount1] as [ AnyObject ] ,
80
+ extraData: Data ( ) ,
81
+ transactionOptions: options) else {
82
+ return
83
+ }
84
+ let estimate1 = try tx1. estimateGasPromise ( ) . wait ( )
85
+ print ( estimate1)
86
+
87
+ let amount2 = Web3 . Utils. parseToBigUInt ( " 0.00000005 " , units: . eth) // 50 gwei
88
+
89
+ guard let tx2 = contract. write ( " test " ,
90
+ parameters: [ amount2] as [ AnyObject ] ,
91
+ extraData: Data ( ) ,
92
+ transactionOptions: options) else {
93
+ return
94
+ }
95
+ let estimate2 = try tx2. estimateGasPromise ( ) . wait ( )
96
+ print ( estimate2)
97
+ XCTAssert ( estimate2 - estimate1 <= 22000 )
98
+ } catch {
74
99
print ( error)
75
100
XCTFail ( )
76
101
}
0 commit comments