-
Notifications
You must be signed in to change notification settings - Fork 358
/
Copy pathtest_para.ts
158 lines (134 loc) · 5.49 KB
/
test_para.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
import "@moonbeam-network/api-augment";
import { MoonwallContext, beforeAll, describeSuite, expect } from "@moonwall/cli";
import { BALTATHAR_ADDRESS, alith, charleth } from "@moonwall/util";
import { ApiPromise } from "@polkadot/api";
import { ethers } from "ethers";
import fs from "node:fs";
describeSuite({
id: "Z01",
title: "Zombie AlphaNet Upgrade Test",
foundationMethods: "zombie",
testCases: ({ it, context, log }) => {
let paraApi: ApiPromise;
let relayApi: ApiPromise;
beforeAll(async () => {
paraApi = context.polkadotJs("parachain");
relayApi = context.polkadotJs("relaychain");
const currentBlock = (await paraApi.rpc.chain.getBlock()).block.header.number.toNumber();
expect(currentBlock, "Parachain not producing blocks").to.be.greaterThan(0);
}, 120000);
it({
id: "T01",
title: "Blocks are being produced on parachain",
test: async () => {
const blockNum = (await paraApi.rpc.chain.getBlock()).block.header.number.toNumber();
expect(blockNum).to.be.greaterThan(0);
},
});
it({
id: "T02",
title: "Chain can be upgraded",
timeout: 600000,
test: async () => {
const currentCode = (await paraApi.rpc.state.getStorage(":code")) as any;
const codeString = currentCode.toString();
const upgradePath = (await MoonwallContext.getContext()).rtUpgradePath;
const rtBefore = paraApi.consts.system.version.specVersion.toNumber();
if (!upgradePath) {
throw new Error("Runtime upgrade path not set");
}
const wasm = fs.readFileSync(upgradePath);
const rtHex = `0x${wasm.toString("hex")}`;
if (rtHex === codeString) {
log("Runtime already upgraded, skipping test");
return;
}
log("Runtime not upgraded, proceeding with test");
log(`Current runtime hash: ${rtHex.slice(0, 10)}...${rtHex.slice(-10)}`);
log(`New runtime hash: ${codeString.slice(0, 10)}...${codeString.slice(-10)}`);
const blockNumberBefore = (
await paraApi.rpc.chain.getBlock()
).block.header.number.toNumber();
await paraApi.tx.parachainSystem.enactAuthorizedUpgrade(rtHex).signAndSend(alith);
await context.waitBlock(15);
const rtafter = paraApi.consts.system.version.specVersion.toNumber();
expect(rtafter).to.be.greaterThan(rtBefore);
log(`RT upgrade has increased specVersion from ${rtBefore} to ${rtafter}`);
const blockNumberAfter = (
await paraApi.rpc.chain.getBlock()
).block.header.number.toNumber();
log(`Before: #${blockNumberBefore}, After: #${blockNumberAfter}`);
expect(blockNumberAfter, "Block number did not increase").to.be.greaterThan(
blockNumberBefore
);
},
});
it({
id: "T03",
title: "Can connect to parachain and execute a transaction",
timeout: 240000,
test: async () => {
const balBefore = (await paraApi.query.system.account(BALTATHAR_ADDRESS)).data.free;
log("Please wait, this will take at least 30s for transaction to complete");
// TODO: Renable the below when we are using polkadot 1.7.0
// There is a discrepancy with polkadotJs and 1.3.0
//
// await new Promise((resolve, reject) => {
// paraApi.tx.balances
// .transferAllowDeath(BALTATHAR_ADDRESS, ethers.parseEther("2"))
// .signAndSend(charleth, ({ status, events }) => {
// if (status.isInBlock) {
// log("Transaction is in block");
// }
// if (status.isFinalized) {
// log("Transaction is finalized!");
// resolve(events);
// }
// if (
// status.isDropped ||
// status.isInvalid ||
// status.isUsurped ||
// status.isFinalityTimeout
// ) {
// reject("transaction failed!");
// throw new Error("Transaction failed");
// }
// });
// })
await paraApi.tx.balances
.transferAllowDeath(BALTATHAR_ADDRESS, ethers.parseEther("2"))
.signAndSend(charleth);
// TODO: Remove waitBlock below when we are using polkadot 1.7.0
await context.waitBlock(6);
const balAfter = (await paraApi.query.system.account(BALTATHAR_ADDRESS)).data.free;
expect(
balBefore.lt(balAfter),
`${balBefore.toHuman()} is not less than ${balAfter.toHuman()}`
).to.be.true;
},
});
it({
id: "T04",
title: "Tags are present on emulated Ethereum blocks",
test: async () => {
expect(
(await context.ethers().provider?.getBlock("safe"))?.number,
"Safe tag is not present"
).to.be.greaterThan(0);
expect(
(await context.ethers().provider?.getBlock("finalized"))?.number,
"Finalized tag is not present"
).to.be.greaterThan(0);
expect(
(await context.ethers().provider?.getBlock("latest"))?.number,
"Latest tag is not present"
).to.be.greaterThan(0);
// log(await ethersSigner.provider.getTransactionCount(ALITH_ADDRESS, "latest"));
// await context
// .ethers()
// .sendTransaction({ to: BALTATHAR_ADDRESS, value: ethers.parseEther("1") });
// log(await ethersSigner.provider.getTransactionCount(ALITH_ADDRESS, "pending"));
},
});
},
});