git.delta.rocks / unique-network / refs/commits / 867eaa10a099

difftreelog

Merge pull request #993 from UniqueNetwork/fix/governance-with-batch

Yaroslav Bolyukin2023-09-13parents: #e089f01 #e0258a2.patch.diff
in: master
Fix/governance with batch

10 files changed

modifiedCargo.tomldiffbeforeafterboth
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -119,6 +119,7 @@
 pallet-state-trie-migration = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
 pallet-sudo = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
 pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
+pallet-utility = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
 pallet-transaction-payment = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
 pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
 pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
modifiedruntime/common/config/governance/technical_committee.rsdiffbeforeafterboth
--- a/runtime/common/config/governance/technical_committee.rs
+++ b/runtime/common/config/governance/technical_committee.rs
@@ -38,7 +38,7 @@
 	type RemoveOrigin = RootOrMoreThanHalfCouncil;
 	type SwapOrigin = RootOrMoreThanHalfCouncil;
 	type ResetOrigin = EnsureRoot<AccountId>;
-	type PrimeOrigin = EnsureRoot<AccountId>;
+	type PrimeOrigin = RootOrMoreThanHalfCouncil;
 	type MembershipInitialized = TechnicalCommittee;
 	type MembershipChanged = TechnicalCommittee;
 	type MaxMembers = TechnicalMaxMembers;
modifiedruntime/common/config/substrate.rsdiffbeforeafterboth
--- a/runtime/common/config/substrate.rs
+++ b/runtime/common/config/substrate.rs
@@ -35,8 +35,8 @@
 };
 use pallet_transaction_payment::{Multiplier, ConstFeeMultiplier};
 use crate::{
-	runtime_common::DealWithFees, Runtime, RuntimeEvent, RuntimeCall, RuntimeOrigin, PalletInfo,
-	System, Balances, SS58Prefix, Version,
+	runtime_common::DealWithFees, Runtime, RuntimeEvent, RuntimeCall, RuntimeOrigin, OriginCaller,
+	PalletInfo, System, Balances, SS58Prefix, Version,
 };
 use up_common::{types::*, constants::*};
 use sp_std::vec;
@@ -248,3 +248,10 @@
 	type DisabledValidators = ();
 	type MaxAuthorities = MaxAuthorities;
 }
+
+impl pallet_utility::Config for Runtime {
+	type RuntimeEvent = RuntimeEvent;
+	type RuntimeCall = RuntimeCall;
+	type PalletsOrigin = OriginCaller;
+	type WeightInfo = pallet_utility::weights::SubstrateWeight<Self>;
+}
modifiedruntime/common/construct_runtime.rsdiffbeforeafterboth
--- a/runtime/common/construct_runtime.rs
+++ b/runtime/common/construct_runtime.rs
@@ -136,6 +136,8 @@
 
 				BalancesAdapter: pallet_balances_adapter = 155,
 
+				Utility: pallet_utility = 156,
+
 				#[cfg(feature = "pallet-test-utils")]
 				TestUtils: pallet_test_utils = 255,
 			}
modifiedruntime/opal/Cargo.tomldiffbeforeafterboth
--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -58,6 +58,7 @@
 	'pallet-refungible/runtime-benchmarks',
 	'pallet-structure/runtime-benchmarks',
 	'pallet-timestamp/runtime-benchmarks',
+	'pallet-utility/runtime-benchmarks',
 	'pallet-unique-scheduler-v2/runtime-benchmarks',
 	'pallet-unique/runtime-benchmarks',
 	'pallet-xcm/runtime-benchmarks',
@@ -120,6 +121,7 @@
 	'pallet-structure/std',
 	'pallet-sudo/std',
 	'pallet-timestamp/std',
+	'pallet-utility/std',
 	'pallet-transaction-payment-rpc-runtime-api/std',
 	'pallet-transaction-payment/std',
 	'pallet-treasury/std',
@@ -213,6 +215,7 @@
 	'pallet-sudo/try-runtime',
 	'pallet-test-utils?/try-runtime',
 	'pallet-timestamp/try-runtime',
