Skip to content

Commit

Permalink
manual nonce managment
Browse files Browse the repository at this point in the history
Signed-off-by: Charles Ferrell <[email protected]>
  • Loading branch information
ferrell-code committed Jun 26, 2024
1 parent aee547f commit 051dfc2
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tests/chain-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {ApiPromise} from "@polkadot/api";
import {KeyringPair} from "@polkadot/keyring/types";
import {blake2AsHex} from "@polkadot/util-crypto";
import {BN} from "@polkadot/util";
import { Index } from "@polkadot/types/interfaces";

export const timer = (ms: number) => new Promise(res => setTimeout(res, ms))

Expand All @@ -20,19 +21,25 @@ export async function execute_with_root_via_governance(
extrinsicData: any,
) {
const encodedCallData = extrinsicData.method.toHex();
await api.tx.preimage.notePreimage(encodedCallData).signAndSend(keyring, {nonce: -1});
let nonce = await api.rpc.system.accountNextIndex(keyring.address);

await api.tx.preimage.notePreimage(encodedCallData).signAndSend(keyring, {nonce});
nonce = nonce.addn(1) as Index;

console.log("Runtime upgrade preimage noted ...");
let encodedCallDataHash = blake2AsHex(encodedCallData);
let externalProposeDefault = await api.tx.democracy.externalProposeDefault({
let externalProposeDefault = api.tx.democracy.externalProposeDefault({
Legacy: {
hash: encodedCallDataHash
}
});
const encodedExternalProposeDefault = externalProposeDefault.method.toHex();
await api.tx.council.propose(1, encodedExternalProposeDefault, encodedExternalProposeDefault.length).signAndSend(keyring, {nonce: -1});
await api.tx.council.propose(1, encodedExternalProposeDefault, encodedExternalProposeDefault.length).signAndSend(keyring, {nonce});
nonce = nonce.addn(1) as Index;
console.log("Runtime upgrade governance proposed ...");
let fastTrackCall = await api.tx.democracy.fastTrack(encodedCallDataHash, 1, 1);
let fastTrackCall = api.tx.democracy.fastTrack(encodedCallDataHash, 1, 1);
await api.tx.technicalCommittee.propose(1, fastTrackCall, fastTrackCall.encodedLength).signAndSend(keyring, {nonce: -1});
nonce = nonce.addn(1) as Index;
console.log("Runtime upgrade governance fast tracked ...");
const parachainId = Number(await api.query.parachainInfo.parachainId());
let balance = new BN("1000000000000"); // Calamari: 12
Expand All @@ -41,7 +48,7 @@ export async function execute_with_root_via_governance(
}
await api.tx.democracy.vote(referendumIndexObject.referendumIndex, {
Standard: { balance, vote: { aye: true, conviction: 1 } },
}).signAndSend(keyring, {nonce: -1});
}).signAndSend(keyring, {nonce});
console.log("Runtime upgrade governance voted on ...");
referendumIndexObject.referendumIndex++;
}
Expand All @@ -51,8 +58,10 @@ export async function execute_via_governance(
keyring: KeyringPair,
extrinsicData: any,
) {
let nonce = await api.rpc.system.accountNextIndex(keyring.address);
const encodedCallData = extrinsicData.method.toHex();
await api.tx.preimage.notePreimage(encodedCallData).signAndSend(keyring, {nonce: -1});
nonce = nonce.addn(1) as Index;

let encodedCallDataHash = blake2AsHex(encodedCallData);
let externalProposeDefault = await api.tx.democracy.externalProposeDefault({
Expand All @@ -62,6 +71,7 @@ export async function execute_via_governance(
});
const encodedExternalProposeDefault = externalProposeDefault.method.toHex();
await api.tx.council.propose(1, encodedExternalProposeDefault, encodedExternalProposeDefault.length).signAndSend(keyring, {nonce: -1});
nonce = nonce.addn(1) as Index;

let fastTrackCall = await api.tx.democracy.fastTrack(encodedCallDataHash, 3, 2);
await api.tx.technicalCommittee.propose(1, fastTrackCall, fastTrackCall.encodedLength).signAndSend(keyring, {nonce: -1});
Expand Down

0 comments on commit 051dfc2

Please sign in to comment.