1
1
/* global describe, before, it */
2
- import { Web3 } from 'web3'
3
2
import { Provider } from '../src/index'
4
- const web3 = new Web3 ( )
5
3
import * as assert from 'assert'
6
4
import { ethers , BrowserProvider } from "ethers"
7
5
@@ -13,7 +11,6 @@ describe('blocks', () => {
13
11
coinbase : '0x0000000000000000000000000000000000000001'
14
12
} )
15
13
await provider . init ( )
16
- web3 . setProvider ( provider as any )
17
14
ethersProvider = new ethers . BrowserProvider ( provider as any )
18
15
} )
19
16
@@ -203,26 +200,30 @@ describe('blocks', () => {
203
200
] as const
204
201
205
202
const code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029'
203
+ const signer = await ethersProvider . getSigner ( ) ;
204
+ const contract = new ethers . ContractFactory ( abi , code , signer )
206
205
207
- const contract = new web3 . eth . Contract ( abi )
208
- const accounts = await web3 . eth . getAccounts ( )
206
+ const contractInstance = await contract . deploy ( 100 )
207
+ await contractInstance . waitForDeployment ( )
209
208
210
- const contractInstance : any = await contract . deploy ( { data : code , arguments : [ 100 ] } ) . send ( { from : accounts [ 0 ] , gas : '400000' } )
211
- contractInstance . currentProvider = web3 . eth . currentProvider
212
- // contractInstance.givenProvider = web3.eth.currentProvider
209
+ const contractAddress = await contractInstance . getAddress ( )
210
+ const contractInteract = new ethers . Contract ( contractAddress , abi , signer )
213
211
214
- await contractInstance . methods . set ( 100 ) . send ( { from : accounts [ 0 ] . toLowerCase ( ) , gas : 400000 } )
215
- let storage = await web3 . eth . getStorageAt ( contractInstance . options . address , 0 )
212
+ let tx = await contractInteract . set ( 100 )
213
+ await tx . wait ( )
214
+ let storage = await ethersProvider . getStorage ( contractAddress , "0x0" )
216
215
assert . deepEqual ( storage , '0x64' )
217
216
218
- await contractInstance . methods . set ( 200 ) . send ( { from : accounts [ 0 ] . toLowerCase ( ) , gas : 400000 } )
219
- storage = await web3 . eth . getStorageAt ( contractInstance . options . address , 0 )
217
+ tx = await contractInteract . set ( 200 )
218
+ await tx . wait ( )
219
+ storage = await ethersProvider . getStorage ( contractAddress , "0x0" )
220
220
assert . deepEqual ( storage , '0xc8' )
221
221
222
- await contractInstance . methods . set ( 1 ) . send ( { from : accounts [ 0 ] . toLowerCase ( ) , gas : 400000 } )
223
- storage = await web3 . eth . getStorageAt ( contractInstance . options . address , 0 )
222
+ tx = await contractInteract . set ( 1 )
223
+ await tx . wait ( )
224
+ storage = await ethersProvider . getStorage ( contractAddress , "0x0" )
224
225
assert . deepEqual ( storage , '0x01' )
225
- } )
226
+ } ) . timeout ( 20000 )
226
227
} )
227
228
describe ( 'eth_call' , ( ) => {
228
229
it ( 'should get a value' , async ( ) => {
@@ -310,14 +311,18 @@ describe('blocks', () => {
310
311
311
312
const code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029'
312
313
313
- const contract = new web3 . eth . Contract ( abi )
314
- const accounts = await web3 . eth . getAccounts ( )
314
+ const signer = await ethersProvider . getSigner ( ) ;
315
+ const contract = new ethers . ContractFactory ( abi , code , signer )
316
+
317
+ const contractInstance = await contract . deploy ( 100 )
318
+ await contractInstance . waitForDeployment ( )
315
319
316
- const contractInstance : any = await contract . deploy ( { data : code , arguments : [ 100 ] } ) . send ( { from : accounts [ 0 ] , gas : '400000' } )
317
- contractInstance . currentProvider = web3 . eth . currentProvider
320
+ const contractAddress = await contractInstance . getAddress ( )
321
+ const contractInteract = new ethers . Contract ( contractAddress , abi , signer )
322
+
323
+ let value = await contractInteract . get ( )
318
324
319
- const value = await contractInstance . methods . get ( ) . call ( { from : accounts [ 0 ] } )
320
325
assert . deepEqual ( value , 100 )
321
- } )
326
+ } ) . timeout ( 5000 )
322
327
} )
323
328
} )
0 commit comments