Skip to content

Commit

Permalink
feat: propose-upgrade governance script (#1019)
Browse files Browse the repository at this point in the history
* feat: governance scripts

* fix: move propose-upgrade script to tests
  • Loading branch information
mrshiposha authored Oct 17, 2023
1 parent 8af05a8 commit 092e9b8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@
"polkadot-types-from-defs": "ts-node --esm ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",
"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"
"generateEnv": "ts-node --esm ./src/generateEnv.ts",
"propose-upgrade": "ts-node --esm ./src/proposeupgrade.ts"
},
"author": "",
"license": "SEE LICENSE IN ../LICENSE",
Expand Down Expand Up @@ -159,4 +160,4 @@
},
"type": "module",
"packageManager": "[email protected]"
}
}
39 changes: 39 additions & 0 deletions tests/src/proposeupgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {ApiPromise, WsProvider} from '@polkadot/api';
import {blake2AsHex} from '@polkadot/util-crypto';
import {readFileSync} from 'fs';

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

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

const wasmFileBytes = readFileSync(wasmFile);
const wasmFileHash = blake2AsHex(wasmFileBytes, 256);

const authorizeUpgrade = api.tx.parachainSystem.authorizeUpgrade(wasmFileHash, true);

const councilMembers = (await api.query.council.members()).toJSON() as any[];
const councilProposalThreshold = Math.floor(councilMembers.length / 2) + 1;

const democracyProposal = api.tx.democracy.externalProposeDefault({
Inline: authorizeUpgrade.method.toHex(),
});

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

const encodedCall = councilProposal.method.toHex();

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

await api.disconnect();
}

await main();

0 comments on commit 092e9b8

Please sign in to comment.