+	'pallet-utility/try-runtime',
 	'pallet-transaction-payment/try-runtime',
 	'pallet-treasury/try-runtime',
 	'pallet-unique-scheduler-v2/try-runtime',
@@ -263,6 +266,7 @@
 pallet-state-trie-migration = { workspace = true }
 pallet-sudo = { workspace = true }
 pallet-timestamp = { workspace = true }
+pallet-utility = { workspace = true }
 pallet-transaction-payment = { workspace = true }
 pallet-transaction-payment-rpc-runtime-api = { workspace = true }
 pallet-treasury = { workspace = true }
modifiedruntime/quartz/Cargo.tomldiffbeforeafterboth
--- a/runtime/quartz/Cargo.toml
+++ b/runtime/quartz/Cargo.toml
@@ -55,6 +55,7 @@
 	'pallet-scheduler/runtime-benchmarks',
 	'pallet-structure/runtime-benchmarks',
 	'pallet-timestamp/runtime-benchmarks',
+	'pallet-utility/runtime-benchmarks',
 	'pallet-unique/runtime-benchmarks',
 	'pallet-xcm/runtime-benchmarks',
 	'sp-runtime/runtime-benchmarks',
@@ -120,6 +121,7 @@
 	'pallet-structure/std',
 	'pallet-sudo/std',
 	'pallet-timestamp/std',
+	'pallet-utility/std',
 	'pallet-transaction-payment-rpc-runtime-api/std',
 	'pallet-transaction-payment/std',
 	'pallet-treasury/std',
@@ -203,6 +205,7 @@
 	'pallet-structure/try-runtime',
 	'pallet-sudo/try-runtime',
 	'pallet-timestamp/try-runtime',
+	'pallet-utility/try-runtime',
 	'pallet-transaction-payment/try-runtime',
 	'pallet-treasury/try-runtime',
 	'pallet-unique/try-runtime',
@@ -252,6 +255,7 @@
 pallet-state-trie-migration = { workspace = true }
 pallet-sudo = { workspace = true }
 pallet-timestamp = { workspace = true }
+pallet-utility = { workspace = true }
 pallet-transaction-payment = { workspace = true }
 pallet-transaction-payment-rpc-runtime-api = { workspace = true }
 pallet-treasury = { workspace = true }
modifiedruntime/unique/Cargo.tomldiffbeforeafterboth
--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -52,6 +52,7 @@
 	'pallet-scheduler/runtime-benchmarks',
 	'pallet-structure/runtime-benchmarks',
 	'pallet-timestamp/runtime-benchmarks',
+	'pallet-utility/runtime-benchmarks',
 	'pallet-unique/runtime-benchmarks',
 	'pallet-xcm/runtime-benchmarks',
 	'sp-runtime/runtime-benchmarks',
@@ -118,6 +119,7 @@
 	'pallet-structure/std',
 	'pallet-sudo/std',
 	'pallet-timestamp/std',
+	'pallet-utility/std',
 	'pallet-transaction-payment-rpc-runtime-api/std',
 	'pallet-transaction-payment/std',
 	'pallet-treasury/std',
@@ -205,6 +207,7 @@
 	'pallet-structure/try-runtime',
 	'pallet-sudo/try-runtime',
 	'pallet-timestamp/try-runtime',
+	'pallet-utility/try-runtime',
 	'pallet-transaction-payment/try-runtime',
 	'pallet-treasury/try-runtime',
 	'pallet-unique/try-runtime',
@@ -255,6 +258,7 @@
 pallet-state-trie-migration = { workspace = true }
 pallet-sudo = { workspace = true }
 pallet-timestamp = { workspace = true }
+pallet-utility = { workspace = true }
 pallet-transaction-payment = { workspace = true }
 pallet-transaction-payment-rpc-runtime-api = { workspace = true }
 pallet-treasury = { workspace = true }
