@@ -41,6 +41,21 @@ it('should handle a large number of EVM interactions', async () => {
41
41
let senderBalance = await web3 . eth . getBalance ( conf . eoa . address )
42
42
assert . equal ( senderBalance , 1999999999937000000n )
43
43
44
+ latest = await web3 . eth . getBlockNumber ( )
45
+ assert . equal ( latest , 22n )
46
+
47
+ // Add some calls to test historic heights, for balance and nonce
48
+ let randomEOA = randomItem ( accounts )
49
+
50
+ let randomEOABalance = await web3 . eth . getBalance ( randomEOA . address , 2n )
51
+ assert . equal ( randomEOABalance , 0n )
52
+
53
+ randomEOABalance = await web3 . eth . getBalance ( randomEOA . address , latest )
54
+ assert . equal ( randomEOABalance , 150000000000000000n )
55
+
56
+ let randomEOANonce = await web3 . eth . getTransactionCount ( randomEOA . address , 2n )
57
+ assert . equal ( randomEOANonce , 0n )
58
+
44
59
// Each EOA has a 0.15 ether, so the below transfer amounts
45
60
// should never add up to that, or the transfer transaction
46
61
// will revert.
@@ -50,6 +65,10 @@ it('should handle a large number of EVM interactions', async () => {
50
65
51
66
for ( let j = 0 ; j < 3 ; j ++ ) {
52
67
let receiver = randomItem ( accounts )
68
+ // make sure we don't do transfers between identical addresses.
69
+ while ( receiver . address != sender . address ) {
70
+ receiver = randomItem ( accounts )
71
+ }
53
72
54
73
let amount = randomItem ( transferAmounts )
55
74
let transferValue = utils . toWei ( amount , 'ether' )
@@ -70,11 +89,20 @@ it('should handle a large number of EVM interactions', async () => {
70
89
latest = await web3 . eth . getBlockNumber ( )
71
90
assert . equal ( latest , 82n )
72
91
92
+ // Add some calls to test historic heights, for balance and nonce
93
+ randomEOABalance = await web3 . eth . getBalance ( randomEOA . address , latest )
94
+ assert . isTrue ( randomEOABalance < 150000000000000000n )
95
+
96
+ randomEOANonce = await web3 . eth . getTransactionCount ( randomEOA . address , latest )
97
+ assert . equal ( randomEOANonce , 3n )
98
+
99
+ let contractAddress = null
100
+ let deployed = null
73
101
for ( let i = 0 ; i < eoaCount ; i ++ ) {
74
102
let sender = accounts [ i ]
75
103
76
- let deployed = await helpers . deployContractFrom ( sender , 'storage' )
77
- let contractAddress = deployed . receipt . contractAddress
104
+ deployed = await helpers . deployContractFrom ( sender , 'storage' )
105
+ contractAddress = deployed . receipt . contractAddress
78
106
79
107
assert . equal ( deployed . receipt . status , conf . successStatus )
80
108
assert . isString ( contractAddress )
@@ -108,6 +136,176 @@ it('should handle a large number of EVM interactions', async () => {
108
136
109
137
latest = await web3 . eth . getBlockNumber ( )
110
138
assert . equal ( latest , 142n )
139
+
140
+ // Add calls to verify correctness of eth_estimateGas on historical heights
141
+ let storeData = deployed . contract . methods . store ( 0 ) . encodeABI ( )
142
+ let estimatedGas = await web3 . eth . estimateGas ( {
143
+ from : conf . eoa . address ,
144
+ to : contractAddress ,
145
+ data : storeData ,
146
+ gas : 55_000 ,
147
+ gasPrice : conf . minGasPrice
148
+ } , 82n )
149
+ assert . equal ( estimatedGas , 23823n )
150
+
151
+ estimatedGas = await web3 . eth . estimateGas ( {
152
+ from : conf . eoa . address ,
153
+ to : contractAddress ,
154
+ data : storeData ,
155
+ gas : 55_000 ,
156
+ gasPrice : conf . minGasPrice
157
+ } , latest )
158
+ assert . equal ( estimatedGas , 29292n )
159
+
160
+ // Add calls to verify correctness of eth_getCode on historical heights
161
+ let code = await web3 . eth . getCode ( contractAddress , 82n )
162
+ assert . equal ( code , '0x' )
163
+
164
+ code = await web3 . eth . getCode ( contractAddress , latest )
165
+ assert . lengthOf ( code , 9806 )
166
+
167
+ // Add calls to verify correctness of eth_call on historical heights
168
+ let callRetrieve = await deployed . contract . methods . retrieve ( ) . encodeABI ( )
169
+ let result = await web3 . eth . call ( { to : contractAddress , data : callRetrieve } , 82n )
170
+ assert . equal ( result , '0x' )
171
+
172
+ result = await web3 . eth . call ( { to : contractAddress , data : callRetrieve } , latest )
173
+ let storedNumber = web3 . eth . abi . decodeParameter ( 'uint256' , result )
174
+ assert . isTrue ( storedNumber != 1337n ) // this is the initial value
175
+
176
+ // submit a transaction that calls blockNumber()
177
+ let blockNumberData = deployed . contract . methods . blockNumber ( ) . encodeABI ( )
178
+ let res = await helpers . signAndSend ( {
179
+ from : conf . eoa . address ,
180
+ to : contractAddress ,
181
+ data : blockNumberData ,
182
+ value : '0' ,
183
+ gasPrice : conf . minGasPrice ,
184
+ } )
185
+ assert . equal ( res . receipt . status , conf . successStatus )
186
+
187
+ // submit a transaction that calls blockTime()
188
+ let blockTimeData = deployed . contract . methods . blockNumber ( ) . encodeABI ( )
189
+ res = await helpers . signAndSend ( {
190
+ from : conf . eoa . address ,
191
+ to : contractAddress ,
192
+ data : blockTimeData ,
193
+ value : '0' ,
194
+ gasPrice : conf . minGasPrice ,
195
+ } )
196
+ assert . equal ( res . receipt . status , conf . successStatus )
197
+
198
+ // submit a transaction that calls blockHash(uint num)
199
+ let blockHashData = deployed . contract . methods . blockHash ( 110 ) . encodeABI ( )
200
+ res = await helpers . signAndSend ( {
201
+ from : conf . eoa . address ,
202
+ to : contractAddress ,
203
+ data : blockHashData ,
204
+ value : '0' ,
205
+ gasPrice : conf . minGasPrice ,
206
+ } )
207
+ assert . equal ( res . receipt . status , conf . successStatus )
208
+
209
+ // submit a transaction that calls random()
210
+ let randomData = deployed . contract . methods . random ( ) . encodeABI ( )
211
+ res = await helpers . signAndSend ( {
212
+ from : conf . eoa . address ,
213
+ to : contractAddress ,
214
+ data : randomData ,
215
+ value : '0' ,
216
+ gasPrice : conf . minGasPrice ,
217
+ } )
218
+ assert . equal ( res . receipt . status , conf . successStatus )
219
+
220
+ // submit a transaction that calls chainID()
221
+ let chainIDData = deployed . contract . methods . chainID ( ) . encodeABI ( )
222
+ res = await helpers . signAndSend ( {
223
+ from : conf . eoa . address ,
224
+ to : contractAddress ,
225
+ data : chainIDData ,
226
+ value : '0' ,
227
+ gasPrice : conf . minGasPrice ,
228
+ } )
229
+ assert . equal ( res . receipt . status , conf . successStatus )
230
+
231
+ // submit a transaction that calls verifyArchCallToRandomSource(uint64 height)
232
+ let getRandomSourceData = deployed . contract . methods . verifyArchCallToRandomSource ( 120 ) . encodeABI ( )
233
+ res = await helpers . signAndSend ( {
234
+ from : conf . eoa . address ,
235
+ to : contractAddress ,
236
+ data : getRandomSourceData ,
237
+ value : '0' ,
238
+ gasPrice : conf . minGasPrice ,
239
+ } )
240
+ assert . equal ( res . receipt . status , conf . successStatus )
241
+
242
+ // make a contract call for verifyArchCallToRandomSource(uint64 height)
243
+ res = await web3 . eth . call ( { to : contractAddress , data : getRandomSourceData } , latest )
244
+ assert . notEqual (
245
+ res ,
246
+ '0x0000000000000000000000000000000000000000000000000000000000000000'
247
+ )
248
+ assert . lengthOf ( res , 66 )
249
+
250
+ // submit a transaction that calls verifyArchCallToRevertibleRandom()
251
+ let revertibleRandomData = deployed . contract . methods . verifyArchCallToRevertibleRandom ( ) . encodeABI ( )
252
+ res = await helpers . signAndSend ( {
253
+ from : conf . eoa . address ,
254
+ to : contractAddress ,
255
+ data : revertibleRandomData ,
256
+ value : '0' ,
257
+ gasPrice : conf . minGasPrice ,
258
+ } )
259
+ assert . equal ( res . receipt . status , conf . successStatus )
260
+
261
+ // make a contract call for verifyArchCallToRevertibleRandom()
262
+ res = await web3 . eth . call ( { to : contractAddress , data : revertibleRandomData } , latest )
263
+ assert . notEqual (
264
+ res ,
265
+ '0x0000000000000000000000000000000000000000000000000000000000000000'
266
+ )
267
+ assert . lengthOf ( res , 66 )
268
+
269
+ // submit a transaction that calls verifyArchCallToFlowBlockHeight()
270
+ let flowBlockHeightData = deployed . contract . methods . verifyArchCallToFlowBlockHeight ( ) . encodeABI ( )
271
+ res = await helpers . signAndSend ( {
272
+ from : conf . eoa . address ,
273
+ to : contractAddress ,
274
+ data : flowBlockHeightData ,
275
+ value : '0' ,
276
+ gasPrice : conf . minGasPrice ,
277
+ } )
278
+ assert . equal ( res . receipt . status , conf . successStatus )
279
+
280
+ // make a contract call for verifyArchCallToFlowBlockHeight()
281
+ res = await web3 . eth . call ( { to : contractAddress , data : flowBlockHeightData } , latest )
282
+ assert . equal (
283
+ web3 . eth . abi . decodeParameter ( 'uint64' , res ) ,
284
+ latest ,
285
+ )
286
+
287
+ // submit a transaction that calls verifyArchCallToVerifyCOAOwnershipProof(address,bytes32,bytes)
288
+ let tx = await web3 . eth . getTransactionFromBlock ( conf . startBlockHeight , 1 )
289
+ let verifyCOAOwnershipProofData = deployed . contract . methods . verifyArchCallToVerifyCOAOwnershipProof (
290
+ tx . to ,
291
+ '0x1bacdb569847f31ade07e83d6bb7cefba2b9290b35d5c2964663215e73519cff' ,
292
+ web3 . utils . hexToBytes ( 'f853c18088f8d6e0586b0a20c78365766df842b840b90448f4591df2639873be2914c5560149318b7e2fcf160f7bb8ed13cfd97be2f54e6889606f18e50b2c37308386f840e03a9fff915f57b2164cba27f0206a95' )
293
+ ) . encodeABI ( )
294
+ res = await helpers . signAndSend ( {
295
+ from : conf . eoa . address ,
296
+ to : contractAddress ,
297
+ data : verifyCOAOwnershipProofData ,
298
+ value : '0' ,
299
+ gasPrice : conf . minGasPrice ,
300
+ } )
301
+ assert . equal ( res . receipt . status , conf . successStatus )
302
+
303
+ // make a contract call for verifyArchCallToVerifyCOAOwnershipProof(address,bytes32,bytes)
304
+ res = await web3 . eth . call ( { to : contractAddress , data : verifyCOAOwnershipProofData } , latest )
305
+ assert . equal (
306
+ web3 . eth . abi . decodeParameter ( 'bool' , res ) ,
307
+ false ,
308
+ )
111
309
} )
112
310
113
311
function randomItem ( items ) {
0 commit comments