Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add propose-fast-track #1022

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@
"polkadot-types-from-chain": "ts-node --esm ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",
"polkadot-types": "echo \"export default {}\" > src/interfaces/lookup.ts && yarn polkadot-types-fetch-metadata && yarn polkadot-types-from-defs && yarn polkadot-types-from-defs && yarn polkadot-types-from-chain",
"generateEnv": "ts-node --esm ./src/generateEnv.ts",
"propose-upgrade": "ts-node --esm ./src/proposeupgrade.ts"
"propose-upgrade": "ts-node --esm ./src/proposeupgrade.ts",
"propose-fast-track": "ts-node --esm ./src/proposefasttrack.ts"
},
"author": "",
"license": "SEE LICENSE IN ../LICENSE",
Expand Down
42 changes: 42 additions & 0 deletions tests/src/proposefasttrack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {ApiPromise, WsProvider} from '@polkadot/api';
import {blake2AsHex} from '@polkadot/util-crypto';

async function main() {
const networkUrl = process.argv[2];

const wsProvider = new WsProvider(networkUrl);
const api = await ApiPromise.create({provider: wsProvider});

const externalDemocracyProposal = (await api.query.democracy.nextExternal() as any).unwrap()[0];

let proposalHash;
if(externalDemocracyProposal.isInline) {
proposalHash = blake2AsHex(externalDemocracyProposal.asInline, 256);
} else if(externalDemocracyProposal.isLegacy) {
proposalHash = externalDemocracyProposal.asLegacy.toJSON().hash;
} else {
proposalHash = externalDemocracyProposal.asLookup.toJSON().hash;
}

const voringPeriod = 7200;
const delay = 10;

const democracyFastTrack = api.tx.democracy.fastTrack(proposalHash, voringPeriod, delay);

const techCommThreshold = ((await api.query.technicalCommittee.members()).toJSON() as any[]).length;
const techCommProposal = api.tx.technicalCommittee.propose(
techCommThreshold,
democracyFastTrack.method.toHex(),
democracyFastTrack.encodedLength,
);

const encodedCall = techCommProposal.method.toHex();

console.log('-----------------');
console.log('Fast Track Proposal: ', `https://polkadot.js.org/apps/?rpc=${networkUrl}#/extrinsics/decode/${encodedCall}`);
console.log('-----------------');

await api.disconnect();
}

await main();
22 changes: 16 additions & 6 deletions tests/src/proposeupgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,30 @@ async function main() {
const councilMembers = (await api.query.council.members()).toJSON() as any[];
const councilProposalThreshold = Math.floor(councilMembers.length / 2) + 1;

const democracyProposalContent = api.tx.utility.batchAll([
authorizeUpgrade.method.toHex(),
enableMaintenance.method.toHex(),
]).method.toHex();

const democracyProposalHash = blake2AsHex(democracyProposalContent, 256);
const democracyProposalPreimage = api.tx.preimage.notePreimage(democracyProposalContent).method.toHex();

const democracyProposal = api.tx.democracy.externalProposeDefault({
Inline: api.tx.utility.batchAll([
authorizeUpgrade.method.toHex(),
enableMaintenance.method.toHex(),
]).method.toHex(),
Legacy: democracyProposalHash,
});

const councilProposal = api.tx.council.propose(
councilProposalThreshold,
democracyProposal,
democracyProposal.method.encodedLength,
);
).method.toHex();

const proposeUpgradeBatch = api.tx.utility.batchAll([
democracyProposalPreimage,
councilProposal,
]);

const encodedCall = councilProposal.method.toHex();
const encodedCall = proposeUpgradeBatch.method.toHex();

console.log('-----------------');
console.log('Upgrade Proposal: ', `https://polkadot.js.org/apps/?rpc=${networkUrl}#/extrinsics/decode/${encodedCall}`);
Expand Down
Loading