From ee3ae020840f76d39bf27db93f857fe7f4a417ce Mon Sep 17 00:00:00 2001 From: Szegoo Date: Mon, 17 Oct 2022 11:00:50 +0200 Subject: [PATCH 01/13] Utility: add more tests for batch/batchAll/forceBatch --- Cargo.lock | 1 + frame/utility/Cargo.toml | 1 + frame/utility/src/lib.rs | 12 ++++---- frame/utility/src/tests.rs | 61 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 49b3dd3cf957b..5a3c2aacd64a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6505,6 +6505,7 @@ dependencies = [ "frame-support", "frame-system", "pallet-balances", + "pallet-timestamp", "parity-scale-codec", "scale-info", "sp-core", diff --git a/frame/utility/Cargo.toml b/frame/utility/Cargo.toml index cbe2892d72dc7..973d678b81340 100644 --- a/frame/utility/Cargo.toml +++ b/frame/utility/Cargo.toml @@ -25,6 +25,7 @@ sp-std = { version = "4.0.0", default-features = false, path = "../../primitives [dev-dependencies] pallet-balances = { version = "4.0.0-dev", path = "../balances" } +pallet-timestamp = { version = "4.0.0-dev", path = "../timestamp" } sp-core = { version = "6.0.0", path = "../../primitives/core" } [features] diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index 9ae89097a9bc3..ed167a2f21b78 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -164,13 +164,13 @@ pub mod pallet { impl Pallet { /// Send a batch of dispatch calls. /// - /// May be called from any origin. + /// May be called from either the root or a signed origin. /// /// - `calls`: The calls to be dispatched from the same origin. The number of call must not /// exceed the constant: `batched_calls_limit` (available in constant metadata). /// - /// If origin is root then call are dispatch without checking origin filter. (This includes - /// bypassing `frame_system::Config::BaseCallFilter`). + /// If origin is root then the calls are dispatched without checking origin filter. (This + /// includes bypassing `frame_system::Config::BaseCallFilter`). /// /// # /// - Complexity: O(C) where C is the number of calls to be batched. @@ -291,13 +291,13 @@ pub mod pallet { /// Send a batch of dispatch calls and atomically execute them. /// The whole transaction will rollback and fail if any of the calls failed. /// - /// May be called from any origin. + /// May be called from either the root or a signed origin. /// /// - `calls`: The calls to be dispatched from the same origin. The number of call must not /// exceed the constant: `batched_calls_limit` (available in constant metadata). /// - /// If origin is root then call are dispatch without checking origin filter. (This includes - /// bypassing `frame_system::Config::BaseCallFilter`). + /// If origin is root then the calls are dispatched without checking origin filter. (This + /// includes bypassing `frame_system::Config::BaseCallFilter`). /// /// # /// - Complexity: O(C) where C is the number of calls to be batched. diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index ebd8dda81adbc..9cade82fd7084 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -92,6 +92,7 @@ frame_support::construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic, { System: frame_system::{Pallet, Call, Config, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, Utility: utility::{Pallet, Call, Event}, Example: example::{Pallet, Call}, @@ -140,6 +141,13 @@ impl pallet_balances::Config for Test { type AccountStore = System; type WeightInfo = (); } + +impl pallet_timestamp::Config for Test { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = ConstU64<3>; + type WeightInfo = (); +} parameter_types! { pub const MultisigDepositBase: u64 = 1; pub const MultisigDepositFactor: u64 = 1; @@ -175,6 +183,7 @@ type UtilityCall = crate::Call; use frame_system::Call as SystemCall; use pallet_balances::{Call as BalancesCall, Error as BalancesError}; +use pallet_timestamp::Call as TimestampCall; pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); @@ -679,3 +688,55 @@ fn none_origin_does_not_work() { assert_noop!(Utility::batch_all(RuntimeOrigin::none(), vec![]), BadOrigin); }) } + +#[test] +fn batch_doesnt_work_with_inherents() { + new_test_ext().execute_with(|| { + // fails because inherents expect the origin to be none. + assert_ok!(Utility::batch( + RuntimeOrigin::signed(1), + vec![RuntimeCall::Timestamp(TimestampCall::set { now: 42 }),] + )); + System::assert_last_event( + utility::Event::BatchInterrupted { + index: 0, + error: frame_system::Error::::CallFiltered.into(), + } + .into(), + ); + }) +} + +#[test] +fn force_batch_doesnt_work_with_inherents() { + new_test_ext().execute_with(|| { + // fails because inherents expect the origin to be none. + assert_ok!(Utility::force_batch( + RuntimeOrigin::root(), + vec![RuntimeCall::Timestamp(TimestampCall::set { now: 42 }),] + )); + System::assert_last_event(utility::Event::BatchCompletedWithErrors.into()); + }) +} + +#[test] +fn batch_all_doesnt_work_with_inherents() { + new_test_ext().execute_with(|| { + let batch_all = RuntimeCall::Utility(UtilityCall::batch_all { + calls: vec![RuntimeCall::Timestamp(TimestampCall::set { now: 42 })], + }); + let info = batch_all.get_dispatch_info(); + + // fails because inherents expect the origin to be none. + assert_noop!( + batch_all.dispatch(RuntimeOrigin::signed(1)), + DispatchErrorWithPostInfo { + post_info: PostDispatchInfo { + actual_weight: Some(info.weight), + pays_fee: Pays::Yes + }, + error: frame_system::Error::::CallFiltered.into(), + } + ); + }) +} From ca5dd249596af7f63bb193491a7cd6b1780e000c Mon Sep 17 00:00:00 2001 From: Szegoo Date: Mon, 17 Oct 2022 11:03:35 +0200 Subject: [PATCH 02/13] remove unnecessary --- frame/utility/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index 9cade82fd7084..85052304a4af9 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -92,7 +92,7 @@ frame_support::construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic, { System: frame_system::{Pallet, Call, Config, Storage, Event}, - Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + Timestamp: pallet_timestamp::{Call, Inherent}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, Utility: utility::{Pallet, Call, Event}, Example: example::{Pallet, Call}, From a5e22b4b3bf1b158674c07e53cffbf502bdad57e Mon Sep 17 00:00:00 2001 From: Szegoo Date: Mon, 17 Oct 2022 20:33:23 +0200 Subject: [PATCH 03/13] batch works with council --- Cargo.lock | 1 + frame/utility/Cargo.toml | 1 + frame/utility/src/tests.rs | 70 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 52abfce0884bd..e14aa33a5b607 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6559,6 +6559,7 @@ dependencies = [ "frame-support", "frame-system", "pallet-balances", + "pallet-collective", "pallet-timestamp", "parity-scale-codec", "scale-info", diff --git a/frame/utility/Cargo.toml b/frame/utility/Cargo.toml index 973d678b81340..ac4f52c6bb9f3 100644 --- a/frame/utility/Cargo.toml +++ b/frame/utility/Cargo.toml @@ -25,6 +25,7 @@ sp-std = { version = "4.0.0", default-features = false, path = "../../primitives [dev-dependencies] pallet-balances = { version = "4.0.0-dev", path = "../balances" } +pallet-collective = { version = "4.0.0-dev", path = "../collective" } pallet-timestamp = { version = "4.0.0-dev", path = "../timestamp" } sp-core = { version = "6.0.0", path = "../../primitives/core" } diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index 85052304a4af9..ecd31df5c77c3 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -27,15 +27,18 @@ use frame_support::{ dispatch::{DispatchError, DispatchErrorWithPostInfo, Dispatchable, Pays}, error::BadOrigin, parameter_types, storage, - traits::{ConstU32, ConstU64, Contains}, + traits::{ConstU32, ConstU64, Contains, GenesisBuild}, weights::Weight, }; +use pallet_collective::Instance1; use sp_core::H256; use sp_runtime::{ testing::Header, - traits::{BlakeTwo256, IdentityLookup}, + traits::{BlakeTwo256, Hash, IdentityLookup}, }; +type BlockNumber = u64; + // example module to test behaviors. #[frame_support::pallet] pub mod example { @@ -94,6 +97,7 @@ frame_support::construct_runtime!( System: frame_system::{Pallet, Call, Config, Storage, Event}, Timestamp: pallet_timestamp::{Call, Inherent}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + Council: pallet_collective::, Utility: utility::{Pallet, Call, Event}, Example: example::{Pallet, Call}, } @@ -148,10 +152,27 @@ impl pallet_timestamp::Config for Test { type MinimumPeriod = ConstU64<3>; type WeightInfo = (); } + +const MOTION_DURATION_IN_BLOCKS: BlockNumber = 3; parameter_types! { pub const MultisigDepositBase: u64 = 1; pub const MultisigDepositFactor: u64 = 1; pub const MaxSignatories: u16 = 3; + pub const MotionDuration: BlockNumber = MOTION_DURATION_IN_BLOCKS; + pub const MaxProposals: u32 = 100; + pub const MaxMembers: u32 = 100; +} + +type CouncilCollective = pallet_collective::Instance1; +impl pallet_collective::Config for Test { + type RuntimeOrigin = RuntimeOrigin; + type Proposal = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type MotionDuration = MotionDuration; + type MaxProposals = MaxProposals; + type MaxMembers = MaxMembers; + type DefaultVote = pallet_collective::PrimeDefaultVote; + type WeightInfo = (); } impl example::Config for Test {} @@ -192,6 +213,14 @@ pub fn new_test_ext() -> sp_io::TestExternalities { } .assimilate_storage(&mut t) .unwrap(); + + pallet_collective::GenesisConfig:: { + members: vec![1, 2, 3], + phantom: Default::default(), + } + .assimilate_storage(&mut t) + .unwrap(); + let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| System::set_block_number(1)); ext @@ -740,3 +769,40 @@ fn batch_all_doesnt_work_with_inherents() { ); }) } + +#[test] +fn batch_works_with_council_origin() { + new_test_ext().execute_with(|| { + let proposal = RuntimeCall::Utility(UtilityCall::batch { + calls: vec![call_transfer(1, 5), call_transfer(1, 5)], + }); + let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32); + let proposal_weight = proposal.get_dispatch_info().weight; + let hash = BlakeTwo256::hash_of(&proposal); + + assert_ok!(Council::propose( + RuntimeOrigin::signed(1), + 3, + Box::new(proposal.clone()), + proposal_len + )); + + assert_ok!(Council::vote(RuntimeOrigin::signed(1), hash, 0, true)); + assert_ok!(Council::vote(RuntimeOrigin::signed(2), hash, 0, true)); + assert_ok!(Council::vote(RuntimeOrigin::signed(3), hash, 0, true)); + + System::set_block_number(4); + assert_ok!(Council::close( + RuntimeOrigin::signed(4), + hash, + 0, + proposal_weight, + proposal_len + )); + + System::assert_last_event(RuntimeEvent::Council(pallet_collective::Event::Executed { + proposal_hash: hash, + result: Ok(()), + })); + }) +} From 71818e78355f731e7fef2933fe0fd453a1f10ee8 Mon Sep 17 00:00:00 2001 From: Szegoo Date: Tue, 18 Oct 2022 09:28:38 +0200 Subject: [PATCH 04/13] add more tests --- frame/utility/src/lib.rs | 6 ++-- frame/utility/src/tests.rs | 74 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index ed167a2f21b78..de9ec2eb0fefa 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -403,13 +403,13 @@ pub mod pallet { /// Send a batch of dispatch calls. /// Unlike `batch`, it allows errors and won't interrupt. /// - /// May be called from any origin. + /// May be called from either the root or a signed origin. /// /// - `calls`: The calls to be dispatched from the same origin. The number of call must not /// exceed the constant: `batched_calls_limit` (available in constant metadata). /// - /// If origin is root then call are dispatch without checking origin filter. (This includes - /// bypassing `frame_system::Config::BaseCallFilter`). + /// If origin is root then the calls are dispatch without checking origin filter. (This + /// includes bypassing `frame_system::Config::BaseCallFilter`). /// /// # /// - Complexity: O(C) where C is the number of calls to be batched. diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index ecd31df5c77c3..9cf4e234167a5 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -806,3 +806,77 @@ fn batch_works_with_council_origin() { })); }) } + +#[test] +fn force_batch_works_with_council_origin() { + new_test_ext().execute_with(|| { + let proposal = RuntimeCall::Utility(UtilityCall::force_batch { + calls: vec![call_transfer(1, 5), call_transfer(1, 5)], + }); + let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32); + let proposal_weight = proposal.get_dispatch_info().weight; + let hash = BlakeTwo256::hash_of(&proposal); + + assert_ok!(Council::propose( + RuntimeOrigin::signed(1), + 3, + Box::new(proposal.clone()), + proposal_len + )); + + assert_ok!(Council::vote(RuntimeOrigin::signed(1), hash, 0, true)); + assert_ok!(Council::vote(RuntimeOrigin::signed(2), hash, 0, true)); + assert_ok!(Council::vote(RuntimeOrigin::signed(3), hash, 0, true)); + + System::set_block_number(4); + assert_ok!(Council::close( + RuntimeOrigin::signed(4), + hash, + 0, + proposal_weight, + proposal_len + )); + + System::assert_last_event(RuntimeEvent::Council(pallet_collective::Event::Executed { + proposal_hash: hash, + result: Ok(()), + })); + }) +} + +#[test] +fn batch_all_doesnt_work_with_council_origin() { + new_test_ext().execute_with(|| { + let proposal = RuntimeCall::Utility(UtilityCall::batch_all { + calls: vec![call_transfer(1, 5), call_transfer(1, 5)], + }); + let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32); + let proposal_weight = proposal.get_dispatch_info().weight; + let hash = BlakeTwo256::hash_of(&proposal); + + assert_ok!(Council::propose( + RuntimeOrigin::signed(1), + 3, + Box::new(proposal.clone()), + proposal_len + )); + + assert_ok!(Council::vote(RuntimeOrigin::signed(1), hash, 0, true)); + assert_ok!(Council::vote(RuntimeOrigin::signed(2), hash, 0, true)); + assert_ok!(Council::vote(RuntimeOrigin::signed(3), hash, 0, true)); + + System::set_block_number(4); + assert_ok!(Council::close( + RuntimeOrigin::signed(4), + hash, + 0, + proposal_weight, + proposal_len + )); + + System::assert_last_event(RuntimeEvent::Council(pallet_collective::Event::Executed { + proposal_hash: hash, + result: Err(BadOrigin.into()), + })); + }) +} From 3a806e8f779a3de842ddaa2eaa627491f41eb254 Mon Sep 17 00:00:00 2001 From: Szegoo Date: Wed, 19 Oct 2022 11:54:21 +0200 Subject: [PATCH 05/13] better call examples --- frame/utility/src/tests.rs | 53 +++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index 9cf4e234167a5..5f0ab5e091b3f 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -30,7 +30,7 @@ use frame_support::{ traits::{ConstU32, ConstU64, Contains, GenesisBuild}, weights::Weight, }; -use pallet_collective::Instance1; +use pallet_collective::{EnsureProportionAtLeast, Instance1}; use sp_core::H256; use sp_runtime::{ testing::Header, @@ -85,6 +85,42 @@ pub mod example { } } +mod mock_democracy { + pub use pallet::*; + #[frame_support::pallet] + pub mod pallet { + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config + Sized { + type RuntimeEvent: From> + + IsType<::RuntimeEvent>; + type ExternalMajorityOrigin: EnsureOrigin; + } + + #[pallet::call] + impl Pallet { + #[pallet::weight(0)] + pub fn external_propose_majority(origin: OriginFor) -> DispatchResult { + T::ExternalMajorityOrigin::ensure_origin(origin)?; + Self::deposit_event(Event::::ExternalProposed); + Ok(()) + } + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + ExternalProposed, + } + } +} + type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; @@ -100,6 +136,7 @@ frame_support::construct_runtime!( Council: pallet_collective::, Utility: utility::{Pallet, Call, Event}, Example: example::{Pallet, Call}, + Democracy: mock_democracy::{Pallet, Call, Event}, } ); @@ -192,6 +229,10 @@ impl Contains for TestBaseCallFilter { } } } +impl mock_democracy::Config for Test { + type RuntimeEvent = RuntimeEvent; + type ExternalMajorityOrigin = EnsureProportionAtLeast; +} impl Config for Test { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; @@ -774,7 +815,7 @@ fn batch_all_doesnt_work_with_inherents() { fn batch_works_with_council_origin() { new_test_ext().execute_with(|| { let proposal = RuntimeCall::Utility(UtilityCall::batch { - calls: vec![call_transfer(1, 5), call_transfer(1, 5)], + calls: vec![RuntimeCall::Democracy(mock_democracy::Call::external_propose_majority {})], }); let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32); let proposal_weight = proposal.get_dispatch_info().weight; @@ -811,7 +852,7 @@ fn batch_works_with_council_origin() { fn force_batch_works_with_council_origin() { new_test_ext().execute_with(|| { let proposal = RuntimeCall::Utility(UtilityCall::force_batch { - calls: vec![call_transfer(1, 5), call_transfer(1, 5)], + calls: vec![RuntimeCall::Democracy(mock_democracy::Call::external_propose_majority {})], }); let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32); let proposal_weight = proposal.get_dispatch_info().weight; @@ -845,10 +886,10 @@ fn force_batch_works_with_council_origin() { } #[test] -fn batch_all_doesnt_work_with_council_origin() { +fn batch_all_works_with_council_origin() { new_test_ext().execute_with(|| { let proposal = RuntimeCall::Utility(UtilityCall::batch_all { - calls: vec![call_transfer(1, 5), call_transfer(1, 5)], + calls: vec![RuntimeCall::Democracy(mock_democracy::Call::external_propose_majority {})], }); let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32); let proposal_weight = proposal.get_dispatch_info().weight; @@ -876,7 +917,7 @@ fn batch_all_doesnt_work_with_council_origin() { System::assert_last_event(RuntimeEvent::Council(pallet_collective::Event::Executed { proposal_hash: hash, - result: Err(BadOrigin.into()), + result: Ok(()), })); }) } From b3416de4cb5f9a9d52c6eef64ad04f6dedbab2e7 Mon Sep 17 00:00:00 2001 From: Szegoo Date: Wed, 19 Oct 2022 21:56:36 +0200 Subject: [PATCH 06/13] shorter code --- frame/utility/src/tests.rs | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index 5f0ab5e091b3f..8fe0fbff380f0 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -888,36 +888,9 @@ fn force_batch_works_with_council_origin() { #[test] fn batch_all_works_with_council_origin() { new_test_ext().execute_with(|| { - let proposal = RuntimeCall::Utility(UtilityCall::batch_all { - calls: vec![RuntimeCall::Democracy(mock_democracy::Call::external_propose_majority {})], - }); - let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32); - let proposal_weight = proposal.get_dispatch_info().weight; - let hash = BlakeTwo256::hash_of(&proposal); - - assert_ok!(Council::propose( - RuntimeOrigin::signed(1), - 3, - Box::new(proposal.clone()), - proposal_len - )); - - assert_ok!(Council::vote(RuntimeOrigin::signed(1), hash, 0, true)); - assert_ok!(Council::vote(RuntimeOrigin::signed(2), hash, 0, true)); - assert_ok!(Council::vote(RuntimeOrigin::signed(3), hash, 0, true)); - - System::set_block_number(4); - assert_ok!(Council::close( - RuntimeOrigin::signed(4), - hash, - 0, - proposal_weight, - proposal_len + assert_ok!(Utility::batch_all( + RuntimeOrigin::from(pallet_collective::RawOrigin::Members(3, 3)), + vec![RuntimeCall::Democracy(mock_democracy::Call::external_propose_majority {})] )); - - System::assert_last_event(RuntimeEvent::Council(pallet_collective::Event::Executed { - proposal_hash: hash, - result: Ok(()), - })); }) } From 92dfc6c0fca068fd6f700922b9b5c62c4b023705 Mon Sep 17 00:00:00 2001 From: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> Date: Thu, 20 Oct 2022 21:32:15 +0200 Subject: [PATCH 07/13] Update frame/utility/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- frame/utility/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index de9ec2eb0fefa..a390da3c046dd 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -164,7 +164,7 @@ pub mod pallet { impl Pallet { /// Send a batch of dispatch calls. /// - /// May be called from either the root or a signed origin. + /// May be called from any origin except `None`. /// /// - `calls`: The calls to be dispatched from the same origin. The number of call must not /// exceed the constant: `batched_calls_limit` (available in constant metadata). From 9c1301558f13578e604420baf4c64a65df026435 Mon Sep 17 00:00:00 2001 From: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> Date: Thu, 20 Oct 2022 21:32:21 +0200 Subject: [PATCH 08/13] Update frame/utility/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- frame/utility/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index a390da3c046dd..826c91c1d8517 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -403,7 +403,7 @@ pub mod pallet { /// Send a batch of dispatch calls. /// Unlike `batch`, it allows errors and won't interrupt. /// - /// May be called from either the root or a signed origin. + /// May be called from any origin except `None`. /// /// - `calls`: The calls to be dispatched from the same origin. The number of call must not /// exceed the constant: `batched_calls_limit` (available in constant metadata). From f003754dfd6932c223ebcc79854d4f7f2abb0242 Mon Sep 17 00:00:00 2001 From: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> Date: Thu, 20 Oct 2022 21:32:27 +0200 Subject: [PATCH 09/13] Update frame/utility/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- frame/utility/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index 826c91c1d8517..9db8b9c2e3580 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -291,7 +291,7 @@ pub mod pallet { /// Send a batch of dispatch calls and atomically execute them. /// The whole transaction will rollback and fail if any of the calls failed. /// - /// May be called from either the root or a signed origin. + /// May be called from any origin except `None`. /// /// - `calls`: The calls to be dispatched from the same origin. The number of call must not /// exceed the constant: `batched_calls_limit` (available in constant metadata). From 822fbc6da92ae2feafa750c1611609eadf476de9 Mon Sep 17 00:00:00 2001 From: Szegoo Date: Thu, 20 Oct 2022 21:36:28 +0200 Subject: [PATCH 10/13] update TestBaseCallFilter --- frame/utility/src/tests.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index 8fe0fbff380f0..19cd8081f1924 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -225,6 +225,8 @@ impl Contains for TestBaseCallFilter { RuntimeCall::System(frame_system::Call::remark { .. }) => true, // For tests RuntimeCall::Example(_) => true, + // For council origin tests. + RuntimeCall::Collective(_) => true, _ => false, } } @@ -892,5 +894,10 @@ fn batch_all_works_with_council_origin() { RuntimeOrigin::from(pallet_collective::RawOrigin::Members(3, 3)), vec![RuntimeCall::Democracy(mock_democracy::Call::external_propose_majority {})] )); + + System::assert_last_event(RuntimeEvent::Council(pallet_collective::Event::Executed { + proposal_hash: hash, + result: Ok(()), + })); }) } From 4002f5ef77aed14af125e3d706fafdd7bf809453 Mon Sep 17 00:00:00 2001 From: Szegoo Date: Thu, 20 Oct 2022 21:38:29 +0200 Subject: [PATCH 11/13] fix --- frame/utility/src/tests.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index 19cd8081f1924..837068525f395 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -226,7 +226,7 @@ impl Contains for TestBaseCallFilter { // For tests RuntimeCall::Example(_) => true, // For council origin tests. - RuntimeCall::Collective(_) => true, + RuntimeCall::Democracy(_) => true, _ => false, } } @@ -894,10 +894,5 @@ fn batch_all_works_with_council_origin() { RuntimeOrigin::from(pallet_collective::RawOrigin::Members(3, 3)), vec![RuntimeCall::Democracy(mock_democracy::Call::external_propose_majority {})] )); - - System::assert_last_event(RuntimeEvent::Council(pallet_collective::Event::Executed { - proposal_hash: hash, - result: Ok(()), - })); }) } From 12b6a1afceeacb9e3182cb0a4808fc7c01bd2175 Mon Sep 17 00:00:00 2001 From: Szegoo Date: Fri, 28 Oct 2022 15:15:45 +0200 Subject: [PATCH 12/13] fix? --- frame/utility/src/tests.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index 2433d0fbeb4c6..3c7b306fcc4b9 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -195,6 +195,23 @@ parameter_types! { pub const MultisigDepositBase: u64 = 1; pub const MultisigDepositFactor: u64 = 1; pub const MaxSignatories: u32 = 3; + pub const MaxSignatories: u16 = 3; + pub const MotionDuration: BlockNumber = MOTION_DURATION_IN_BLOCKS; + pub const MaxProposals: u32 = 100; + pub const MaxMembers: u32 = 100; +} + +type CouncilCollective = pallet_collective::Instance1; +impl pallet_collective::Config for Test { + type RuntimeOrigin = RuntimeOrigin; + type Proposal = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type MotionDuration = MotionDuration; + type MaxProposals = MaxProposals; + type MaxMembers = MaxMembers; + type DefaultVote = pallet_collective::PrimeDefaultVote; + type WeightInfo = (); + pub const MaxSignatories: u32 = 3; } impl example::Config for Test {} From bf0f4f221c7032a22f436ed2483b0abf7418714c Mon Sep 17 00:00:00 2001 From: Szegoo Date: Fri, 28 Oct 2022 15:23:11 +0200 Subject: [PATCH 13/13] fix --- frame/utility/src/tests.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index 3c7b306fcc4b9..c374f5ae21099 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -195,7 +195,6 @@ parameter_types! { pub const MultisigDepositBase: u64 = 1; pub const MultisigDepositFactor: u64 = 1; pub const MaxSignatories: u32 = 3; - pub const MaxSignatories: u16 = 3; pub const MotionDuration: BlockNumber = MOTION_DURATION_IN_BLOCKS; pub const MaxProposals: u32 = 100; pub const MaxMembers: u32 = 100; @@ -211,7 +210,6 @@ impl pallet_collective::Config for Test { type MaxMembers = MaxMembers; type DefaultVote = pallet_collective::PrimeDefaultVote; type WeightInfo = (); - pub const MaxSignatories: u32 = 3; } impl example::Config for Test {}