Skip to content

Commit

Permalink
Mesh 1310/ensure 11_governance_management can be re-run without resta…
Browse files Browse the repository at this point in the history
…rting node (#674)

* minor changes

* minor change

* fixed re-run issue

* minor change

Co-authored-by: Adam Dossa <adam.dossa@gmail.com>
Co-authored-by: poly-auto-merge[bot] <65769705+poly-auto-merge[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 15, 2020
1 parent f4c88a3 commit 58f2de2
Show file tree
Hide file tree
Showing 3 changed files with 352 additions and 287 deletions.
1 change: 0 additions & 1 deletion scripts/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"dependencies": {
"@liftr/tscov": "^1.4.7",
"@polkadot/api": "^1.32.1",
"@polkadot/keyring": "^2.6.2",
"@polkadot/util": "^2.6.2",
"@polkadot/util-crypto": "^2.6.2",
"@types/clear": "^0.1.0",
Expand Down
43 changes: 28 additions & 15 deletions scripts/cli/tests/11_governance_management.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ module.exports = require("../util/init.js");

let { reqImports } = require("../util/init.js");

// Import the test keyring (already has dev keys for Alice, Bob, Charlie, Eve & Ferdie)
const testKeyring = require('@polkadot/keyring/testing');

// Sets the default exit code to fail unless the script runs successfully
process.exitCode = 1;

Expand All @@ -17,39 +14,48 @@ async function main() {
const testEntities = await reqImports.initMain(api);

let alice = testEntities[0];
let dave = await reqImports.generateRandomEntity(api);
let bob = await reqImports.generateRandomEntity(api);
let govCommittee1 = testEntities[2];
let govCommittee2 = testEntities[3];

await reqImports.createIdentities(api, [bob, govCommittee1, govCommittee2], alice);

// Bob needs some funds to use.
await reqImports.distributePolyBatch(api, [bob], reqImports.transfer_amount, alice);
await sendTx(alice, api.tx.sudo.sudo(api.tx.pips.setDefaultEnactmentPeriod(10)));
await reqImports.createIdentities(api, [bob, dave, govCommittee1, govCommittee2], alice);

await sendTx(alice, api.tx.staking.bond(bob.publicKey, 20000, "Staked"));
// Bob and Dave needs some funds to use.
await reqImports.distributePolyBatch(api, [bob, dave], reqImports.transfer_amount, alice);

await sendTx(dave, api.tx.staking.bond(bob.publicKey, 20000, "Staked"));
// Create a PIP which is then amended.
const setLimit = api.tx.pips.setActivePipLimit(42);
// Create a PIP, but first placing the cool-off period.
await sendTx(alice, api.tx.sudo.sudo(api.tx.pips.setProposalCoolOffPeriod(10)));

let firstPipCount = await api.query.pips.pipIdSequence();
await sendTx(bob, api.tx.pips.propose(setLimit, 10000000000, "google.com", "first"));
await sendTx(bob, api.tx.pips.amendProposal(0, "www.facebook.com", null));

await sendTx(bob, api.tx.pips.amendProposal(firstPipCount, "www.facebook.com", null));

// Create a PIP, but first remove the cool-off period.
await sendTx(alice, api.tx.sudo.sudo(api.tx.pips.setProposalCoolOffPeriod(0)));

let secondPipCount = await api.query.pips.pipIdSequence();
await sendTx(bob, api.tx.pips.propose(setLimit, 10000000000, "google.com", "second"));

// GC needs some funds to use.
await reqImports.distributePolyBatch(api, [govCommittee1, govCommittee2], reqImports.transfer_amount, alice);

// Snapshot and approve second PIP.
await sendTx(govCommittee1, api.tx.pips.snapshot());
const approvePIP = api.tx.pips.enactSnapshotResults([[1, { "Approve": "" }]]);
const voteApprove = api.tx.polymeshCommittee.voteOrPropose(true, approvePIP);
await sendTx(govCommittee1, voteApprove);
await sendTx(govCommittee2, voteApprove);
const approvePIP = api.tx.pips.enactSnapshotResults([[secondPipCount, { "Approve": "" }]]);
await voteResult(api, approvePIP, [govCommittee1, govCommittee2]);

// Finally reschedule, demonstrating that it had been scheduled.
await sendTx(alice, api.tx.pips.rescheduleExecution(1, null));
// Reject the first PIP
const rejectPIP = api.tx.pips.rejectProposal(firstPipCount);
await voteResult(api, rejectPIP, [govCommittee1, govCommittee2]);

// Finally reschedule, demonstrating that it had been scheduled.
await sendTx(alice, api.tx.pips.rescheduleExecution(secondPipCount, null));
if (reqImports.fail_count > 0) {
console.log("Failed");
} else {
Expand All @@ -68,4 +74,11 @@ async function sendTx(signer, tx) {
reqImports.nonces.set(signer.address, reqImports.nonces.get(signer.address).addn(1));
}

async function voteResult(api, tx, signers) {
const vote = api.tx.polymeshCommittee.voteOrPropose(true, tx);
for (let i = 0; i < signers.length; i++) {
await sendTx(signers[i], vote);
}
}

main().catch(console.error);
Loading

0 comments on commit 58f2de2

Please sign in to comment.