-
Notifications
You must be signed in to change notification settings - Fork 109
/
getters.spec.ts
87 lines (75 loc) · 2.85 KB
/
getters.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
import { beginCell, toNano } from "@ton/core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox";
import { Test, Test_getterMapping } from "./contracts/output/getters_Test";
import "@ton/test-utils";
describe("getters", () => {
let blockchain: Blockchain;
let treasure: SandboxContract<TreasuryContract>;
let contract: SandboxContract<Test>;
beforeEach(async () => {
blockchain = await Blockchain.create();
blockchain.verbosity.print = false;
treasure = await blockchain.treasury("treasure");
contract = blockchain.openContract(await Test.fromInit());
const deployResult = await contract.send(
treasure.getSender(),
{ value: toNano("10") },
{
$$type: "Deploy",
queryId: 0n,
},
);
expect(deployResult.transactions).toHaveTransaction({
from: treasure.address,
to: contract.address,
success: true,
deploy: true,
});
});
it("should implement getters correctly", async () => {
// Getter name conflicts
expect(await contract.getTestGetter()).toBe(1n);
expect(await contract.gettest_getter()).toBe(2n);
expect(await contract.getTest_getter()).toBe(3n);
expect(Test_getterMapping["testGetter"]).toBe("getTestGetter");
expect(Test_getterMapping["test_getter"]).toBe("gettest_getter");
expect(Test_getterMapping["Test_getter"]).toBe("getTest_getter");
// Passing `S` struct to getter
expect(
await contract.getStructAsInput({
$$type: "S",
a: 1n,
b: 2n,
}),
).toMatchSnapshot();
// Returning `self` from getter
expect(await contract.getContractData()).toMatchSnapshot();
// Passing `SetIdAndData` message to getter
expect(
await contract.getMessageAsInput1({
$$type: "SetIdAndData",
id: 42n,
data: beginCell().endCell(),
}),
).toBe(42n);
expect(
await contract.getMessageAsInput2({
$$type: "SetIdAndData",
id: 42n,
data: beginCell().endCell(),
}),
).toMatchSnapshot();
// Passing `Test` contract data to getter
expect(
await contract.getContractAsInput({
$$type: "Test$Data",
id: 123n,
anotherData: beginCell().storeUint(123, 64).endCell(),
}),
).toMatchSnapshot();
expect(await contract.getMethodIdExpr()).toBe(true);
expect(await contract.getMethodIdConst()).toBe(2n ** 14n);
expect(await contract.getMethodIdMin()).toBe(true);
expect(await contract.getMethodIdMax()).toBe(true);
});
});