-
Notifications
You must be signed in to change notification settings - Fork 109
/
stdlib.spec.ts
110 lines (96 loc) · 3.63 KB
/
stdlib.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { Address, beginCell, toNano } from "@ton/core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox";
import { StdlibTest } from "./contracts/output/stdlib_StdlibTest";
import "@ton/test-utils";
describe("stdlib", () => {
let blockchain: Blockchain;
let treasure: SandboxContract<TreasuryContract>;
let contract: SandboxContract<StdlibTest>;
beforeEach(async () => {
blockchain = await Blockchain.create();
blockchain.verbosity.print = false;
treasure = await blockchain.treasury("treasure");
contract = blockchain.openContract(await StdlibTest.fromInit());
const deployResult = await contract.send(
treasure.getSender(),
{ value: toNano("10") },
null,
);
expect(deployResult.transactions).toHaveTransaction({
from: treasure.address,
to: contract.address,
success: true,
deploy: true,
});
});
it("should execute stdlib methods correctly", async () => {
const slice = beginCell()
.storeBit(1)
.storeBit(1)
.storeRef(beginCell().storeBit(1).endCell())
.endCell()
.asSlice();
// Execute and verify slice methods
expect(await contract.getSliceBits(slice)).toBe(2n);
expect(await contract.getSliceRefs(slice)).toBe(1n);
expect(await contract.getSliceEmpty(slice)).toBe(false);
expect(await contract.getLoadBool(slice)).toBe(true);
expect(await contract.getLoadBit(slice)).toBe(true);
expect(
(await contract.getStoreBool(beginCell(), true))
.endCell()
.toString(),
).toBe(beginCell().storeBit(true).endCell().toString());
expect(
(await contract.getStoreBit(beginCell(), true))
.endCell()
.toString(),
).toBe(beginCell().storeBit(true).endCell().toString());
expect(await contract.getTvm_2023_07Upgrade()).toEqual(1355n);
expect(await contract.getTvm_2024_04Upgrade()).toEqual(82009144n);
expect(
(
await contract.getStoreMaybeRef(
beginCell(),
beginCell().storeUint(123, 64).endCell(),
)
).endCell(),
).toEqualCell(
beginCell()
.storeMaybeRef(beginCell().storeUint(123, 64).endCell())
.endCell(),
);
expect(
(await contract.getStoreMaybeRef(beginCell(), null)).endCell(),
).toEqualCell(beginCell().storeMaybeRef(null).endCell());
const addrStd = await contract.getParseStdAddress(
beginCell()
.storeAddress(
Address.parse(
"0:4a81708d2cf7b15a1b362fbf64880451d698461f52f05f145b36c08517d76873",
),
)
.endCell()
.asSlice(),
);
expect(addrStd.workchain).toBe(0n);
expect(addrStd.address).toBe(
BigInt(
"0x4a81708d2cf7b15a1b362fbf64880451d698461f52f05f145b36c08517d76873",
),
);
const addrVar = await contract.getParseVarAddress(
beginCell()
.storeUint(6, 3)
.storeUint(123, 9)
.storeUint(234, 32)
.storeUint(345, 123)
.endCell()
.asSlice(),
);
expect(addrVar.workchain).toBe(234n);
expect(addrVar.address.asCell()).toEqualCell(
beginCell().storeUint(345, 123).endCell(),
);
});
});