|
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'
|
| 4 | +import { ethers, BrowserProvider } from "ethers" |
6 | 5 |
|
7 | 6 | describe('Misc', () => {
|
| 7 | + let ethersProvider: BrowserProvider |
8 | 8 | before(async () => {
|
9 | 9 | const provider = new Provider()
|
10 | 10 | await provider.init()
|
11 |
| - web3.setProvider(provider as any) |
| 11 | + ethersProvider = new ethers.BrowserProvider(provider as any) |
12 | 12 | })
|
13 | 13 |
|
14 | 14 | describe('web3_clientVersion', () => {
|
15 | 15 | it('should get correct remix simulator version', async () => {
|
16 |
| - web3['_requestManager'].send({ method: 'web3_clientVersion', params: []}) |
17 |
| - .then(version => { |
18 |
| - const remixVersion = require('../package.json').version |
19 |
| - assert.equal(version, 'Remix Simulator/' + remixVersion) |
20 |
| - }) |
21 |
| - .catch(err => { throw new Error(err) }) |
| 16 | + const version = await ethersProvider.send("web3_clientVersion", []) |
| 17 | + const remixVersion = require('../package.json').version |
| 18 | + assert.equal(version, 'Remix Simulator/' + remixVersion) |
22 | 19 | })
|
23 | 20 | })
|
24 | 21 |
|
25 | 22 | describe('eth_protocolVersion', () => {
|
26 | 23 | it('should get protocol version', async () => {
|
27 |
| - web3['_requestManager'].send({ method: 'eth_protocolVersion', params: []}) |
28 |
| - .then(result => assert.equal(result, '0x3f')) |
29 |
| - .catch(err => { throw new Error(err) }) |
| 24 | + const result = await ethersProvider.send("eth_protocolVersion", []) |
| 25 | + assert.equal(result, '0x3f') |
30 | 26 | })
|
31 | 27 | })
|
32 | 28 |
|
33 | 29 | describe('eth_syncing', () => {
|
34 | 30 | it('should get if is syncing', async () => {
|
35 |
| - const isSyncing = await web3.eth.isSyncing() |
| 31 | + const isSyncing = await ethersProvider.send("eth_syncing", []) |
36 | 32 | assert.equal(isSyncing, false)
|
37 | 33 | })
|
38 | 34 | })
|
39 | 35 |
|
40 | 36 | describe('eth_mining', () => {
|
41 | 37 | it('should get if is mining', async () => {
|
42 |
| - const isMining = await web3.eth.isMining() |
| 38 | + const isMining = await ethersProvider.send("eth_mining", []) |
43 | 39 | assert.equal(isMining, false)
|
44 | 40 | })
|
45 | 41 | })
|
46 | 42 |
|
47 | 43 | describe('eth_hashrate', () => {
|
48 | 44 | it('should get hashrate', async () => {
|
49 |
| - const hashrate = await web3.eth.getHashrate() |
| 45 | + const hashrate = await ethersProvider.send("eth_hashrate", []) |
50 | 46 | assert.equal(hashrate, 0)
|
51 | 47 | })
|
52 | 48 | })
|
53 | 49 |
|
54 | 50 | describe('web3_sha3', () => {
|
55 | 51 | it('should get result of a sha3', async () => {
|
56 |
| - web3['_requestManager'].send({ method: 'web3_sha3', params: ['0x68656c6c6f20776f726c64']}) |
57 |
| - .then(result => assert.equal(result, '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad')) |
58 |
| - .catch(err => { throw new Error(err)} ) |
| 52 | + const result = await ethersProvider.send("web3_sha3", ['0x68656c6c6f20776f726c64']) |
| 53 | + assert.equal(result, '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad') |
59 | 54 | })
|
60 | 55 | })
|
61 | 56 |
|
62 | 57 | describe('eth_getCompilers', () => {
|
63 | 58 | it('should get list of compilers', async () => {
|
64 |
| - web3['_requestManager'].send({ method: 'eth_getCompilers', params: []}) |
65 |
| - .then(result => assert.equal(result, 0)) |
66 |
| - .catch(err => { throw new Error(err) }) |
| 59 | + const result = await ethersProvider.send("eth_getCompilers", []) |
| 60 | + assert.equal(result, 0) |
67 | 61 | })
|
68 | 62 | })
|
69 | 63 |
|
70 | 64 | describe('eth_compileSolidity', () => {
|
71 | 65 | it('get unsupported result when requesting solidity compiler', async () => {
|
72 |
| - web3['_requestManager'].send({ method: 'eth_compileSolidity', params: []}) |
73 |
| - .then(result => assert.equal(result, 'unsupported')) |
74 |
| - .catch(err => { throw new Error(err) }) |
| 66 | + const result = await ethersProvider.send("eth_compileSolidity", []) |
| 67 | + assert.equal(result, 'unsupported') |
75 | 68 | })
|
76 | 69 | })
|
77 | 70 |
|
78 | 71 | describe('eth_compileLLL', () => {
|
79 | 72 | it('get unsupported result when requesting LLL compiler', async () => {
|
80 |
| - web3['_requestManager'].send({ method: 'eth_compileLLL', params: []}) |
81 |
| - .then(result => assert.equal(result, 'unsupported')) |
82 |
| - .catch(err => { throw new Error(err) }) |
| 73 | + const result = await ethersProvider.send("eth_compileLLL", []) |
| 74 | + assert.equal(result, 'unsupported') |
83 | 75 | })
|
84 | 76 | })
|
85 | 77 |
|
86 | 78 | describe('eth_compileSerpent', () => {
|
87 | 79 | it('get unsupported result when requesting serpent compiler', async () => {
|
88 |
| - web3['_requestManager'].send({ method: 'eth_compileSerpent', params: []}) |
89 |
| - .then(result => assert.equal(result, 'unsupported')) |
90 |
| - .catch(err => { throw new Error(err)} ) |
| 80 | + const result = await ethersProvider.send("eth_compileSerpent", []) |
| 81 | + assert.equal(result, 'unsupported') |
91 | 82 | })
|
92 | 83 | })
|
93 | 84 | })
|
0 commit comments