addedtests/src/governance/init.test.tsdiffbeforeafterboth
after · tests/src/governance/init.test.ts
1import {IKeyringPair} from '@polkadot/types/types';2import {usingPlaygrounds, itSub, expect, Pallets, requirePalletsOrSkip, describeGov} from '../util';3import {Event} from '../util/playgrounds/unique.dev';4import {ICounselors, democracyLaunchPeriod, democracyVotingPeriod, ITechComms, democracyEnactmentPeriod, clearCouncil, clearTechComm, clearFellowship} from './util';56describeGov('Governance: Initialization', () => {7  let donor: IKeyringPair;8  let sudoer: IKeyringPair;9  let counselors: ICounselors;10  let techcomms: ITechComms;11  let coreDevs: any;1213  const expectedAlexFellowRank = 7;14  const expectedFellowRank = 6;1516  before(async function() {17    await usingPlaygrounds(async (helper, privateKey) => {18      requirePalletsOrSkip(this, helper, [Pallets.Democracy, Pallets.Council, Pallets.TechnicalCommittee]);1920      const councilMembers = await helper.council.membership.getMembers();21      const techcommMembers = await helper.technicalCommittee.membership.getMembers();22      expect(councilMembers.length == 0, 'The Council must be empty before the Gov Init');23      expect(techcommMembers.length == 0, 'The Technical Commettee must be empty before the Gov Init');2425      donor = await privateKey({url: import.meta.url});26      sudoer = await privateKey('//Alice');2728      const counselorsNum = 5;29      const techCommsNum = 3;30      const coreDevsNum = 2;31      const [32        alex,33        ildar,34        charu,35        filip,36        irina,3738        greg,39        andy,40        constantine,4142        yaroslav,43        daniel,44      ] = await helper.arrange.createAccounts(new Array(counselorsNum + techCommsNum + coreDevsNum).fill(10_000n), donor);4546      counselors = {47        alex,48        ildar,49        charu,50        filip,51        irina,52      };5354      techcomms = {55        greg,56        andy,57        constantine,58      };5960      coreDevs = {61        yaroslav: yaroslav,62        daniel: daniel,63      };64    });65  });6667  itSub('Initialize Governance', async ({helper}) => {68    const promoteFellow = (fellow: string, promotionsNum: number) => new Array(promotionsNum).fill(helper.fellowship.collective.promoteCall(fellow));6970    const expectFellowRank = async (fellow: string, expectedRank: number) => {71      expect(await helper.fellowship.collective.getMemberRank(fellow)).to.be.equal(expectedRank);72    };7374    console.log('\t- Setup the Prime of the Council via sudo');75    await helper.getSudo().utility.batchAll(sudoer, [76      helper.council.membership.addMemberCall(counselors.alex.address),77      helper.council.membership.setPrimeCall(counselors.alex.address),7879      helper.fellowship.collective.addMemberCall(counselors.alex.address),80      ...promoteFellow(counselors.alex.address, expectedAlexFellowRank),81    ]);8283    let councilMembers = await helper.council.membership.getMembers();84    const councilPrime = await helper.council.collective.getPrimeMember();85    const alexFellowRank = await helper.fellowship.collective.getMemberRank(counselors.alex.address);86    expect(councilMembers).to.be.deep.equal([counselors.alex.address]);87    expect(councilPrime).to.be.equal(counselors.alex.address);88    expect(alexFellowRank).to.be.equal(expectedAlexFellowRank);8990    console.log('\t- The Council Prime initializes the Technical Commettee');91    const councilProposalThreshold = 1;9293    await helper.council.collective.propose(94      counselors.alex,95      helper.utility.batchAllCall([96        helper.technicalCommittee.membership.addMemberCall(techcomms.greg.address),97        helper.technicalCommittee.membership.addMemberCall(techcomms.andy.address),98        helper.technicalCommittee.membership.addMemberCall(techcomms.constantine.address),99100        helper.technicalCommittee.membership.setPrimeCall(techcomms.greg.address),101      ]),102      councilProposalThreshold,103    );104105    const techCommMembers = await helper.technicalCommittee.membership.getMembers();106    const techCommPrime = await helper.technicalCommittee.membership.getPrimeMember();107    const expectedTechComms = [techcomms.greg.address, techcomms.andy.address, techcomms.constantine.address];108    expect(techCommMembers.length).to.be.equal(expectedTechComms.length);109    expect(techCommMembers).to.containSubset(expectedTechComms);110    expect(techCommPrime).to.be.equal(techcomms.greg.address);111112    console.log('\t- The Council Prime initiates a referendum to add counselors');113    const returnPreimageHash = true;114    const preimageHash = await helper.preimage.notePreimageFromCall(counselors.alex, helper.utility.batchAllCall([115      helper.council.membership.addMemberCall(counselors.ildar.address),116      helper.council.membership.addMemberCall(counselors.charu.address),117      helper.council.membership.addMemberCall(counselors.filip.address),118      helper.council.membership.addMemberCall(counselors.irina.address),119120      helper.fellowship.collective.addMemberCall(counselors.charu.address),121      helper.fellowship.collective.addMemberCall(counselors.ildar.address),122      helper.fellowship.collective.addMemberCall(counselors.irina.address),123      helper.fellowship.collective.addMemberCall(counselors.filip.address),124      helper.fellowship.collective.addMemberCall(techcomms.greg.address),125      helper.fellowship.collective.addMemberCall(techcomms.andy.address),126      helper.fellowship.collective.addMemberCall(techcomms.constantine.address),127      helper.fellowship.collective.addMemberCall(coreDevs.yaroslav.address),128      helper.fellowship.collective.addMemberCall(coreDevs.daniel.address),129130      ...promoteFellow(counselors.charu.address, expectedFellowRank),131      ...promoteFellow(counselors.ildar.address, expectedFellowRank),132      ...promoteFellow(counselors.irina.address, expectedFellowRank),133      ...promoteFellow(counselors.filip.address, expectedFellowRank),134      ...promoteFellow(techcomms.greg.address, expectedFellowRank),135      ...promoteFellow(techcomms.andy.address, expectedFellowRank),136      ...promoteFellow(techcomms.constantine.address, expectedFellowRank),137      ...promoteFellow(coreDevs.yaroslav.address, expectedFellowRank),138      ...promoteFellow(coreDevs.daniel.address, expectedFellowRank),139    ]), returnPreimageHash);140141    await helper.council.collective.propose(142      counselors.alex,143      helper.democracy.externalProposeDefaultWithPreimageCall(preimageHash),144      councilProposalThreshold,145    );146147    console.log('\t- The referendum is being decided');148    const startedEvent = await helper.wait.expectEvent(democracyLaunchPeriod, Event.Democracy.Started);149150    await helper.democracy.vote(counselors.filip, startedEvent.referendumIndex, {151      Standard: {152        vote: {153          aye: true,154          conviction: 1,155        },156        balance: 10_000n,157      },158    });159160    const passedReferendumEvent = await helper.wait.expectEvent(democracyVotingPeriod, Event.Democracy.Passed);161    expect(passedReferendumEvent.referendumIndex).to.be.equal(startedEvent.referendumIndex);162163    await helper.wait.expectEvent(democracyEnactmentPeriod, Event.Scheduler.Dispatched);164165    councilMembers = await helper.council.membership.getMembers();166    const expectedCounselors = [167      counselors.alex.address,168      counselors.ildar.address,169      counselors.charu.address,170      counselors.filip.address,171      counselors.irina.address,172    ];173    expect(councilMembers.length).to.be.equal(expectedCounselors.length);174    expect(councilMembers).to.containSubset(expectedCounselors);175176    await expectFellowRank(counselors.ildar.address, expectedFellowRank);177    await expectFellowRank(counselors.charu.address, expectedFellowRank);178    await expectFellowRank(counselors.filip.address, expectedFellowRank);179    await expectFellowRank(counselors.irina.address, expectedFellowRank);180    await expectFellowRank(techcomms.greg.address, expectedFellowRank);181    await expectFellowRank(techcomms.andy.address, expectedFellowRank);182    await expectFellowRank(techcomms.constantine.address, expectedFellowRank);183    await expectFellowRank(coreDevs.yaroslav.address, expectedFellowRank);184    await expectFellowRank(coreDevs.daniel.address, expectedFellowRank);185  });186187  after(async function() {188    await clearFellowship(sudoer);189    await clearTechComm(sudoer);190    await clearCouncil(sudoer);191  });192});
modifiedtests/src/pallet-presence.test.tsdiffbeforeafterboth
--- a/tests/src/pallet-presence.test.ts
+++ b/tests/src/pallet-presence.test.ts
@@ -27,6 +27,7 @@
   'statetriemigration',
   'structure',
   'system',
