forked from cavanmflynn/ethers-multicall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
executable file
·56 lines (47 loc) · 1.71 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {InfuraProvider} from '@ethersproject/providers';
import { assert } from 'chai';
import { Contract, Provider } from '../src';
const provider = new InfuraProvider('mainnet');
const ethcallProvider = new Provider(provider, 1);
it('human readable abi', async () => {
const abi = ['function totalSupply() public view returns (uint256)'];
const addresses = [
'0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'
];
const yfiContract = new Contract(addresses[0], abi);
const uniContract = new Contract(addresses[1], abi);
const calls = [yfiContract.totalSupply(), uniContract.totalSupply()];
const [yfiSupply, uniSupply] = await ethcallProvider.all(calls);
assert.equal(yfiSupply.toString(), '36666000000000000000000');
assert.equal(uniSupply.toString(), '1000000000000000000000000000');
});
it('json abi', async () => {
const abi = [
{
constant: true,
inputs: [],
name: 'totalSupply',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256'
}
],
payable: false,
stateMutability: 'view',
type: 'function'
}
];
const addresses = [
'0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'
];
const yfiContract = new Contract(addresses[0], abi);
const uniContract = new Contract(addresses[1], abi);
const calls = [yfiContract.totalSupply(), uniContract.totalSupply()];
const [yfiSupply, uniSupply] = await ethcallProvider.all(calls);
assert.equal(yfiSupply.toString(), '36666000000000000000000');
assert.equal(uniSupply.toString(), '1000000000000000000000000000');
});