-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcontract.test.ts
More file actions
117 lines (105 loc) · 3.31 KB
/
contract.test.ts
File metadata and controls
117 lines (105 loc) · 3.31 KB
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
import { Chain, Contract, Account } from "../src";
import { expectAction, expectThrow, expectBalance } from "../src/assertion";
describe("account test", () => {
let chain: Chain;
let contract: Contract;
let chainName = process.env.CHAIN_NAME || "WAX";
let contractAccount, user1, user2, user3: Account;
beforeAll(async () => {
chain = await Chain.setupChain(chainName);
[contractAccount, user1, user2, user3] = chain.accounts;
await contractAccount.addCode("active");
contract = await contractAccount.setContract({
abi: "./contracts/build/testcontract.abi",
wasm: "./contracts/build/testcontract.wasm",
});
}, 60000);
afterAll(async () => {
await chain.clear();
}, 10000);
describe("action test", function () {
it("push action", async () => {
let transaction = await contract.action.testaction(
{ user: contractAccount.name },
[{ actor: contractAccount.name, permission: "active" }]
);
expect(transaction.processed.action_traces[0].console).toBe(
" hello " + contractAccount.name
);
await expectThrow(
contract.action.testaction({ user: "daniel" }, [
{ actor: contractAccount.name, permission: "active" },
]),
"missing authority of daniel"
);
}, 100000);
});
describe("table test", function () {
it("table test", async () => {
let transaction = await contract.action.testtable(
{
user: user1.name,
value1: 2291,
value2: "98123",
},
[{ actor: user1.name, permission: "active" }]
);
const lastRow = await contract.table.logs.getLastRow({
scope: user1.name,
});
expect(lastRow.value1).toBe(2291);
expect(lastRow.value2).toBe("98123");
}, 100000);
});
describe("inline action test", function () {
it("inline action check the transaction matches with action", async () => {
let transaction = await contract.action.testtable(
{
user: user1.name,
value1: 123,
value2: "456789",
},
[{ actor: user1.name, permission: "active" }]
);
const lastRow = await contract.table.logs.getLastRow({
scope: user1.name,
});
expectAction(
transaction,
contract.account.name,
"testlog",
{
user: user1.name,
id: lastRow.id,
value1: 123,
value2: "456789",
},
[{ actor: contract.account.name, permission: "active" }]
);
}, 100000);
it("inline action check the transaction contains with action", async () => {
let transaction = await contract.action.testtable(
{
user: user1.name,
value1: 234,
value2: "456789",
},
[{ actor: user1.name, permission: "active" }]
);
await expectAction(transaction, contract.account.name, "testlog", {
user: "acc12.test",
});
await expect(
expectAction(transaction, contract.account.name, "testlog", {
user: "acc12.test",
value1: 235,
})
).rejects.toThrowError("Expected: ");
await expect(
expectAction(transaction, contract.account.name, "testlog", {
data: "fake",
})
).rejects.toThrowError("Expected: ");
}, 100000);
});
});