+  'utility',
   'vesting',
   'parachainsystem',
   'parachaininfo',
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -3255,8 +3255,8 @@
     return this.helper.executeExtrinsic(signer, `api.tx.${this.collective}.promoteMember`, [member]);
   }
 
-  promoteCall(newMember: string) {
-    return this.helper.constructApiCall(`api.tx.${this.collective}.promoteMember`, [newMember]);
+  promoteCall(member: string) {
+    return this.helper.constructApiCall(`api.tx.${this.collective}.promoteMember`, [member]);
   }
 
   demote(signer: TSigner, member: string) {
@@ -3275,6 +3275,10 @@
     return (await this.helper.getApi().query.fellowshipCollective.members.keys())
       .map((key) => key.args[0].toString());
   }
+
+  async getMemberRank(member: string) {
+    return (await this.helper.callRpc('api.query.fellowshipCollective.members', [member])).toJSON().rank;
+  }
 }
 
 class ReferendaGroup extends HelperGroup<UniqueHelper> {
@@ -3381,6 +3385,10 @@
     return this.helper.constructApiCall('api.tx.democracy.externalProposeDefault', [{Inline: proposalCall.method.toHex()}]);
   }
 
+  externalProposeDefaultWithPreimageCall(preimage: string) {
+    return this.helper.constructApiCall('api.tx.democracy.externalProposeDefault', [{Legacy: preimage}]);
+  }
+
   // ... and blacklist external proposal hash.
   vetoExternal(signer: TSigner, proposalHash: string) {
     return this.helper.executeExtrinsic(signer, 'api.tx.democracy.vetoExternal', [proposalHash]);
@@ -3733,6 +3741,20 @@
   }
 }
 
