1+ const fs = require ( 'fs' )
2+ const utils = require ( 'web3-utils' )
13const { assert } = require ( 'chai' )
24const conf = require ( './config' )
35const helpers = require ( './helpers' )
46const web3 = conf . web3
57
6- it ( 'deploy contract and interact' , async ( ) => {
7- let deployed = await helpers . deployContract ( "storage" )
8+ // Address that will deploy the multicall3 contract (must have been pre-funded)
9+ const MULTICALL3_DEPLOYER = '0x05f32B3cC3888453ff71B01135B34FF8e41263F2'
10+
11+ it ( 'deploys multicall3 contract and interacts' , async ( ) => {
12+ let deployed = await helpers . deployContract ( 'storage' )
813 let contractAddress = deployed . receipt . contractAddress
914
1015 // get the default deployed value on contract
1116 const initValue = 1337
12- let callRetrieve = await deployed . contract . methods . retrieve ( ) . encodeABI ( )
13- result = await web3 . eth . call ( { to : contractAddress , data : callRetrieve } , " latest" )
17+ let callRetrieve = deployed . contract . methods . retrieve ( ) . encodeABI ( )
18+ result = await web3 . eth . call ( { to : contractAddress , data : callRetrieve } , ' latest' )
1419 assert . equal ( result , initValue )
1520
16- let multicall3 = await helpers . deployContract ( "multicall3" )
17- let multicall3Address = multicall3 . receipt . contractAddress
21+ // Fund the multicall3 deployer address
22+ let transfer = await helpers . signAndSend ( {
23+ from : conf . eoa . address ,
24+ to : MULTICALL3_DEPLOYER ,
25+ value : utils . toWei ( '1.0' , 'ether' ) ,
26+ gasPrice : conf . minGasPrice ,
27+ gasLimit : 55_000 ,
28+ } )
29+ assert . equal ( transfer . receipt . status , conf . successStatus )
30+
31+ // Deploy multicall3 using pre-signed raw transaction
32+ // Note: The transaction in multicall3.byte must be signed
33+ // by the address defined in the `MULTICALL3_DEPLOYER` const
34+ let multicall3DeploymentTx = await fs . promises . readFile ( `${ __dirname } /../fixtures/multicall3.byte` , 'utf8' )
35+ let response = await helpers . callRPCMethod (
36+ 'eth_sendRawTransaction' ,
37+ [ multicall3DeploymentTx ]
38+ )
39+ assert . equal ( 200 , response . status )
40+ assert . isDefined ( response . body . result , 'Transaction hash should be returned' )
41+
42+ let txHash = response . body . result
43+
44+ // wait for the transaction receipt to become available
45+ await new Promise ( ( res , _ ) => setTimeout ( ( ) => res ( ) , 1500 ) )
46+ let receipt = await web3 . eth . getTransactionReceipt ( txHash )
47+ let multicall3Address = receipt . contractAddress
1848
1949 // make sure deploy results are correct
20- assert . equal ( multicall3 . receipt . status , conf . successStatus )
21- assert . isString ( multicall3 . receipt . transactionHash )
50+ assert . equal ( receipt . status , conf . successStatus )
51+ assert . equal ( receipt . from , MULTICALL3_DEPLOYER )
52+ assert . isString ( receipt . transactionHash )
2253 assert . isString ( multicall3Address )
2354
24- let callSum20 = await deployed . contract . methods . sum ( 10 , 10 ) . encodeABI ( )
25- let callSum50 = await deployed . contract . methods . sum ( 10 , 40 ) . encodeABI ( )
26- let callAggregate3 = await multicall3 . contract . methods . aggregate3 (
55+ let tx = await web3 . eth . getTransaction ( txHash )
56+ assert . equal ( tx . from , MULTICALL3_DEPLOYER )
57+ assert . isUndefined ( tx . chainId )
58+
59+ let block = await web3 . eth . getBlock ( receipt . blockNumber , true )
60+ assert . equal ( block . transactions [ 0 ] . from , MULTICALL3_DEPLOYER )
61+ assert . isUndefined ( block . transactions [ 0 ] . chainId )
62+
63+ let multicall3ABI = require ( '../fixtures/multicall3ABI.json' )
64+ let multicall3 = new web3 . eth . Contract ( multicall3ABI , multicall3Address , { handleReverted : true } )
65+
66+ let callSum20 = deployed . contract . methods . sum ( 10 , 10 ) . encodeABI ( )
67+ let callSum50 = deployed . contract . methods . sum ( 10 , 40 ) . encodeABI ( )
68+ let callAggregate3 = multicall3 . methods . aggregate3 (
2769 [
2870 {
2971 target : contractAddress ,
@@ -43,7 +85,7 @@ it('deploy contract and interact', async () => {
4385 to : multicall3Address ,
4486 data : callAggregate3
4587 } ,
46- " latest"
88+ ' latest'
4789 )
4890 let decodedResult = web3 . eth . abi . decodeParameter (
4991 {
0 commit comments