From 894dfe2208ffee8bb392d57b24fc46e438cc88fa Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Thu, 5 Aug 2021 13:24:21 -0400 Subject: [PATCH] Restore sudo moonbase (#652) * Revert "Remove sudo from Moonriver (and Alphanet temporarily) (#650)" This reverts commit 2386b45071387d039906ee00a43072626eafb352. * remove sudo from moonriver (cherry picked from commit 89d17d5b8dfe6c374e1a7ae67bf68532c98d2505) * also remove it from the integration tests (cherry picked from commit d831ff082643985e7f3eedbee3c2a2c65a133f50) * restore pallet indeces * Revert "Skipping introduced test with sudo (#653)" This reverts commit 4f0bcad2f975abf71c3db8129e5e4b1738c0c732. --- Cargo.lock | 1 + node/service/src/chain_spec/moonbase.rs | 10 +- node/service/src/chain_spec/test_spec.rs | 2 +- runtime/moonbase/Cargo.toml | 4 +- runtime/moonbase/src/lib.rs | 10 +- runtime/moonbase/tests/integration_test.rs | 10 +- tests/tests/test-crowdloan.ts | 149 ++++++++++----------- tests/tests/test-parachain-bond.ts | 4 +- tests/tests/test-sudo.ts | 9 +- tests/tests/test-treasury-proposal.ts | 4 +- 10 files changed, 102 insertions(+), 101 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e80b4ca97a..f7d80b031d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4937,6 +4937,7 @@ dependencies = [ "pallet-randomness-collective-flip", "pallet-scheduler", "pallet-society", + "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", diff --git a/node/service/src/chain_spec/moonbase.rs b/node/service/src/chain_spec/moonbase.rs index 3385c58b7f..690a120bae 100644 --- a/node/service/src/chain_spec/moonbase.rs +++ b/node/service/src/chain_spec/moonbase.rs @@ -28,7 +28,7 @@ use moonbase_runtime::{ currency::UNIT, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig, CouncilCollectiveConfig, CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisConfig, InflationInfo, ParachainInfoConfig, - ParachainStakingConfig, Precompiles, Range, SchedulerConfig, /*SudoConfig,*/ SystemConfig, + ParachainStakingConfig, Precompiles, Range, SchedulerConfig, SudoConfig, SystemConfig, TechComitteeCollectiveConfig, WASM_BINARY, }; use nimbus_primitives::NimbusId; @@ -58,7 +58,7 @@ pub fn development_chain_spec(mnemonic: Option, num_accounts: Option ChainSpec { move || { testnet_genesis( // Alith is Sudo - // AccountId::from_str("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac").unwrap(), + AccountId::from_str("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac").unwrap(), // Council members: Baltathar, Charleth and Dorothy vec![ AccountId::from_str("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0").unwrap(), @@ -182,7 +182,7 @@ pub fn moonbeam_inflation_config() -> InflationInfo { } pub fn testnet_genesis( - // root_key: AccountId, + root_key: AccountId, council_members: Vec, tech_comittee_members: Vec, candidates: Vec<(AccountId, NimbusId, Balance)>, @@ -215,7 +215,7 @@ pub fn testnet_genesis( crowdloan_rewards: CrowdloanRewardsConfig { funded_amount: crowdloan_fund_pot, }, - // sudo: SudoConfig { key: root_key }, + sudo: SudoConfig { key: root_key }, parachain_info: ParachainInfoConfig { parachain_id: para_id, }, diff --git a/node/service/src/chain_spec/test_spec.rs b/node/service/src/chain_spec/test_spec.rs index 1f60bcc2d8..b752593c32 100644 --- a/node/service/src/chain_spec/test_spec.rs +++ b/node/service/src/chain_spec/test_spec.rs @@ -33,7 +33,7 @@ pub fn staking_spec(para_id: ParaId) -> ChainSpec { move || { testnet_genesis( // Root - // AccountId::from_str("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b").unwrap(), + AccountId::from_str("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b").unwrap(), // Council members: Baltathar, Charleth and Dorothy vec![ AccountId::from_str("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0").unwrap(), diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index 9188d2e227..e1824c8dd3 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -52,7 +52,7 @@ frame-system = { git = "https://github.com/paritytech/substrate", default-featur pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.8" } pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.8" } pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.8" } -# pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.8" } +pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.8" } pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.8" } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.8" } @@ -123,7 +123,7 @@ std = [ "pallet-randomness-collective-flip/std", "pallet-timestamp/std", "pallet-treasury/std", - #"pallet-sudo/std", + "pallet-sudo/std", "pallet-transaction-payment/std", "pallet-utility/std", "pallet-ethereum/std", diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 7dd3bc274f..54c57dfd64 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -268,10 +268,10 @@ impl pallet_transaction_payment::Config for Runtime { type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; } -// impl pallet_sudo::Config for Runtime { -// type Call = Call; -// type Event = Event; -// } +impl pallet_sudo::Config for Runtime { + type Call = Call; + type Event = Event; +} impl pallet_ethereum_chain_id::Config for Runtime {} @@ -774,7 +774,7 @@ construct_runtime! { Utility: pallet_utility::{Pallet, Call, Event} = 1, Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 2, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 3, - // Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event} = 4, + Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event} = 4, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 5, ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event} = 6, TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 7, diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index 10592fca0a..979ef72307 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -132,6 +132,14 @@ fn verify_pallet_prefixes() { } ] ); + assert_eq!( + ::storage_info(), + vec![StorageInfo { + prefix: prefix(b"Sudo", b"Key"), + max_values: Some(1), + max_size: Some(20), + }] + ); assert_eq!( ::storage_info(), vec![ @@ -161,7 +169,7 @@ fn verify_pallet_indices() { is_pallet_index::(1); is_pallet_index::(2); is_pallet_index::(3); - // Sudo was previously index 4 + is_pallet_index::(4); is_pallet_index::(5); is_pallet_index::(6); is_pallet_index::(7); diff --git a/tests/tests/test-crowdloan.ts b/tests/tests/test-crowdloan.ts index e8952d0b38..155683aca7 100644 --- a/tests/tests/test-crowdloan.ts +++ b/tests/tests/test-crowdloan.ts @@ -43,7 +43,7 @@ describeDevMoonbeam("Crowdloan", (context) => { genesisAccount = await keyring.addFromUri(GENESIS_ACCOUNT_PRIVATE_KEY, null, "ethereum"); sudoAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); }); - it.skip("should check initial state", async function () { + it("should check initial state", async function () { // check that genesis has genesis balance expect(Number(await context.web3.eth.getBalance(GENESIS_ACCOUNT))).to.eq( Number(GENESIS_ACCOUNT_BALANCE) @@ -54,7 +54,7 @@ describeDevMoonbeam("Crowdloan", (context) => { ); expect(isPayable.toHuman()).to.equal(null); }); - it.skip("should be able to register the genesis account for reward", async function () { + it("should be able to register the genesis account for reward", async function () { // should be able to register the genesis account for reward await context.polkadotApi.tx.sudo .sudo( @@ -95,7 +95,7 @@ describeDevMoonbeam("Crowdloan", (context) => { genesisAccount = await keyring.addFromUri(GENESIS_ACCOUNT_PRIVATE_KEY, null, "ethereum"); sudoAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); }); - it.skip("should be able to make a first claim", async function () { + it("should be able to make a first claim", async function () { await context.polkadotApi.tx.sudo .sudo( context.polkadotApi.tx.crowdloanRewards.initializeRewardVec([ @@ -165,7 +165,7 @@ describeDevMoonbeam("Crowdloan", (context) => { genesisAccount = await keyring.addFromUri(GENESIS_ACCOUNT_PRIVATE_KEY, null, "ethereum"); sudoAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); }); - it.skip("should show the money after 5 blocks, after first claim was called", async function () { + it("should show me the money after 5 blocks, after first claim was called", async function () { await context.polkadotApi.tx.sudo .sudo( context.polkadotApi.tx.crowdloanRewards.initializeRewardVec([ @@ -223,7 +223,7 @@ describeDevMoonbeam("Crowdloan", (context) => { genesisAccount = await keyring.addFromUri(GENESIS_ACCOUNT_PRIVATE_KEY, null, "ethereum"); sudoAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); }); - it.skip("should make first claim 5 blocks after initialization called", async function () { + it("should make first claim 5 blocks after initialization called", async function () { await context.polkadotApi.tx.sudo .sudo( context.polkadotApi.tx.crowdloanRewards.initializeRewardVec([ @@ -276,7 +276,7 @@ describeDevMoonbeam("Crowdloan", (context) => { genesisAccount = await keyring.addFromUri(GENESIS_ACCOUNT_PRIVATE_KEY, null, "ethereum"); sudoAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); }); - it.skip("should not be able to call initializeRewardVec another time", async function () { + it("should not be able to call initializeRewardVec another time", async function () { await context.polkadotApi.tx.sudo .sudo( context.polkadotApi.tx.crowdloanRewards.initializeRewardVec([ @@ -321,7 +321,7 @@ describeDevMoonbeam("Crowdloan", (context) => { alithAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); }); - it.skip("should be able to register the genesis account - with small amount", async function () { + it("should be able to register the genesis account - with small amount", async function () { // initializeRewardVec await context.polkadotApi.tx.sudo .sudo( @@ -380,7 +380,7 @@ describeDevMoonbeam("Crowdloan", (context) => { sudoAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); }); - it.skip("should be able to register many accounts : " + numberOfAccounts, async function () { + it("should be able to register many accounts : " + numberOfAccounts, async function () { // should create a bunch of test eth accounts this.timeout(30000); let web3 = new Web3(); @@ -449,79 +449,74 @@ describeDevMoonbeam("Crowdloan", (context) => { sudoAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); }); - it.skip( - "should be able to register many accounts - batch : " + numberOfAccounts, - async function () { - // should create a bunch of test eth accounts - this.timeout(20000); - let web3 = new Web3(); - let accounts = new Array(numberOfAccounts).fill(0).map((_, i) => web3.eth.accounts.create()); - largInput = accounts.map((acc: Account, i: number) => { - return [ - acc.address + "111111111111111111111111", - acc.address, - (3_000_000n * GLMR) / BigInt(numberOfAccounts), - ]; - }); - expect(largInput.length).to.eq(numberOfAccounts); - expect(largInput[0][1] !== largInput[numberOfAccounts - 1][1]).to.eq(true); - - // should be able to register many accounts - await context.polkadotApi.tx.utility - .batch([ - await context.polkadotApi.tx.sudo.sudo( - context.polkadotApi.tx.crowdloanRewards.initializeRewardVec( - largInput.slice(0, Math.floor(numberOfAccounts / 3)) - ) - ), - await context.polkadotApi.tx.sudo.sudo( - context.polkadotApi.tx.crowdloanRewards.initializeRewardVec( - largInput.slice( - Math.floor(numberOfAccounts / 3), - Math.floor((numberOfAccounts * 2) / 3) - ) - ) - ), - await context.polkadotApi.tx.sudo.sudo( - context.polkadotApi.tx.crowdloanRewards.initializeRewardVec( - largInput.slice(Math.floor((numberOfAccounts * 2) / 3), numberOfAccounts) + it("should be able to register many accounts - batch : " + numberOfAccounts, async function () { + // should create a bunch of test eth accounts + this.timeout(20000); + let web3 = new Web3(); + let accounts = new Array(numberOfAccounts).fill(0).map((_, i) => web3.eth.accounts.create()); + largInput = accounts.map((acc: Account, i: number) => { + return [ + acc.address + "111111111111111111111111", + acc.address, + (3_000_000n * GLMR) / BigInt(numberOfAccounts), + ]; + }); + expect(largInput.length).to.eq(numberOfAccounts); + expect(largInput[0][1] !== largInput[numberOfAccounts - 1][1]).to.eq(true); + + // should be able to register many accounts + await context.polkadotApi.tx.utility + .batch([ + await context.polkadotApi.tx.sudo.sudo( + context.polkadotApi.tx.crowdloanRewards.initializeRewardVec( + largInput.slice(0, Math.floor(numberOfAccounts / 3)) + ) + ), + await context.polkadotApi.tx.sudo.sudo( + context.polkadotApi.tx.crowdloanRewards.initializeRewardVec( + largInput.slice( + Math.floor(numberOfAccounts / 3), + Math.floor((numberOfAccounts * 2) / 3) ) - ), - ]) - .signAndSend(sudoAccount); - await context.createBlock(); + ) + ), + await context.polkadotApi.tx.sudo.sudo( + context.polkadotApi.tx.crowdloanRewards.initializeRewardVec( + largInput.slice(Math.floor((numberOfAccounts * 2) / 3), numberOfAccounts) + ) + ), + ]) + .signAndSend(sudoAccount); + await context.createBlock(); - let initBlock = (await context.polkadotApi.query.crowdloanRewards.initRelayBlock()) as any; + let initBlock = (await context.polkadotApi.query.crowdloanRewards.initRelayBlock()) as any; - // Complete initialization - await context.polkadotApi.tx.sudo - .sudo( - context.polkadotApi.tx.crowdloanRewards.completeInitialization( - Number(initBlock) + vesting - ) - ) - .signAndSend(sudoAccount); - await context.createBlock(); + // Complete initialization + await context.polkadotApi.tx.sudo + .sudo( + context.polkadotApi.tx.crowdloanRewards.completeInitialization(Number(initBlock) + vesting) + ) + .signAndSend(sudoAccount); + await context.createBlock(); - const rewardPerContributor = formatBalance( - (3_000_000n * GLMR) / BigInt(numberOfAccounts), - { withSi: true, withUnit: "UNIT" }, - 18 - ); + const rewardPerContributor = formatBalance( + (3_000_000n * GLMR) / BigInt(numberOfAccounts), + { withSi: true, withUnit: "UNIT" }, + 18 + ); - await Promise.all( - largInput.map(async (input) => { - expect( + await Promise.all( + largInput.map(async (input) => { + expect( + ( ( - ( - await context.polkadotApi.query.crowdloanRewards.accountsPayable(input[1]) - ).toHuman() as any - ).total_reward - ).to.equal(rewardPerContributor); - }) - ); - } - ); + await context.polkadotApi.query.crowdloanRewards.accountsPayable(input[1]) + ).toHuman() as any + ).total_reward + ).to.equal(rewardPerContributor); + }) + ); + }); }); describeDevMoonbeam("Crowdloan", (context) => { @@ -532,7 +527,7 @@ describeDevMoonbeam("Crowdloan", (context) => { genesisAccount = await keyring.addFromUri(GENESIS_ACCOUNT_PRIVATE_KEY, null, "ethereum"); sudoAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); }); - it.skip("should be able to initialize through democracy", async function () { + it("should be able to initialize through democracy", async function () { let calls = []; // We are gonna put the initialization and completion in a batch_all utility call calls.push( @@ -622,7 +617,7 @@ describeDevMoonbeam("Crowdloan", (context) => { genesisAccount = await keyring.addFromUri(GENESIS_ACCOUNT_PRIVATE_KEY, null, "ethereum"); sudoAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); }); - it.skip("should be able to burn the dust", async function () { + it("should be able to burn the dust", async function () { await context.polkadotApi.tx.sudo .sudo( context.polkadotApi.tx.crowdloanRewards.initializeRewardVec([ diff --git a/tests/tests/test-parachain-bond.ts b/tests/tests/test-parachain-bond.ts index 826408aa72..bb21cbcb0f 100644 --- a/tests/tests/test-parachain-bond.ts +++ b/tests/tests/test-parachain-bond.ts @@ -24,7 +24,7 @@ describeDevMoonbeam("Staking - Parachain Bond - genesis and setParachainBondAcco expect(parachainBondInfo.toHuman()["account"]).to.equal(ZERO_ADDRESS); expect(parachainBondInfo.toHuman()["percent"]).to.equal("30.00%"); }); - it.skip("should be able set the parachain bond with sudo", async function () { + it("should be able set the parachain bond with sudo", async function () { // should be able to register the genesis account for reward await context.polkadotApi.tx.sudo .sudo(context.polkadotApi.tx.parachainStaking.setParachainBondAccount(GENESIS_ACCOUNT)) @@ -96,7 +96,7 @@ describeDevMoonbeam("Staking - Parachain Bond - setParachainBondReservePercent", const keyring = new Keyring({ type: "ethereum" }); sudoAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); }); - it.skip("should be able set the parachain bond reserve percent with sudo", async function () { + it("should be able set the parachain bond reserve percent with sudo", async function () { // should be able to register the genesis account await context.polkadotApi.tx.sudo .sudo(context.polkadotApi.tx.parachainStaking.setParachainBondReservePercent(TWENTY_PERCENT)) diff --git a/tests/tests/test-sudo.ts b/tests/tests/test-sudo.ts index 60a5a4df06..84655691cd 100644 --- a/tests/tests/test-sudo.ts +++ b/tests/tests/test-sudo.ts @@ -10,16 +10,14 @@ import { } from "../util/constants"; import { describeDevMoonbeam } from "../util/setup-dev-tests"; -describeDevMoonbeam("Sudo - Sudo Calls", (context) => { +describeDevMoonbeam("Sudo - Only sudo account", (context) => { let genesisAccount: KeyringPair, sudoAccount: KeyringPair; - before("Setup genesis account for substrate", async () => { const keyring = new Keyring({ type: "ethereum" }); genesisAccount = await keyring.addFromUri(GENESIS_ACCOUNT_PRIVATE_KEY, null, "ethereum"); sudoAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); }); - - it.skip("should be restricted to sudo account", async function () { + it("should NOT be able to call sudo with another account than sudo account", async function () { await context.polkadotApi.tx.sudo .sudo(context.polkadotApi.tx.parachainStaking.setParachainBondAccount(GENESIS_ACCOUNT)) .signAndSend(genesisAccount); @@ -28,8 +26,7 @@ describeDevMoonbeam("Sudo - Sudo Calls", (context) => { expect(parachainBondInfo.toHuman()["account"]).to.equal(ZERO_ADDRESS); expect(parachainBondInfo.toHuman()["percent"]).to.equal("30.00%"); }); - - it.skip("should generate events with sudo section/method", async function () { + it("should check events", async function () { const blockHash = await context.polkadotApi.rpc.chain.getBlockHash(1); const signedBlock = await context.polkadotApi.rpc.chain.getBlock(blockHash); const allRecords = await context.polkadotApi.query.system.events.at( diff --git a/tests/tests/test-treasury-proposal.ts b/tests/tests/test-treasury-proposal.ts index bacb1a2c31..cb517bc014 100644 --- a/tests/tests/test-treasury-proposal.ts +++ b/tests/tests/test-treasury-proposal.ts @@ -109,7 +109,7 @@ describeDevMoonbeam("Treasury proposal #4", (context) => { }); describeDevMoonbeam("Treasury proposal #5", (context) => { - it.skip("should be approvable by root", async function () { + it("should be approvable by root", async function () { const keyring = new Keyring({ type: "ethereum" }); const alith = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); const ethan = await keyring.addFromUri(ETHAN_PRIVKEY, null, "ethereum"); @@ -135,7 +135,7 @@ describeDevMoonbeam("Treasury proposal #5", (context) => { }); describeDevMoonbeam("Treasury proposal #6", (context) => { - it.skip("should be rejectable by root", async function () { + it("should be rejectable by root", async function () { const keyring = new Keyring({ type: "ethereum" }); const alith = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum"); const ethan = await keyring.addFromUri(ETHAN_PRIVKEY, null, "ethereum");