+class UtilityGroup<T extends ChainHelperBase> extends HelperGroup<T> {
+  async batch(signer: TSigner, txs: any[]) {
+    return await this.helper.executeExtrinsic(signer, 'api.tx.utility.batch', [txs]);
+  }
+
+  async batchAll(signer: TSigner, txs: any[]) {
+    return await this.helper.executeExtrinsic(signer, 'api.tx.utility.batchAll', [txs]);
+  }
+
+  batchAllCall(txs: any[]) {
+    return this.helper.constructApiCall('api.tx.utility.batchAll', [txs]);
+  }
+}
+
 class AcalaAssetRegistryGroup extends HelperGroup<AcalaHelper> {
   async registerForeignAsset(signer: TSigner, destination: any, metadata: AcalaAssetMetadata) {
     await this.helper.executeExtrinsic(signer, 'api.tx.assetRegistry.registerForeignAsset', [destination, metadata], true);
@@ -3835,6 +3857,7 @@
   xcm: XcmGroup<UniqueHelper>;
   xTokens: XTokensGroup<UniqueHelper>;
   tokens: TokensGroup<UniqueHelper>;
+  utility: UtilityGroup<UniqueHelper>;
 
   constructor(logger?: ILogger, options: { [key: string]: any } = {}) {
     super(logger, options.helperBase ?? UniqueHelper);
@@ -3865,6 +3888,7 @@
     this.xcm = new XcmGroup(this, 'polkadotXcm');
     this.xTokens = new XTokensGroup(this);
     this.tokens = new TokensGroup(this);
+    this.utility = new UtilityGroup(this);
   }
 
   getSudo<T extends UniqueHelper>() {