-
Notifications
You must be signed in to change notification settings - Fork 358
/
Copy pathtest-clear-suicided-contracts.ts
89 lines (78 loc) · 2.72 KB
/
test-clear-suicided-contracts.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
import {
describeSuite,
expect,
deployCreateCompiledContract,
fetchCompiledContract,
beforeAll,
} from "@moonwall/cli";
import { createEthersTransaction } from "@moonwall/util";
import { encodeFunctionData } from "viem";
import { expectOk } from "../../../../helpers";
import { ApiPromise } from "@polkadot/api";
describeSuite({
id: "D012301",
title: "Lazy Migrations Pallet - Clear Suicided Storage",
foundationMethods: "dev",
testCases: ({ context, it }) => {
let api: ApiPromise;
beforeAll(async () => {
api = context.polkadotJs();
});
it({
id: "T01",
title:
"Should clear storage entries of multiple suicided contracts within the deletion limit.",
test: async function () {
const { abi } = fetchCompiledContract("Storage");
for (let i = 0; i < 3; i++) {
const { contractAddress } = await deployCreateCompiledContract(context, "Storage");
// Create storage entries for the contract
const rawSigned = await createEthersTransaction(context, {
to: contractAddress,
data: encodeFunctionData({
abi,
args: [0, 200],
functionName: "store",
}),
gasLimit: 13_000_000,
});
await expectOk(context.createBlock(rawSigned));
await context.createBlock();
// Delete the contract to make it a suicided contract
const rawTx = await createEthersTransaction(context, {
to: contractAddress,
data: encodeFunctionData({
abi,
functionName: "destroy",
}),
gasLimit: 2_000_000,
});
const { result } = await context.createBlock(rawTx);
const receipt = await context
.viem("public")
.getTransactionReceipt({ hash: result?.hash as `0x${string}` });
expect(receipt.status).toBe("success");
// Call the extrinsic to delete the storage entries
const tx = await context.createBlock(
api.tx.moonbeamLazyMigrations.clearSuicidedStorage([contractAddress], 199)
);
await expect(!tx.result?.successful, "The contract storage cannot be removed");
// Remove "Suicided" flag
await context.createBlock(
api.tx.sudo.sudo(
api.tx.system.killStorage([api.query.evm.suicided.key(contractAddress)])
)
);
// Now, the storage can be removed
await expectOk(
context.createBlock(
context
.polkadotJs()
.tx.moonbeamLazyMigrations.clearSuicidedStorage([contractAddress], 199)
)
);
}
},
});
},
});