-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathHelloWorld.spec.ts
166 lines (145 loc) · 4.52 KB
/
HelloWorld.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { comment, toNano } from '@ton/core';
import {
Blockchain,
printTransactionFees,
SandboxContract,
TreasuryContract
} from '@ton/sandbox';
import '@ton/test-utils';
import { HelloWorld } from '../build/HelloWorld/tact_HelloWorld';
import { HelloWorldV2 } from '../build/HelloWorld/tact_HelloWorldV2';
describe('HelloWorld', () => {
let blockchain: Blockchain;
let deployer: SandboxContract<TreasuryContract>;
let contract: SandboxContract<HelloWorld>;
beforeAll(async () => {
blockchain = await Blockchain.create();
deployer = await blockchain.treasury('deployer');
contract = blockchain.openContract(
await HelloWorld.fromInit(
deployer.address,
)
);
});
it('deploy with hello', async () => {
const tx = await contract.send(
deployer.getSender(),
{
value: toNano('1'),
bounce: false,
},
'hello'
);
console.log('deploy with hello');
printTransactionFees(tx.transactions);
expect(tx.transactions).toHaveTransaction({
from: deployer.address,
to: contract.address,
success: true,
op: 0x0,
})
expect(tx.transactions).toHaveTransaction({
from: contract.address,
to: deployer.address,
success: true,
body: comment("hello, owner"),
})
const ver = await contract.getVersion();
expect(ver).toEqual('v1');
});
it('hello from anomynous', async () => {
const anomynous = await blockchain.treasury("anonynous");
const tx = await contract.send(
anomynous.getSender(),
{
value: toNano('1'),
bounce: false,
},
'hello'
);
console.log('hello from anomynous');
printTransactionFees(tx.transactions);
expect(tx.transactions).toHaveTransaction({
from: anomynous.address,
to: contract.address,
success: true,
op: 0x0,
})
expect(tx.transactions).toHaveTransaction({
from: contract.address,
to: anomynous.address,
success: true,
body: comment("hello, world"),
})
});
it('upgrade to v2', async () => {
const v2Init = await HelloWorldV2.fromInit(
deployer.address,
);
const tx = await contract.send(
deployer.getSender(),
{
value: toNano("1"),
bounce: false,
},
{
$$type: "UpgradeContract",
queryId: BigInt("123"),
code: v2Init.init!!.code,
data: null,
responseDestination: deployer.getSender().address,
}
)
console.log('upgrade to v2');
printTransactionFees(tx.transactions);
expect(tx.transactions).toHaveTransaction({
from: deployer.address,
to: contract.address,
success: true,
op: 0x112a9509,
})
expect(tx.transactions).toHaveTransaction({
from: contract.address,
to: deployer.address,
success: true,
op: 0xd53276db,
})
const ver = await contract.getVersion();
expect(ver).toEqual('v2');
});
it('downgrade to v1', async () => {
const v1Init = await HelloWorld.fromInit(
deployer.address,
);
const tx = await contract.send(
deployer.getSender(),
{
value: toNano("1"),
bounce: false,
},
{
$$type: "UpgradeContract",
queryId: BigInt("123"),
code: v1Init.init!!.code,
data: null,
responseDestination: deployer.getSender().address,
}
)
console.log('downgrade to v1');
printTransactionFees(tx.transactions);
expect(tx.transactions).toHaveTransaction({
from: deployer.address,
to: contract.address,
success: true,
op: 0x112a9509,
})
expect(tx.transactions).toHaveTransaction({
from: contract.address,
to: deployer.address,
success: true,
op: 0xd53276db,
})
const ver = await contract.getVersion();
expect(ver).toEqual('v1');
});
});