forked from tact-lang/tact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet.spec.ts
68 lines (63 loc) · 2.35 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
56
57
58
59
60
61
62
63
64
65
66
67
68
import { storeTransfer, Transfer, Wallet } from "./output/wallet_Wallet";
import { ContractSystem, testKey } from "@tact-lang/emulator";
import { beginCell, toNano } from "@ton/core";
import { sign } from "@ton/crypto";
describe("wallet", () => {
it("should deploy", async () => {
// Create wallet
const key = testKey("wallet-key");
const publicKey = beginCell()
.storeBuffer(key.publicKey)
.endCell()
.beginParse()
.loadUintBig(256);
const system = await ContractSystem.create();
const treasure = system.treasure("treasure");
const contract = system.open(await Wallet.fromInit(publicKey, 0n));
const 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
const transfer: Transfer = {
$$type: "Transfer",
seqno: 0n,
mode: 1n,
amount: toNano(10),
to: treasure.address,
body: null,
};
const 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()
.asSlice(),
},
);
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);
});
});