1
1
const Web3 = require ( 'web3' )
2
2
const assert = require ( 'assert' )
3
+ const { ASYNC_CALL_ERRORS } = require ( '../../oracle/src/utils/constants' )
3
4
const { user, homeRPC, foreignRPC, amb, validator } = require ( '../../e2e-commons/constants.json' )
4
5
const { uniformRetry } = require ( '../../e2e-commons/utils' )
5
6
const { BOX_ABI , HOME_AMB_ABI , FOREIGN_AMB_ABI , ambInformationSignatures } = require ( '../../commons' )
@@ -26,6 +27,45 @@ const foreignBox = new foreignWeb3.eth.Contract(BOX_ABI, amb.foreignBox, opts)
26
27
const homeBridge = new homeWeb3 . eth . Contract ( HOME_AMB_ABI , amb . home , opts )
27
28
const foreignBridge = new foreignWeb3 . eth . Contract ( FOREIGN_AMB_ABI , amb . foreign , opts )
28
29
30
+ function validateBlock ( web3 , serialized , block ) {
31
+ assert . strictEqual ( serialized . length , 2 + 64 * 12 )
32
+ const values = web3 . eth . abi . decodeParameter (
33
+ '(uint256,bytes32,address,uint256,uint256,bytes32,bytes32,bytes32,bytes32,uint256,uint256,uint256)' ,
34
+ serialized
35
+ )
36
+ assert . strictEqual ( values [ 0 ] , block . number . toString ( ) , 'wrong block number returned' )
37
+ assert . strictEqual ( values [ 1 ] , block . hash , 'wrong block hash returned' )
38
+ assert . strictEqual ( values [ 2 ] , block . miner , 'wrong block miner returned' )
39
+ assert . strictEqual ( values [ 3 ] , block . gasUsed . toString ( ) , 'wrong block gasUsed returned' )
40
+ assert . strictEqual ( values [ 4 ] , block . gasLimit . toString ( ) , 'wrong block gasLimit returned' )
41
+ assert . strictEqual ( values [ 5 ] , block . parentHash , 'wrong block parentHash returned' )
42
+ assert . strictEqual ( values [ 6 ] , block . receiptsRoot , 'wrong block receiptsRoot returned' )
43
+ assert . strictEqual ( values [ 7 ] , block . stateRoot , 'wrong block stateRoot returned' )
44
+ assert . strictEqual ( values [ 8 ] , block . transactionsRoot , 'wrong block transactionsRoot returned' )
45
+ assert . strictEqual ( values [ 9 ] , block . timestamp . toString ( ) , 'wrong block timestamp returned' )
46
+ assert . strictEqual ( values [ 10 ] , block . difficulty , 'wrong block difficulty returned' )
47
+ assert . strictEqual ( values [ 11 ] , block . totalDifficulty , 'wrong block totalDifficulty returned' )
48
+ }
49
+
50
+ function validateTransaction ( web3 , serialized , tx ) {
51
+ assert . strictEqual ( serialized . length , 64 * 13 + tx . input . length + 56 )
52
+ const values = web3 . eth . abi . decodeParameter (
53
+ '(bytes32,uint256,bytes32,uint256,address,address,uint256,uint256,uint256,uint256,bytes)' ,
54
+ serialized
55
+ )
56
+ assert . strictEqual ( values [ 0 ] , tx . hash , 'wrong txHash returned' )
57
+ assert . strictEqual ( values [ 1 ] , tx . blockNumber . toString ( ) , 'wrong tx blockNumber returned' )
58
+ assert . strictEqual ( values [ 2 ] , tx . blockHash . toString ( ) , 'wrong tx blockHash returned' )
59
+ assert . strictEqual ( values [ 3 ] , tx . transactionIndex . toString ( ) , 'wrong tx transactionIndex returned' )
60
+ assert . strictEqual ( values [ 4 ] , tx . from , 'wrong tx from returned' )
61
+ assert . strictEqual ( values [ 5 ] , tx . to , 'wrong tx to returned' )
62
+ assert . strictEqual ( values [ 6 ] , tx . value , 'wrong tx value returned' )
63
+ assert . strictEqual ( values [ 7 ] , tx . nonce . toString ( ) , 'wrong tx nonce returned' )
64
+ assert . strictEqual ( values [ 8 ] , tx . gas . toString ( ) , 'wrong tx gas returned' )
65
+ assert . strictEqual ( values [ 9 ] , tx . gasPrice , 'wrong tx gasPrice returned' )
66
+ assert . strictEqual ( values [ 10 ] , tx . input , 'wrong tx data returned' )
67
+ }
68
+
29
69
describe ( 'arbitrary message bridging' , ( ) => {
30
70
let requiredSignatures = 1
31
71
before ( async ( ) => {
@@ -264,7 +304,7 @@ describe('arbitrary message bridging', () => {
264
304
await makeAsyncCall ( selector , data2 )
265
305
266
306
assert ( ! ( await homeBox . methods . status ( ) . call ( ) ) , 'status is true' )
267
- assert . strictEqual ( await homeBox . methods . data ( ) . call ( ) , null , 'returned data is incorrect' )
307
+ assert . strictEqual ( await homeBox . methods . data ( ) . call ( ) , ASYNC_CALL_ERRORS . REVERT , 'returned data is incorrect' )
268
308
269
309
const data3 = homeWeb3 . eth . abi . encodeParameters (
270
310
[ 'address' , 'address' , 'uint256' , 'bytes' ] ,
@@ -274,7 +314,7 @@ describe('arbitrary message bridging', () => {
274
314
await makeAsyncCall ( selector , data3 )
275
315
276
316
assert ( ! ( await homeBox . methods . status ( ) . call ( ) ) , 'status is true' )
277
- assert . strictEqual ( await homeBox . methods . data ( ) . call ( ) , null , 'returned data is incorrect' )
317
+ assert . strictEqual ( await homeBox . methods . data ( ) . call ( ) , ASYNC_CALL_ERRORS . REVERT , 'returned data is incorrect' )
278
318
} )
279
319
280
320
it ( 'should make async eth_call for specific block' , async ( ) => {
@@ -315,6 +355,11 @@ describe('arbitrary message bridging', () => {
315
355
await makeAsyncCall ( selector , data3 )
316
356
317
357
assert ( ! ( await homeBox . methods . status ( ) . call ( ) ) , 'status is true' )
358
+ assert . strictEqual (
359
+ await homeBox . methods . data ( ) . call ( ) ,
360
+ ASYNC_CALL_ERRORS . BLOCK_IS_IN_THE_FUTURE ,
361
+ 'returned data is incorrect'
362
+ )
318
363
} )
319
364
320
365
it ( 'should make async eth_blockNumber' , async ( ) => {
@@ -334,15 +379,8 @@ describe('arbitrary message bridging', () => {
334
379
335
380
assert ( await homeBox . methods . status ( ) . call ( ) , 'status is false' )
336
381
const data = await homeBox . methods . data ( ) . call ( )
337
- assert . strictEqual ( data . length , 2 + 64 * 3 )
338
- const { 0 : number , 1 : hash , 2 : miner } = homeWeb3 . eth . abi . decodeParameters (
339
- [ 'uint256' , 'bytes32' , 'address' ] ,
340
- data
341
- )
342
382
const block = await foreignWeb3 . eth . getBlock ( blockNumber )
343
- assert . strictEqual ( number , blockNumber , 'wrong block number returned' )
344
- assert . strictEqual ( hash , block . hash , 'wrong block hash returned' )
345
- assert . strictEqual ( miner , block . miner , 'wrong block miner returned' )
383
+ validateBlock ( homeWeb3 , data , block )
346
384
} )
347
385
348
386
it ( 'should make async eth_getBlockByNumber and return latest block' , async ( ) => {
@@ -352,7 +390,7 @@ describe('arbitrary message bridging', () => {
352
390
353
391
assert ( await homeBox . methods . status ( ) . call ( ) , 'status is false' )
354
392
const data = await homeBox . methods . data ( ) . call ( )
355
- assert . strictEqual ( data . length , 2 + 64 * 3 )
393
+ assert . strictEqual ( data . length , 2 + 64 * 12 )
356
394
} )
357
395
358
396
it ( 'should make async eth_getBlockByHash' , async ( ) => {
@@ -364,16 +402,7 @@ describe('arbitrary message bridging', () => {
364
402
365
403
assert ( await homeBox . methods . status ( ) . call ( ) , 'status is false' )
366
404
const data = await homeBox . methods . data ( ) . call ( )
367
- assert . strictEqual ( data . length , 2 + 64 * 3 )
368
-
369
- const { 0 : number , 1 : hash , 2 : miner } = homeWeb3 . eth . abi . decodeParameters (
370
- [ 'uint256' , 'bytes32' , 'address' ] ,
371
- data
372
- )
373
-
374
- assert . strictEqual ( number , blockNumber , 'wrong block number returned' )
375
- assert . strictEqual ( hash , block . hash , 'wrong block hash returned' )
376
- assert . strictEqual ( miner , block . miner , 'wrong block miner returned' )
405
+ validateBlock ( homeWeb3 , data , block )
377
406
} )
378
407
379
408
it ( 'should make async eth_getBalance' , async ( ) => {
@@ -469,28 +498,7 @@ describe('arbitrary message bridging', () => {
469
498
470
499
assert ( await homeBox . methods . status ( ) . call ( ) , 'status is false' )
471
500
const data = await homeBox . methods . data ( ) . call ( )
472
- const dataTypes = [
473
- 'bytes32' ,
474
- 'uint256' ,
475
- 'address' ,
476
- 'address' ,
477
- 'uint256' ,
478
- 'uint256' ,
479
- 'uint256' ,
480
- 'uint256' ,
481
- 'bytes'
482
- ]
483
- const values = homeWeb3 . eth . abi . decodeParameters ( dataTypes , data )
484
-
485
- assert . strictEqual ( values [ 0 ] , txHash , 'wrong txHash returned' )
486
- assert . strictEqual ( values [ 1 ] , tx . blockNumber . toString ( ) , 'wrong tx blockNumber returned' )
487
- assert . strictEqual ( values [ 2 ] , tx . from , 'wrong tx from returned' )
488
- assert . strictEqual ( values [ 3 ] , tx . to , 'wrong tx to returned' )
489
- assert . strictEqual ( values [ 4 ] , tx . value , 'wrong tx value returned' )
490
- assert . strictEqual ( values [ 5 ] , tx . nonce . toString ( ) , 'wrong tx nonce returned' )
491
- assert . strictEqual ( values [ 6 ] , tx . gas . toString ( ) , 'wrong tx gas returned' )
492
- assert . strictEqual ( values [ 7 ] , tx . gasPrice , 'wrong tx gasPrice returned' )
493
- assert . strictEqual ( values [ 8 ] , tx . input , 'wrong tx data returned' )
501
+ validateTransaction ( homeWeb3 , data , tx )
494
502
} )
495
503
496
504
it ( 'should make async eth_getTransactionReceipt' , async ( ) => {
@@ -502,18 +510,25 @@ describe('arbitrary message bridging', () => {
502
510
503
511
assert ( await homeBox . methods . status ( ) . call ( ) , 'status is false' )
504
512
const data = await homeBox . methods . data ( ) . call ( )
505
- const dataTypes = [ 'bytes32' , 'uint256' , 'bool' , '(address,bytes32[],bytes)[]' ]
506
- const values = homeWeb3 . eth . abi . decodeParameters ( dataTypes , data )
513
+ const values = homeWeb3 . eth . abi . decodeParameter (
514
+ '(bytes32,uint256,bytes32,uint256,address,address,uint256,bool,(address,bytes32[],bytes)[])' ,
515
+ data
516
+ )
507
517
508
518
assert . strictEqual ( values [ 0 ] , txHash , 'wrong txHash returned' )
509
519
assert . strictEqual ( values [ 1 ] , receipt . blockNumber . toString ( ) , 'wrong tx blockNumber returned' )
510
- assert . strictEqual ( values [ 2 ] , receipt . status , 'wrong tx status returned' )
511
- assert . strictEqual ( values [ 3 ] . length , 1 , 'wrong logs length returned' )
512
- assert . strictEqual ( values [ 3 ] [ 0 ] [ 0 ] , receipt . logs [ 0 ] . address , 'wrong log address returned' )
513
- assert . strictEqual ( values [ 3 ] [ 0 ] [ 1 ] . length , 2 , 'wrong log topics length returned' )
514
- assert . strictEqual ( values [ 3 ] [ 0 ] [ 1 ] [ 0 ] , receipt . logs [ 0 ] . topics [ 0 ] , 'wrong event signature returned' )
515
- assert . strictEqual ( values [ 3 ] [ 0 ] [ 1 ] [ 1 ] , receipt . logs [ 0 ] . topics [ 1 ] , 'wrong message id returned' )
516
- assert . strictEqual ( values [ 3 ] [ 0 ] [ 2 ] , receipt . logs [ 0 ] . data , 'wrong log data returned' )
520
+ assert . strictEqual ( values [ 2 ] , receipt . blockHash , 'wrong tx blockHash returned' )
521
+ assert . strictEqual ( values [ 3 ] , receipt . transactionIndex . toString ( ) , 'wrong tx transactionIndex returned' )
522
+ assert . strictEqual ( values [ 4 ] . toLowerCase ( ) , receipt . from , 'wrong tx from returned' )
523
+ assert . strictEqual ( values [ 5 ] . toLowerCase ( ) , receipt . to , 'wrong tx to returned' )
524
+ assert . strictEqual ( values [ 6 ] , receipt . gasUsed . toString ( ) , 'wrong gasUsed to returned' )
525
+ assert . strictEqual ( values [ 7 ] , receipt . status , 'wrong tx status returned' )
526
+ assert . strictEqual ( values [ 8 ] . length , 1 , 'wrong logs length returned' )
527
+ assert . strictEqual ( values [ 8 ] [ 0 ] [ 0 ] , receipt . logs [ 0 ] . address , 'wrong log address returned' )
528
+ assert . strictEqual ( values [ 8 ] [ 0 ] [ 1 ] . length , 2 , 'wrong log topics length returned' )
529
+ assert . strictEqual ( values [ 8 ] [ 0 ] [ 1 ] [ 0 ] , receipt . logs [ 0 ] . topics [ 0 ] , 'wrong event signature returned' )
530
+ assert . strictEqual ( values [ 8 ] [ 0 ] [ 1 ] [ 1 ] , receipt . logs [ 0 ] . topics [ 1 ] , 'wrong message id returned' )
531
+ assert . strictEqual ( values [ 8 ] [ 0 ] [ 2 ] , receipt . logs [ 0 ] . data , 'wrong log data returned' )
517
532
} )
518
533
519
534
it ( 'should make async eth_getStorageAt' , async ( ) => {
0 commit comments