@@ -3,38 +3,42 @@ import { Web3 } from 'web3'
3
3
import { Provider } from '../src/index'
4
4
const web3 = new Web3 ( )
5
5
import * as assert from 'assert'
6
+ import { ethers , BrowserProvider } from "ethers"
6
7
7
8
describe ( 'blocks' , ( ) => {
9
+ let ethersProvider : BrowserProvider
10
+
8
11
before ( async ( ) => {
9
12
const provider = new Provider ( {
10
13
coinbase : '0x0000000000000000000000000000000000000001'
11
14
} )
12
15
await provider . init ( )
13
16
web3 . setProvider ( provider as any )
17
+ ethersProvider = new ethers . BrowserProvider ( provider as any )
14
18
} )
15
19
16
20
describe ( 'eth_getBlockByNumber' , ( ) => {
17
21
it ( 'should get block given its number' , async ( ) => {
18
- const block = await web3 . eth . getBlock ( 0 )
19
-
22
+ const block = await ethersProvider . send ( 'eth_getBlockByNumber' , [ 0 ] )
20
23
const expectedBlock = {
21
- baseFeePerGas : '1' ,
22
- difficulty : '0' ,
23
- extraData : '0x00' ,
24
- gasLimit : '8000000' ,
25
- gasUsed : '0' ,
24
+ baseFeePerGas : '0x01' ,
25
+ number : '0x0' ,
26
26
hash : block . hash . toString ( ) ,
27
- logsBloom : '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331' ,
28
- miner : '0x0000000000000000000000000000000000000001' ,
29
- nonce : '0' ,
30
- number : '0' ,
31
27
parentHash : '0x0000000000000000000000000000000000000000000000000000000000000000' ,
28
+ nonce : '0x0000000000000000' ,
32
29
sha3Uncles : '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347' ,
33
- size : '163591' ,
30
+ logsBloom : '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331' ,
31
+ transactionsRoot : '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421' ,
34
32
stateRoot : '0x0000000000000000000000000000000000000000000000000000000000000000' ,
33
+ miner : '0x0000000000000000000000000000000000000001' ,
34
+ difficulty : '0x0' ,
35
+ totalDifficulty : '0x0' ,
36
+ extraData : '0x00' ,
37
+ size : '0x027f07' ,
38
+ gasLimit : '0x7a1200' ,
39
+ gasUsed : '0x0' ,
35
40
timestamp : block . timestamp ,
36
- totalDifficulty : '0' ,
37
- transactionsRoot : '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421' ,
41
+ transactions : [ ] ,
38
42
uncles : [ ]
39
43
}
40
44
@@ -44,82 +48,73 @@ describe('blocks', () => {
44
48
45
49
describe ( 'eth_getGasPrice' , ( ) => {
46
50
it ( 'should get gas price' , async ( ) => {
47
- const gasPrice = await web3 . eth . getGasPrice ( )
51
+ const { gasPrice } = await ethersProvider . getFeeData ( )
48
52
assert . equal ( gasPrice , 1 )
49
53
} )
50
54
} )
51
55
52
56
describe ( 'eth_coinbase' , ( ) => {
53
57
it ( 'should get coinbase' , async ( ) => {
54
- const coinbase = await web3 . eth . getCoinbase ( )
58
+ const coinbase = await ethersProvider . send ( "eth_coinbase" , [ ] )
55
59
assert . equal ( coinbase , '0x0000000000000000000000000000000000000001' )
56
60
} )
57
61
} )
58
62
59
63
describe ( 'eth_blockNumber' , ( ) => {
60
64
it ( 'should get current block number' , async ( ) => {
61
- const number = await web3 . eth . getBlockNumber ( )
65
+ const number = await ethersProvider . getBlockNumber ( )
62
66
assert . equal ( number , 0 )
63
67
} )
64
68
} )
65
69
66
70
describe ( 'evm_mine' , ( ) => {
67
71
it ( 'should mine empty block using evm_mine' , async function ( ) {
68
- await web3 . provider . request ( {
69
- method : 'evm_mine' ,
70
- params : [ { blocks : 3 } ] ,
71
- } )
72
- const number = await web3 . eth . getBlockNumber ( )
72
+ await ethersProvider . send ( 'evm_mine' , [ { blocks : 3 } ] )
73
+ const number = await ethersProvider . send ( 'eth_blockNumber' , [ ] )
73
74
assert . equal ( number , 3 )
74
75
} )
75
76
} )
76
77
77
78
describe ( 'eth_getBlockByHash' , ( ) => {
78
79
it ( 'should get block given its hash' , async ( ) => {
79
- const correctBlock = await web3 . eth . getBlock ( 0 )
80
- const block = await web3 . eth . getBlock ( correctBlock . hash )
80
+ const correctBlock = await ethersProvider . getBlock ( 0 )
81
+ const block = await ethersProvider . getBlock ( correctBlock . hash )
81
82
82
83
assert . deepEqual ( block , correctBlock )
83
84
} )
84
85
} )
85
86
86
87
describe ( 'eth_getBlockTransactionCountByHash' , ( ) => {
87
- it ( 'should get block given its hash' , async ( ) => {
88
- const correctBlock = await web3 . eth . getBlock ( 0 )
89
- const numberTransactions = await web3 . eth . getBlockTransactionCount ( correctBlock . hash )
88
+ it ( 'should get block transactions count given block hash' , async ( ) => {
89
+ const correctBlock = await ethersProvider . getBlock ( 0 )
90
+ const numberTransactions = await ethersProvider . send ( 'eth_getBlockTransactionCountByHash' , [ correctBlock . hash ] )
90
91
91
92
assert . deepEqual ( numberTransactions , 0 )
92
93
} )
93
94
} )
94
95
95
96
describe ( 'eth_getBlockTransactionCountByNumber' , ( ) => {
96
- it ( 'should get block given its hash ' , async ( ) => {
97
- const numberTransactions = await web3 . eth . getBlockTransactionCount ( 0 )
97
+ it ( 'should get block transactions count given block number ' , async ( ) => {
98
+ const numberTransactions = await ethersProvider . send ( 'eth_getBlockTransactionCountByNumber' , [ '0x0' ] )
98
99
99
100
assert . deepEqual ( numberTransactions , 0 )
100
101
} )
101
102
} )
102
103
103
104
describe ( 'eth_getUncleCountByBlockHash' , ( ) => {
104
- it ( 'should get block given its hash' , async ( ) => {
105
- const correctBlock = await web3 . eth . getBlock ( 0 )
106
- const numberTransactions = await ( new Promise ( ( resolve , reject ) => {
107
- web3 [ '_requestManager' ] . send ( { method : 'eth_getUncleCountByBlockHash' , params : [ correctBlock . hash ] } )
108
- . then ( numberTransactions => resolve ( numberTransactions ) )
109
- . catch ( err => reject ( err ) )
110
- } ) )
105
+ it ( 'should get block uncles count given its hash' , async ( ) => {
106
+ const correctBlock = await ethersProvider . send ( 'eth_getBlockByNumber' , [ 0 ] )
107
+ const numberTransactions = await ethersProvider . send ( 'eth_getUncleCountByBlockHash' , [ correctBlock . hash ] )
108
+
111
109
assert . deepEqual ( numberTransactions , correctBlock . uncles . length )
112
110
} )
113
111
} )
114
112
115
113
describe ( 'eth_getUncleCountByBlockNumber' , ( ) => {
116
- it ( 'should get block given its number' , async ( ) => {
117
- const correctBlock = await web3 . eth . getBlock ( 0 )
118
- const numberTransactions = await ( new Promise ( ( resolve , reject ) => {
119
- web3 [ '_requestManager' ] . send ( { method : 'eth_getUncleCountByBlockHash' , params : [ 0 ] } )
120
- . then ( numberTransactions => resolve ( numberTransactions ) )
121
- . catch ( err => reject ( err ) )
122
- } ) )
114
+ it ( 'should get block uncles count given its number' , async ( ) => {
115
+ const correctBlock = await ethersProvider . send ( 'eth_getBlockByNumber' , [ 0 ] )
116
+ const numberTransactions = await ethersProvider . send ( 'eth_getUncleCountByBlockNumber' , [ 0 ] )
117
+
123
118
assert . deepEqual ( numberTransactions , correctBlock . uncles . length )
124
119
} )
125
120
} )
0 commit comments