-
Notifications
You must be signed in to change notification settings - Fork 358
/
Copy pathtest-democracy-preimage.ts
65 lines (58 loc) · 2.23 KB
/
test-democracy-preimage.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
import "@moonbeam-network/api-augment";
import { describeSuite, expect, notePreimage } from "@moonwall/cli";
import { ALITH_ADDRESS, MICROGLMR, alith } from "@moonwall/util";
import { blake2AsHex } from "@polkadot/util-crypto";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
describeSuite({
id: "D010901",
title: "Democracy - Preimage",
foundationMethods: "dev",
testCases: ({ context, it }) => {
it({
id: "T01",
title: "should be notable",
test: async function () {
const encodedProposal =
context
.polkadotJs()
.tx.parachainStaking.setParachainBondAccount(
privateKeyToAccount(generatePrivateKey()).address
)
.method.toHex() || "";
const encodedHash = blake2AsHex(encodedProposal);
await context.createBlock(context.polkadotJs().tx.preimage.notePreimage(encodedProposal));
const preimageStatus = (
await context.polkadotJs().query.preimage.requestStatusFor(encodedHash)
).toHuman();
expect(preimageStatus).to.not.be.undefined;
// TODO: uncomment when we have types
//expect(preimageStatus.unwrap().isUnrequested).to.be.true;
// TODO: change syntax when we have types
const proposer = preimageStatus!["Unrequested"]["ticket"][0];
const balance = preimageStatus!["Unrequested"]["ticket"][1].replaceAll(/,/g, "");
expect(proposer.toLowerCase()).to.eq(ALITH_ADDRESS.toLowerCase());
expect(BigInt(balance)).to.eq(5002200n * MICROGLMR);
},
});
it({
id: "T02",
title: "should be forgettable immediatly",
test: async function () {
const encodedHash = await notePreimage(
context,
context
.polkadotJs()
.tx.parachainStaking.setParachainBondAccount(
privateKeyToAccount(generatePrivateKey()).address
),
alith
);
await context.createBlock(context.polkadotJs().tx.preimage.unnotePreimage(encodedHash));
const preimageStatus = (await context
.polkadotJs()
.query.preimage.statusFor(encodedHash)) as any;
expect(preimageStatus.isSome).to.be.false;
},
});
},
});