This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
wallet.spec.ts
55 lines (49 loc) · 2.1 KB
/
wallet.spec.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
import { storeTransfer, Transfer, Wallet } from "./output/wallet_Wallet";
import { ContractSystem, testKey } from "ton-emulator";
import { beginCell, toNano } from "ton-core";
import { sign } from "ton-crypto";
describe('wallet', () => {
it('should deploy', async () => {
// Create wallet
let key = testKey('wallet-key');
let publicKey = beginCell().storeBuffer(key.publicKey).endCell().beginParse().loadUintBig(256);
let system = await ContractSystem.create();
let treasure = system.treasure('treasure');
let contract = system.open(await Wallet.fromInit(publicKey, 0n));
let tracker = system.track(contract.address);
await contract.send(treasure, { value: toNano('10') }, 'Deploy');
await system.run();
// Create executor
expect(await contract.getPublicKey()).toBe(publicKey);
expect(await contract.getWalletId()).toBe(0n);
expect(await contract.getSeqno()).toBe(0n);
// Send transfer and check seqno
let transfer: Transfer = {
$$type: 'Transfer',
seqno: 0n,
mode: 1n,
amount: toNano(10),
to: treasure.address,
body: null
};
let signature = sign(beginCell().store(storeTransfer(transfer)).endCell().hash(), key.secretKey);
await contract.send(treasure, { value: toNano(1) }, {
$$type: 'TransferMessage',
transfer,
signature: beginCell().storeBuffer(signature).endCell()
});
await system.run();
expect(tracker.collect()).toMatchSnapshot();
expect(await contract.getSeqno()).toBe(1n);
// Send empty message
await contract.send(treasure, { value: toNano(1) }, 'notify');
await system.run();
expect(tracker.collect()).toMatchSnapshot();
expect(await contract.getSeqno()).toBe(2n);
// Send comment message
await contract.send(treasure, { value: toNano(1) }, null);
await system.run();
expect(tracker.collect()).toMatchSnapshot();
expect(await contract.getSeqno()).toBe(3n);
});
});