-
Notifications
You must be signed in to change notification settings - Fork 5
/
Fireworks.EdgeCases.spec.ts
485 lines (430 loc) · 19.2 KB
/
Fireworks.EdgeCases.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
import { Blockchain, BlockchainSnapshot, SandboxContract, TreasuryContract } from '@ton/sandbox';
import { Cell, toNano, beginCell } from '@ton/core';
import { ExitCode, Fireworks, OPCODES } from '../wrappers/Fireworks';
import '@ton/test-utils';
import { compile } from '@ton/blueprint';
import * as fs from 'fs';
describe('Edge Cases Tests', () => {
let code: Cell;
let blockchain: Blockchain;
let fireworks: SandboxContract<Fireworks>;
let launched_f1: SandboxContract<Fireworks>;
let launched_f2: SandboxContract<Fireworks>;
let launcher: SandboxContract<TreasuryContract>;
let initialState: BlockchainSnapshot;
beforeAll(async () => {
code = await compile('Fireworks');
blockchain = await Blockchain.create();
blockchain.verbosity = {
...blockchain.verbosity,
blockchainLogs: true,
vmLogs: 'vm_logs_full',
debugLogs: true,
print: false,
};
launcher = await blockchain.treasury('launcher');
fireworks = blockchain.openContract(
Fireworks.createFromConfig(
{
id: 0,
},
code
)
);
launched_f1 = blockchain.openContract(
Fireworks.createFromConfig(
{
id: 1,
},
code
)
);
launched_f2 = blockchain.openContract(
Fireworks.createFromConfig(
{
id: 2,
},
code
)
);
const deployer = await blockchain.treasury('deployer');
const deployResult = await fireworks.sendDeploy(deployer.getSender(), toNano('100'));
expect(deployResult.transactions).toHaveTransaction({
from: deployer.address,
to: fireworks.address,
deploy: true,
success: true,
});
initialState = blockchain.snapshot();
});
afterEach(async () => {
await blockchain.loadFrom(initialState);
});
it('compute phase | exit code = 0', async () => {
const body = beginCell().storeUint(OPCODES.FAKED_LAUNCH, 32).storeUint(ExitCode.Success, 8).endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('2.0'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: true,
exitCode: ExitCode.Success,
// exit code = 0 | Standard successful execution exit code.
op: OPCODES.FAKED_LAUNCH,
});
});
it('compute phase | exit code = 1', async () => {
const body = beginCell().storeUint(OPCODES.FAKED_LAUNCH, 32).storeUint(ExitCode.SuccessAlt, 8).endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('2.0'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: true,
exitCode: ExitCode.SuccessAlt,
// exit code = 1 | Alternative successful execution exit code.
op: OPCODES.FAKED_LAUNCH,
});
});
it('compute phase | exit code = 2', async () => {
const body = beginCell().storeUint(OPCODES.FAKED_LAUNCH, 32).storeUint(ExitCode.StackUnderflow, 8).endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('2.0'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
exitCode: ExitCode.StackUnderflow,
// exit code = 2 | Stack underflow. Last op-code consumed more elements than there are on the stacks.
op: OPCODES.FAKED_LAUNCH,
});
});
it('compute phase | exit code = 3', async () => {
const body = beginCell().storeUint(OPCODES.FAKED_LAUNCH, 32).storeUint(ExitCode.StackOverflow, 8).endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('2.0'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
exitCode: ExitCode.StackOverflow,
// exit code = 3 | Stack overflow. More values have been stored on a stack than allowed by this version of TVM.
op: OPCODES.FAKED_LAUNCH,
});
});
it('compute phase | exit code = 4', async () => {
const maxUint256 = 115792089237316195423570985008687907853269984665640564039457584007913129639935n;
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.IntegerOverflow, 8)
.storeUint(maxUint256, 256)
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('2.0'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
exitCode: ExitCode.IntegerOverflow,
// exit code = 4 | Integer overflow. Integer does not fit into −2256 ≤ x < 2256 or a division by zero has occurred.
op: OPCODES.FAKED_LAUNCH,
});
});
it('compute phase | exit code = 5', async () => {
const negativeNumber = -5;
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.IntegerOutOfRange, 8)
.storeInt(negativeNumber, 8)
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('2.0'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
exitCode: ExitCode.IntegerOutOfRange,
// exit code = 5 | Integer out of expected range.
op: OPCODES.FAKED_LAUNCH,
});
});
it('compute phase | exit code = 6', async () => {
const body = beginCell().storeUint(OPCODES.FAKED_LAUNCH, 32).storeUint(ExitCode.InvalidOpcode, 8).endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('2.0'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
exitCode: ExitCode.InvalidOpcode,
// exit code = 6 | Invalid opcode. Instruction is unknown in the current TVM version.
op: OPCODES.FAKED_LAUNCH,
});
});
it('compute phase | exit code = 7', async () => {
const body = beginCell().storeUint(OPCODES.FAKED_LAUNCH, 32).storeUint(ExitCode.TypeCheckError, 8).endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('2.0'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
exitCode: ExitCode.TypeCheckError,
// exit code = 7 | Type check error. An argument to a primitive is of an incorrect value type.
op: OPCODES.FAKED_LAUNCH,
});
});
it('compute phase | exit code = 8', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.CellOverflow, 8)
.storeRef(beginCell().storeUint(1, 256).storeUint(2, 256).storeUint(3, 256).storeUint(4, 255).endCell()) // 1023 bits cell
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('2.0'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
exitCode: ExitCode.CellOverflow,
// exit code = 8 | Cell overflow. Writing to builder is not possible since after operation there would be more than 1023 bits or 4 references.
op: OPCODES.FAKED_LAUNCH,
});
});
it('compute phase | exit code = 9', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.CellUnderflow, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('2.0'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
exitCode: ExitCode.CellUnderflow,
// exit code = 9 | Stack underflow. Last TVM op-code consumed more elements than there are on the stacks.
op: OPCODES.FAKED_LAUNCH,
});
});
it('compute phase | exit code = 10', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.DictionaryError, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('2.0'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
exitCode: ExitCode.DictionaryError,
// exit code = 10 | Dictionary error. Error during manipulation with dictionary (hashmaps).
op: OPCODES.FAKED_LAUNCH,
});
});
it('compute phase | exit code = 11', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.UnknownError, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('2.0'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
exitCode: ExitCode.UnknownError,
// exit code = 11 | Most oftenly caused by trying to call get-method whose id wasn't found in the code (missing method_id modifier or wrong get-method name specified when trying to call it). In TVM docs its described as "Unknown error, may be thrown by user programs".
op: OPCODES.FAKED_LAUNCH,
});
});
it('compute phase | exit code = -14', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.OutOfGasError, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('0.003'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
exitCode: ExitCode.OutOfGasErrorAlt,
// exit code = -14 | It means out of gas error, same as 13. Negative, because it cannot be faked
op: OPCODES.FAKED_LAUNCH,
});
});
it('compute phase | exit code = 0xffff', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(123, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('1'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
exitCode: 0xffff,
// exit code = 0xffff (65535 in decimal) | This usually means that the received opcode is unknown to the contract. When writing contracts, this code is set by the developer himself.
op: OPCODES.FAKED_LAUNCH,
});
});
it('action phase | exit code = 32', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.ActionListInvalid, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('1'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
actionResultCode: ExitCode.ActionListInvalid,
// exit code = 32 | Action list is invalid. Set during action phase if c5 register after execution contains unparsable object.
op: OPCODES.FAKED_LAUNCH,
});
});
it('action phase | exit code = 33', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.ActionListTooLong, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('1'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
actionResultCode: ExitCode.ActionListTooLong,
// exit code = 33 | Action list is too long.
op: OPCODES.FAKED_LAUNCH,
});
});
it('action phase | exit code = 34', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.ActionInvalid, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('1'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
actionResultCode: ExitCode.ActionInvalid,
// exit code = 34 | Action is invalid or not supported. Set during action phase if current action cannot be applied.
op: OPCODES.FAKED_LAUNCH,
});
});
it('action phase | exit code = 35', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.InvalidSrcAddr, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('1'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
actionResultCode: ExitCode.InvalidSrcAddr,
// exit code = 35 | Invalid Source address in outbound message.
op: OPCODES.FAKED_LAUNCH,
});
});
it('action phase | exit code = 36', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.InvalidDstAddr, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('1'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
actionResultCode: ExitCode.InvalidDstAddr,
// exit code = 36 | Invalid Destination address in outbound message.
op: OPCODES.FAKED_LAUNCH,
});
});
it('action phase | exit code = 37', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.NotEnoughTON, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('1'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
actionResultCode: ExitCode.NotEnoughTON,
// exit code = 37 | Not enough TON. Message sends too much TON (or there is not enough TON after deducting fees).
op: OPCODES.FAKED_LAUNCH,
});
});
it('action phase | exit code = 38', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.NotEnoughExtraCurrencies, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('1'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
actionResultCode: ExitCode.NotEnoughExtraCurrencies,
// exit code = 38 | Not enough extra-currencies.
op: OPCODES.FAKED_LAUNCH,
});
});
it('action phase | exit code = 40', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.NotEnoughFounds, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('1'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
actionResultCode: ExitCode.NotEnoughFounds,
// exit code = 40 | Not enough funds to process a message. This error is thrown when there is only enough gas to cover part of the message, but does not cover it completely.
op: OPCODES.FAKED_LAUNCH,
});
});
it('action phase | exit code = 43', async () => {
const body = beginCell()
.storeUint(OPCODES.FAKED_LAUNCH, 32)
.storeUint(ExitCode.LibOutOfLimit, 8)
.storeRef(beginCell().endCell())
.endCell();
const launchResult = await fireworks.sendBadMessage(launcher.getSender(), toNano('1'), body);
expect(launchResult.transactions).toHaveTransaction({
from: launcher.address,
to: fireworks.address,
success: false,
aborted: true,
actionResultCode: ExitCode.LibOutOfLimit,
// exit code = 43 | The maximum number of cells in the library is exceeded or the maximum depth of the Merkle tree is exceeded.
op: OPCODES.FAKED_LAUNCH,
});
});
});