forked from matter-labs/zksync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet.test.ts
91 lines (77 loc) · 3.65 KB
/
wallet.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { expect } from 'chai';
import { BigNumber, ethers } from 'ethers';
import { Wallet } from '../src/wallet';
import { getTokens } from 'reading-tool';
import { Provider } from '../src/provider';
import { Network } from '../src/types';
describe('Wallet with mock provider', function () {
async function getWallet(ethPrivateKey: Uint8Array, network: Network): Promise<Wallet> {
const ethWallet = new ethers.Wallet(ethPrivateKey);
const tokens = getTokens(network);
const mockProvider = await Provider.newMockProvider(network, ethPrivateKey, () => [...tokens]);
const wallet = await Wallet.fromEthSigner(ethWallet, mockProvider);
return wallet;
}
it('Wallet has valid address', async function () {
const key = new Uint8Array(new Array(32).fill(5));
const wallet = await getWallet(key, 'mainnet');
expect(wallet.address()).eq('0xd09Ad14080d4b257a819a4f579b8485Be88f086c', 'Wallet address does not match');
});
it("Wallet's account info has the same address as the wallet itself", async function () {
const key = new Uint8Array(new Array(32).fill(10));
const wallet = await getWallet(key, 'mainnet');
const accountState = await wallet.getAccountState();
expect(accountState.address).eq(wallet.address(), 'Wallet address does not match the accountState.address');
});
it('Wallet has defined account id', async function () {
const key = new Uint8Array(new Array(32).fill(14));
const wallet = await getWallet(key, 'mainnet');
const accountId = await wallet.getAccountId();
expect(accountId).eq(42, "Wallet's accountId does not match the hardcoded mock value");
});
it('Wallet has expected committed balances', async function () {
const key = new Uint8Array(new Array(32).fill(40));
const wallet = await getWallet(key, 'mainnet');
const balance = await wallet.getBalance('DAI', 'committed');
expect(balance).eql(
BigNumber.from(12345),
"Wallet's committed balance does not match the hardcoded mock value"
);
});
it('Wallet do not have unexpected committed balances', async function () {
const key = new Uint8Array(new Array(32).fill(40));
const wallet = await getWallet(key, 'mainnet');
let thrown = false;
try {
await wallet.getBalance('ETH', 'committed');
} catch {
thrown = true;
}
expect(thrown, 'getBalance call was expected to throw an exception').to.be.true;
});
it('Wallet has expected verified balances', async function () {
const key = new Uint8Array(new Array(32).fill(50));
const wallet = await getWallet(key, 'mainnet');
const balance = await wallet.getBalance('USDC', 'verified');
expect(balance).eql(
BigNumber.from(98765),
"Wallet's committed balance does not match the hardcoded mock value"
);
});
it('Wallet do not have unexpected verified balances', async function () {
const key = new Uint8Array(new Array(32).fill(50));
const wallet = await getWallet(key, 'mainnet');
let thrown = false;
try {
await wallet.getBalance('ETH', 'verified');
} catch {
thrown = true;
}
expect(thrown, 'getBalance call was expected to throw an exception').to.be.true;
});
it("Wallet's signing key checking", async function () {
const key = new Uint8Array(new Array(32).fill(60));
const wallet = await getWallet(key, 'mainnet');
expect(await wallet.isSigningKeySet()).eq(true, "Wallet's signing key is unset");
});
});