diff --git a/tests/package.json b/tests/package.json index 01ca1ad5e8..c669f54d63 100644 --- a/tests/package.json +++ b/tests/package.json @@ -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", @@ -159,4 +160,4 @@ }, "type": "module", "packageManager": "yarn@3.6.1" -} \ No newline at end of file +} diff --git a/tests/src/proposeupgrade.ts b/tests/src/proposeupgrade.ts new file mode 100644 index 0000000000..a008f7ec40 --- /dev/null +++ b/tests/src/proposeupgrade.ts @@ -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();