-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathchain.test.ts
More file actions
195 lines (180 loc) · 5.46 KB
/
chain.test.ts
File metadata and controls
195 lines (180 loc) · 5.46 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
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
import { TransactResult } from "eosjs/dist/eosjs-api-interfaces";
import { PushTransactionArgs } from "eosjs/dist/eosjs-rpc-interfaces";
import { Chain } from "../src/chain";
import { blockTimeToMs } from "../src/utils";
describe("chain test", () => {
let chain: Chain;
let chainName = process.env.CHAIN_NAME || "WAX";
afterAll(async () => {
await chain.clear();
}, 10000);
it("test setup chain", async () => {
chain = await Chain.setupChain(chainName);
const chainInfo = await chain.rpc.get_info();
expect(chainInfo.head_block_num).toBeGreaterThan(0);
expect(chainInfo.last_irreversible_block_num).toBeGreaterThan(0);
const testAccount1 = await chain.rpc.get_account("acc11.test");
const testAccount10 = await chain.rpc.get_account("acc25.test");
if (chain.systemContractEnable) {
expect(testAccount1.total_resources.net_weight).toBe(
chain.coreSymbol.convertAssetString(10)
);
expect(testAccount10.total_resources.net_weight).toBe(
chain.coreSymbol.convertAssetString(10)
);
}
}, 100000);
it("create account", async () => {
const newAccountName = "newaccount11";
await chain.system.createAccount(
newAccountName,
chain.coreSymbol.convertAssetString(11.11),
99998
);
const newAccountInfo = await chain.rpc.get_account(newAccountName);
if (chain.systemContractEnable) {
expect(newAccountInfo.total_resources.net_weight).toBe(
chain.coreSymbol.convertAssetString(10)
);
expect(newAccountInfo.total_resources.cpu_weight).toBe(
chain.coreSymbol.convertAssetString(10)
);
}
const newAccountBalance = await chain.rpc.get_currency_balance(
"eosio.token",
newAccountName,
chain.coreSymbol.symbol
);
expect(newAccountBalance[0]).toBe(
chain.coreSymbol.convertAssetString(11.11)
);
});
it("push action", async () => {
const testingAccountName = "newaccount11";
// @ts-ignore
const transaction: TransactResult = await chain.pushAction({
account: "eosio.token",
name: "transfer",
authorization: [
{
actor: testingAccountName,
permission: "active",
},
],
data: {
from: testingAccountName,
to: chain.accounts[0].name,
quantity: chain.coreSymbol.convertAssetString(1),
memo: "test",
},
});
expect(transaction.transaction_id.length).toBe(64);
expect(transaction.processed.block_num).toBeGreaterThan(0);
});
it("push multiple action", async () => {
const testingAccountName = "newaccount11";
// @ts-ignore
const transaction: TransactResult = await chain.pushActions([
{
account: "eosio.token",
name: "transfer",
authorization: [
{
actor: testingAccountName,
permission: "active",
},
],
data: {
from: testingAccountName,
to: chain.accounts[0].name,
quantity: chain.coreSymbol.convertAssetString(1),
memo: "test",
},
},
{
account: "eosio.token",
name: "transfer",
authorization: [
{
actor: testingAccountName,
permission: "active",
},
],
data: {
from: testingAccountName,
to: chain.accounts[1].name,
quantity: chain.coreSymbol.convertAssetString(1),
memo: "test",
},
},
]);
expect(transaction.transaction_id.length).toBe(64);
expect(transaction.processed.block_num).toBeGreaterThan(0);
});
it("should sign transaction only without broadcast", async () => {
const testingAccountName = "newaccount11";
// @ts-ignore
const transaction: PushTransactionArgs = await chain.pushActions(
[
{
account: "eosio.token",
name: "transfer",
authorization: [
{
actor: testingAccountName,
permission: "active",
},
],
data: {
from: testingAccountName,
to: chain.accounts[0].name,
quantity: chain.coreSymbol.convertAssetString(1),
memo: "test",
},
},
{
account: "eosio.token",
name: "transfer",
authorization: [
{
actor: testingAccountName,
permission: "active",
},
],
data: {
from: testingAccountName,
to: chain.accounts[1].name,
quantity: chain.coreSymbol.convertAssetString(1),
memo: "test",
},
},
],
false,
true
);
expect(transaction.signatures.length).toBe(1);
expect(transaction.signatures[0].startsWith("SIG_K1_")).toBe(true);
expect(transaction.serializedTransaction.length).toBeGreaterThan(0);
});
it("add time", async () => {
const currentBlockTime = await blockTimeToMs(
(
await chain.getInfo()
).head_block_time
);
await chain.time.increase(344);
const blockTimeAfterAdd1 = await blockTimeToMs(
(
await chain.getInfo()
).head_block_time
);
expect(blockTimeAfterAdd1 - currentBlockTime).toBeGreaterThan(344);
await chain.time.increase(34567);
const blockTimeAfterAdd2 = await blockTimeToMs(
(
await chain.getInfo()
).head_block_time
);
expect(blockTimeAfterAdd2 - blockTimeAfterAdd1).toBeGreaterThan(34567);
}, 100000);
});