Skip to content

Commit c7da882

Browse files
committed
simulator account ut
1 parent eb191e2 commit c7da882

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

libs/remix-simulator/test/accounts.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
11
/* global describe, before, it */
2-
import { Web3, FMT_BYTES, FMT_NUMBER } from 'web3'
32
import { Provider } from '../src/index'
4-
const web3 = new Web3()
53
import * as assert from 'assert'
4+
import { ethers, BrowserProvider } from "ethers";
65

76
describe('Accounts', () => {
7+
let ethersProvider: BrowserProvider
88
before(async function () {
99
const provider = new Provider()
1010
await provider.init()
11-
web3.setProvider(provider as any)
11+
ethersProvider = new ethers.BrowserProvider(provider as any)
1212
})
1313

1414
describe('eth_getAccounts', () => {
1515
it('should get a list of accounts', async function () {
16-
const accounts: string[] = await web3.eth.getAccounts()
16+
const accounts: string[] = await ethersProvider.send("eth_requestAccounts", [])
1717
assert.notEqual(accounts.length, 0)
1818
})
1919
})
2020

2121
describe('eth_getBalance', () => {
2222
it('should get an account balance', async () => {
23-
const accounts: string[] = await web3.eth.getAccounts()
24-
const balance0: string = await web3.eth.getBalance(accounts[0], undefined, { number: FMT_NUMBER.STR, bytes: FMT_BYTES.HEX })
25-
const balance1: string = await web3.eth.getBalance(accounts[1], undefined, { number: FMT_NUMBER.STR, bytes: FMT_BYTES.HEX })
26-
const balance2: string = await web3.eth.getBalance(accounts[2], undefined, { number: FMT_NUMBER.STR, bytes: FMT_BYTES.HEX })
23+
const accounts: string[] = await ethersProvider.send("eth_requestAccounts", [])
24+
const balance0: bigint = await ethersProvider.getBalance(accounts[0])
25+
const balance1: bigint = await ethersProvider.getBalance(accounts[1])
26+
const balance2: bigint = await ethersProvider.getBalance(accounts[2])
2727

28-
assert.deepEqual(balance0, '100000000000000000000')
29-
assert.deepEqual(balance1, '100000000000000000000')
30-
assert.deepEqual(balance2, '100000000000000000000')
28+
assert.deepEqual(balance0.toString(), '100000000000000000000')
29+
assert.deepEqual(balance1.toString(), '100000000000000000000')
30+
assert.deepEqual(balance2.toString(), '100000000000000000000')
3131
})
3232
})
3333

3434
describe('eth_sign', () => {
3535
it('should sign payloads', async () => {
36-
const accounts: string[] = await web3.eth.getAccounts()
37-
const signature = await web3.eth.sign(web3.utils.utf8ToHex('Hello world'), accounts[0])
38-
36+
const signer = await ethersProvider.getSigner()
37+
const signature: any = await signer._legacySignMessage('Hello world') // _legacySignMessage uses 'eth_sign' internally
3938
assert.deepEqual(typeof signature === 'string' ? signature.length : signature.signature.length, 132)
4039
})
4140
})
4241

4342
describe('eth_signTypedData', () => {
4443
it('should sign typed data', async () => {
45-
const accounts: string[] = await web3.eth.getAccounts()
44+
const accounts: string[] = await ethersProvider.send("eth_requestAccounts", [])
4645
const typedData = {
4746
domain: {
4847
chainId: 1,
@@ -68,10 +67,7 @@ describe('Accounts', () => {
6867
],
6968
},
7069
};
71-
const result = await web3.currentProvider.request({
72-
method: 'eth_signTypedData',
73-
params: [accounts[0], typedData]
74-
})
70+
const result = await ethersProvider.send('eth_signTypedData', [accounts[0], typedData])
7571
assert.equal(result, '0x248d23de0e23231370db8aa21ad5908ca90c33ae2b8c611b906674bda6b1a8b85813f945c2ea896316e240089029619ab3d801a1b098c199bd462dd8026349da1c')
7672
})
7773
})

0 commit comments

Comments
 (0)