-
Notifications
You must be signed in to change notification settings - Fork 321
/
test_moonbeam.ts
130 lines (116 loc) · 4.53 KB
/
test_moonbeam.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
import "@moonbeam-network/api-augment";
import { MoonwallContext, beforeAll, describeSuite, expect } from "@moonwall/cli";
import { BALTATHAR_ADDRESS, charleth } from "@moonwall/util";
import { ApiPromise } from "@polkadot/api";
import { Signer, ethers } from "ethers";
import fs from "node:fs";
describeSuite({
id: "ZAN",
title: "Zombie AlphaNet Upgrade Test",
foundationMethods: "zombie",
testCases: function ({ it, context, log }) {
let paraApi: ApiPromise;
let relayApi: ApiPromise;
let ethersSigner: Signer;
beforeAll(async () => {
paraApi = context.polkadotJs("parachain");
relayApi = context.polkadotJs("relaychain");
ethersSigner = context.ethers()!;
const relayNetwork = relayApi.consts.system.version.specName.toString();
expect(relayNetwork, "Relay API incorrect").to.contain("rococo");
const paraNetwork = paraApi.consts.system.version.specName.toString();
expect(paraNetwork, "Para API incorrect").to.contain("moonbeam");
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 function () {
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 function () {
const blockNumberBefore = (
await paraApi.rpc.chain.getBlock()
).block.header.number.toNumber();
const currentCode = (await paraApi.rpc.state.getStorage(":code")) as any;
const codeString = currentCode.toString();
const wasm = fs.readFileSync(MoonwallContext.getContext().rtUpgradePath!);
const rtHex = `0x${wasm.toString("hex")}`;
if (rtHex === codeString) {
log("Runtime already upgraded, skipping test");
return;
}
await context.upgradeRuntime({
logger: log,
runtimeName: "moonbeam",
localPath: MoonwallContext.getContext().rtUpgradePath,
useGovernance: true,
waitMigration: true,
runtimeTag: "local",
});
await context.waitBlock(2);
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: 60000,
test: async function () {
const balBefore = (await paraApi.query.system.account(BALTATHAR_ADDRESS)).data.free;
log("Please wait, this will take at least 30s for transaction to complete");
await new Promise((resolve) => {
paraApi.tx.balances
.transfer(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);
}
});
});
const balAfter = (await paraApi.query.system.account(BALTATHAR_ADDRESS)).data.free;
expect(balBefore.lt(balAfter)).to.be.true;
},
});
it({
id: "T04",
title: "Tags are present on emulated Ethereum blocks",
test: async function () {
expect(
(await ethersSigner.provider!.getBlock("safe"))!.number,
"Safe tag is not present"
).to.be.greaterThan(0);
expect(
(await ethersSigner.provider!.getBlock("finalized"))!.number,
"Finalized tag is not present"
).to.be.greaterThan(0);
expect(
(await ethersSigner.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"));
},
});
},
});