Skip to content

Commit 04e05ae

Browse files
committed
remix simulator blocks ut1
1 parent c7da882 commit 04e05ae

File tree

2 files changed

+39
-44
lines changed

2 files changed

+39
-44
lines changed

libs/remix-simulator/test/accounts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global describe, before, it */
22
import { Provider } from '../src/index'
33
import * as assert from 'assert'
4-
import { ethers, BrowserProvider } from "ethers";
4+
import { ethers, BrowserProvider } from "ethers"
55

66
describe('Accounts', () => {
77
let ethersProvider: BrowserProvider

libs/remix-simulator/test/blocks.ts

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,42 @@ import { Web3 } from 'web3'
33
import { Provider } from '../src/index'
44
const web3 = new Web3()
55
import * as assert from 'assert'
6+
import { ethers, BrowserProvider } from "ethers"
67

78
describe('blocks', () => {
9+
let ethersProvider: BrowserProvider
10+
811
before(async () => {
912
const provider = new Provider({
1013
coinbase: '0x0000000000000000000000000000000000000001'
1114
})
1215
await provider.init()
1316
web3.setProvider(provider as any)
17+
ethersProvider = new ethers.BrowserProvider(provider as any)
1418
})
1519

1620
describe('eth_getBlockByNumber', () => {
1721
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])
2023
const expectedBlock = {
21-
baseFeePerGas: '1',
22-
difficulty: '0',
23-
extraData: '0x00',
24-
gasLimit: '8000000',
25-
gasUsed: '0',
24+
baseFeePerGas: '0x01',
25+
number: '0x0',
2626
hash: block.hash.toString(),
27-
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
28-
miner: '0x0000000000000000000000000000000000000001',
29-
nonce: '0',
30-
number: '0',
3127
parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
28+
nonce: '0x0000000000000000',
3229
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
33-
size: '163591',
30+
logsBloom: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
31+
transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
3432
stateRoot: '0x0000000000000000000000000000000000000000000000000000000000000000',
33+
miner: '0x0000000000000000000000000000000000000001',
34+
difficulty: '0x0',
35+
totalDifficulty: '0x0',
36+
extraData: '0x00',
37+
size: '0x027f07',
38+
gasLimit: '0x7a1200',
39+
gasUsed: '0x0',
3540
timestamp: block.timestamp,
36-
totalDifficulty: '0',
37-
transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
41+
transactions: [],
3842
uncles: []
3943
}
4044

@@ -44,82 +48,73 @@ describe('blocks', () => {
4448

4549
describe('eth_getGasPrice', () => {
4650
it('should get gas price', async () => {
47-
const gasPrice = await web3.eth.getGasPrice()
51+
const { gasPrice } = await ethersProvider.getFeeData()
4852
assert.equal(gasPrice, 1)
4953
})
5054
})
5155

5256
describe('eth_coinbase', () => {
5357
it('should get coinbase', async () => {
54-
const coinbase = await web3.eth.getCoinbase()
58+
const coinbase = await ethersProvider.send("eth_coinbase", [])
5559
assert.equal(coinbase, '0x0000000000000000000000000000000000000001')
5660
})
5761
})
5862

5963
describe('eth_blockNumber', () => {
6064
it('should get current block number', async () => {
61-
const number = await web3.eth.getBlockNumber()
65+
const number = await ethersProvider.getBlockNumber()
6266
assert.equal(number, 0)
6367
})
6468
})
6569

6670
describe('evm_mine', () => {
6771
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', [])
7374
assert.equal(number, 3)
7475
})
7576
})
7677

7778
describe('eth_getBlockByHash', () => {
7879
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)
8182

8283
assert.deepEqual(block, correctBlock)
8384
})
8485
})
8586

8687
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])
9091

9192
assert.deepEqual(numberTransactions, 0)
9293
})
9394
})
9495

9596
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'])
9899

99100
assert.deepEqual(numberTransactions, 0)
100101
})
101102
})
102103

103104
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+
111109
assert.deepEqual(numberTransactions, correctBlock.uncles.length)
112110
})
113111
})
114112

115113
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+
123118
assert.deepEqual(numberTransactions, correctBlock.uncles.length)
124119
})
125120
})

0 commit comments

Comments
 (0)