@@ -27,6 +27,45 @@ const foreignBox = new foreignWeb3.eth.Contract(BOX_ABI, amb.foreignBox, opts)
2727const homeBridge = new homeWeb3 . eth . Contract ( HOME_AMB_ABI , amb . home , opts )
2828const foreignBridge = new foreignWeb3 . eth . Contract ( FOREIGN_AMB_ABI , amb . foreign , opts )
2929
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+
3069describe ( 'arbitrary message bridging' , ( ) => {
3170 let requiredSignatures = 1
3271 before ( async ( ) => {
@@ -340,15 +379,8 @@ describe('arbitrary message bridging', () => {
340379
341380 assert ( await homeBox . methods . status ( ) . call ( ) , 'status is false' )
342381 const data = await homeBox . methods . data ( ) . call ( )
343- assert . strictEqual ( data . length , 2 + 64 * 3 )
344- const { 0 : number , 1 : hash , 2 : miner } = homeWeb3 . eth . abi . decodeParameters (
345- [ 'uint256' , 'bytes32' , 'address' ] ,
346- data
347- )
348382 const block = await foreignWeb3 . eth . getBlock ( blockNumber )
349- assert . strictEqual ( number , blockNumber , 'wrong block number returned' )
350- assert . strictEqual ( hash , block . hash , 'wrong block hash returned' )
351- assert . strictEqual ( miner , block . miner , 'wrong block miner returned' )
383+ validateBlock ( homeWeb3 , data , block )
352384 } )
353385
354386 it ( 'should make async eth_getBlockByNumber and return latest block' , async ( ) => {
@@ -358,7 +390,7 @@ describe('arbitrary message bridging', () => {
358390
359391 assert ( await homeBox . methods . status ( ) . call ( ) , 'status is false' )
360392 const data = await homeBox . methods . data ( ) . call ( )
361- assert . strictEqual ( data . length , 2 + 64 * 3 )
393+ assert . strictEqual ( data . length , 2 + 64 * 12 )
362394 } )
363395
364396 it ( 'should make async eth_getBlockByHash' , async ( ) => {
@@ -370,16 +402,7 @@ describe('arbitrary message bridging', () => {
370402
371403 assert ( await homeBox . methods . status ( ) . call ( ) , 'status is false' )
372404 const data = await homeBox . methods . data ( ) . call ( )
373- assert . strictEqual ( data . length , 2 + 64 * 3 )
374-
375- const { 0 : number , 1 : hash , 2 : miner } = homeWeb3 . eth . abi . decodeParameters (
376- [ 'uint256' , 'bytes32' , 'address' ] ,
377- data
378- )
379-
380- assert . strictEqual ( number , blockNumber , 'wrong block number returned' )
381- assert . strictEqual ( hash , block . hash , 'wrong block hash returned' )
382- assert . strictEqual ( miner , block . miner , 'wrong block miner returned' )
405+ validateBlock ( homeWeb3 , data , block )
383406 } )
384407
385408 it ( 'should make async eth_getBalance' , async ( ) => {
@@ -475,28 +498,7 @@ describe('arbitrary message bridging', () => {
475498
476499 assert ( await homeBox . methods . status ( ) . call ( ) , 'status is false' )
477500 const data = await homeBox . methods . data ( ) . call ( )
478- const dataTypes = [
479- 'bytes32' ,
480- 'uint256' ,
481- 'address' ,
482- 'address' ,
483- 'uint256' ,
484- 'uint256' ,
485- 'uint256' ,
486- 'uint256' ,
487- 'bytes'
488- ]
489- const values = homeWeb3 . eth . abi . decodeParameters ( dataTypes , data )
490-
491- assert . strictEqual ( values [ 0 ] , txHash , 'wrong txHash returned' )
492- assert . strictEqual ( values [ 1 ] , tx . blockNumber . toString ( ) , 'wrong tx blockNumber returned' )
493- assert . strictEqual ( values [ 2 ] , tx . from , 'wrong tx from returned' )
494- assert . strictEqual ( values [ 3 ] , tx . to , 'wrong tx to returned' )
495- assert . strictEqual ( values [ 4 ] , tx . value , 'wrong tx value returned' )
496- assert . strictEqual ( values [ 5 ] , tx . nonce . toString ( ) , 'wrong tx nonce returned' )
497- assert . strictEqual ( values [ 6 ] , tx . gas . toString ( ) , 'wrong tx gas returned' )
498- assert . strictEqual ( values [ 7 ] , tx . gasPrice , 'wrong tx gasPrice returned' )
499- assert . strictEqual ( values [ 8 ] , tx . input , 'wrong tx data returned' )
501+ validateTransaction ( homeWeb3 , data , tx )
500502 } )
501503
502504 it ( 'should make async eth_getTransactionReceipt' , async ( ) => {
@@ -508,18 +510,25 @@ describe('arbitrary message bridging', () => {
508510
509511 assert ( await homeBox . methods . status ( ) . call ( ) , 'status is false' )
510512 const data = await homeBox . methods . data ( ) . call ( )
511- const dataTypes = [ 'bytes32' , 'uint256' , 'bool' , '(address,bytes32[],bytes)[]' ]
512- 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+ )
513517
514518 assert . strictEqual ( values [ 0 ] , txHash , 'wrong txHash returned' )
515519 assert . strictEqual ( values [ 1 ] , receipt . blockNumber . toString ( ) , 'wrong tx blockNumber returned' )
516- assert . strictEqual ( values [ 2 ] , receipt . status , 'wrong tx status returned' )
517- assert . strictEqual ( values [ 3 ] . length , 1 , 'wrong logs length returned' )
518- assert . strictEqual ( values [ 3 ] [ 0 ] [ 0 ] , receipt . logs [ 0 ] . address , 'wrong log address returned' )
519- assert . strictEqual ( values [ 3 ] [ 0 ] [ 1 ] . length , 2 , 'wrong log topics length returned' )
520- assert . strictEqual ( values [ 3 ] [ 0 ] [ 1 ] [ 0 ] , receipt . logs [ 0 ] . topics [ 0 ] , 'wrong event signature returned' )
521- assert . strictEqual ( values [ 3 ] [ 0 ] [ 1 ] [ 1 ] , receipt . logs [ 0 ] . topics [ 1 ] , 'wrong message id returned' )
522- 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' )
523532 } )
524533
525534 it ( 'should make async eth_getStorageAt' , async ( ) => {
0 commit comments