-
Notifications
You must be signed in to change notification settings - Fork 42
/
loop.ts
90 lines (82 loc) · 2.58 KB
/
loop.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
import { types } from "@algo-builder/web";
import { assert } from "chai";
import { RUNTIME_ERRORS } from "../../src/errors/errors-list";
import { AccountStore, Runtime } from "../../src/index";
import { useFixture } from "../helpers/integration";
import { expectRuntimeError } from "../helpers/runtime-errors";
describe("TEALv4: Loops", function () {
useFixture("loop");
const john = new AccountStore(10e6);
let runtime: Runtime;
let approvalProgramPassFileName: string;
let approvalProgramFailFileName: string;
let approvalProgramFail1FileName: string;
let clearProgramFilename: string;
let clearProgramV3: string;
let appDefinition: types.AppDefinitionFromFile;
this.beforeAll(async function () {
runtime = new Runtime([john]); // setup test
approvalProgramPassFileName = "approval-pass.teal";
approvalProgramFailFileName = "approval-fail.teal";
approvalProgramFail1FileName = "approval-fail-1.teal";
clearProgramFilename = "clear.teal";
clearProgramV3 = "clearv3.teal";
appDefinition = {
appName: "app",
metaType: types.MetaType.FILE,
approvalProgramFilename: approvalProgramPassFileName,
clearProgramFilename,
globalBytes: 1,
globalInts: 1,
localBytes: 1,
localInts: 1,
};
});
it("should pass during create application", function () {
// this code will pass, because at the end we check if counter is incremented 10 times
assert.doesNotThrow(() => runtime.deployApp(john.account, appDefinition, {}));
});
it("should fail during create application", function () {
// this fails because in last condition we check if counter value with 10.
expectRuntimeError(
() =>
runtime.deployApp(
john.account,
{ ...appDefinition, approvalProgramFilename: approvalProgramFailFileName },
{}
),
RUNTIME_ERRORS.TEAL.REJECTED_BY_LOGIC
);
});
it("should fail during create application", function () {
// this fails because we try to use loops in tealv3
expectRuntimeError(
() =>
runtime.deployApp(
john.account,
{
...appDefinition,
approvalProgramFilename: approvalProgramFail1FileName,
clearProgramFilename: clearProgramV3,
},
{}
),
RUNTIME_ERRORS.TEAL.LABEL_NOT_FOUND
);
});
it("should skip b1 & b2 (continuous labels)", function () {
approvalProgramPassFileName = "continuous-labels.teal";
// this code will pass, because at the end we check if counter is incremented 10 times
assert.doesNotThrow(() =>
runtime.deployApp(
john.account,
{
...appDefinition,
appName: "skipApp",
approvalProgramFilename: approvalProgramPassFileName,
},
{}
)
);
});
});