Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
impl filter in origin
Browse files Browse the repository at this point in the history
  • Loading branch information
gui1117 committed Jun 10, 2020
1 parent e2a6c3e commit 353e0fd
Show file tree
Hide file tree
Showing 76 changed files with 463 additions and 187 deletions.
1 change: 1 addition & 0 deletions bin/node-template/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
}
impl system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Call = ();
type Index = u64;
Expand Down
2 changes: 2 additions & 0 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ parameter_types! {
}

impl system::Trait for Runtime {
/// The basic call filter to use in dispatchable.
type BasicCallFilter = ();
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
/// The aggregated dispatch type that is available for extrinsics.
Expand Down
1 change: 1 addition & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ parameter_types! {
const_assert!(AvailableBlockRatio::get().deconstruct() >= AVERAGE_ON_INITIALIZE_WEIGHT.deconstruct());

impl frame_system::Trait for Runtime {
type BasicCallFilter = ();
type Origin = Origin;
type Call = Call;
type Index = Index;
Expand Down
1 change: 1 addition & 0 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ mod tests {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Index = u64;
type Call = ();
Expand Down
1 change: 1 addition & 0 deletions frame/aura/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ parameter_types! {
}

impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
Expand Down
1 change: 1 addition & 0 deletions frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ mod tests {
}

impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = BlockNumber;
Expand Down
1 change: 1 addition & 0 deletions frame/authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ mod tests {
}

impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
Expand Down
1 change: 1 addition & 0 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ parameter_types! {
}

impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
Expand Down
1 change: 1 addition & 0 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ impl<T: Subtrait<I>, I: Instance> PartialEq for ElevatedTrait<T, I> {
}
impl<T: Subtrait<I>, I: Instance> Eq for ElevatedTrait<T, I> {}
impl<T: Subtrait<I>, I: Instance> frame_system::Trait for ElevatedTrait<T, I> {
type BasicCallFilter = T::BasicCallFilter;
type Origin = T::Origin;
type Call = T::Call;
type Index = T::Index;
Expand Down
1 change: 1 addition & 0 deletions frame/balances/src/tests_composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
Expand Down
1 change: 1 addition & 0 deletions frame/balances/src/tests_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
Expand Down
11 changes: 8 additions & 3 deletions frame/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ pub use utils::*;
pub use analysis::Analysis;
#[doc(hidden)]
pub use sp_io::storage::root as storage_root;
pub use sp_runtime::traits::{Dispatchable, Zero};
pub use sp_runtime::traits::Zero;
pub use frame_support;
pub use paste;

/// Construct pallet benchmarks for weighing dispatchables.
Expand Down Expand Up @@ -242,7 +243,9 @@ macro_rules! benchmarks_iter {
{ $( $common )* }
( $( $names )* )
$name { $( $code )* }: {
<Call<T> as $crate::Dispatchable>::dispatch(Call::<T>::$dispatch($($arg),*), $origin.into())?;
<
Call<T> as $crate::frame_support::traits::PalletDispatchable
>::dispatch_bypass_filter(Call::<T>::$dispatch($($arg),*), $origin.into())?;
}
verify $postcode
$( $rest )*
Expand All @@ -262,7 +265,9 @@ macro_rules! benchmarks_iter {
{ $( $common )* }
( $( $names )* )
$name { $( $code )* }: {
<Call<T, I> as $crate::Dispatchable>::dispatch(Call::<T, I>::$dispatch($($arg),*), $origin.into())?;
<
Call<T, I> as $crate::frame_support::traits::PalletDispatchable
>::dispatch_bypass_filter(Call::<T, I>::$dispatch($($arg),*), $origin.into())?;
}
verify $postcode
$( $rest )*
Expand Down
1 change: 1 addition & 0 deletions frame/benchmarking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub trait Trait {
pub struct Test;

impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
Expand Down
13 changes: 7 additions & 6 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,10 +1015,11 @@ mod tests {
pub const MaxProposals: u32 = 100;
}
impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
type Call = ();
type Call = Call;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
Expand Down Expand Up @@ -1167,7 +1168,7 @@ mod tests {
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!(Collective::set_members(Origin::ROOT, vec![1, 2, 3], Some(3), MAX_MEMBERS));
assert_ok!(Collective::set_members(Origin::root(), vec![1, 2, 3], Some(3), MAX_MEMBERS));

assert_ok!(Collective::propose(Origin::signed(1), 3, Box::new(proposal.clone()), proposal_len));
assert_ok!(Collective::vote(Origin::signed(2), hash.clone(), 0, true));
Expand All @@ -1192,7 +1193,7 @@ mod tests {
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!(Collective::set_members(Origin::ROOT, vec![1, 2, 3], Some(1), MAX_MEMBERS));
assert_ok!(Collective::set_members(Origin::root(), vec![1, 2, 3], Some(1), MAX_MEMBERS));

assert_ok!(Collective::propose(Origin::signed(1), 3, Box::new(proposal.clone()), proposal_len));
assert_ok!(Collective::vote(Origin::signed(2), hash.clone(), 0, true));
Expand Down Expand Up @@ -1260,7 +1261,7 @@ mod tests {
Collective::voting(&hash),
Some(Votes { index: 0, threshold: 3, ayes: vec![1, 2], nays: vec![], end })
);
assert_ok!(Collective::set_members(Origin::ROOT, vec![2, 3, 4], None, MAX_MEMBERS));
assert_ok!(Collective::set_members(Origin::root(), vec![2, 3, 4], None, MAX_MEMBERS));
assert_eq!(
Collective::voting(&hash),
Some(Votes { index: 0, threshold: 3, ayes: vec![2], nays: vec![], end })
Expand All @@ -1275,7 +1276,7 @@ mod tests {
Collective::voting(&hash),
Some(Votes { index: 1, threshold: 2, ayes: vec![2], nays: vec![3], end })
);
assert_ok!(Collective::set_members(Origin::ROOT, vec![2, 4], None, MAX_MEMBERS));
assert_ok!(Collective::set_members(Origin::root(), vec![2, 4], None, MAX_MEMBERS));
assert_eq!(
Collective::voting(&hash),
Some(Votes { index: 1, threshold: 2, ayes: vec![2], nays: vec![], end })
Expand Down Expand Up @@ -1618,7 +1619,7 @@ mod tests {
// Proposal would normally succeed
assert_ok!(Collective::vote(Origin::signed(2), hash.clone(), 0, true));
// But Root can disapprove and remove it anyway
assert_ok!(Collective::disapprove_proposal(Origin::ROOT, hash.clone()));
assert_ok!(Collective::disapprove_proposal(Origin::root(), hash.clone()));
let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] };
assert_eq!(System::events(), vec![
record(Event::collective_Instance1(RawEvent::Proposed(1, 0, hash.clone(), 2))),
Expand Down
13 changes: 7 additions & 6 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Call = ();
type Call = Call;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
Expand Down Expand Up @@ -936,7 +937,7 @@ fn call_contract_removals() {

#[test]
fn inherent_claim_surcharge_contract_removals() {
removals(|| Contracts::claim_surcharge(Origin::NONE, BOB, Some(ALICE)).is_ok());
removals(|| Contracts::claim_surcharge(Origin::none(), BOB, Some(ALICE)).is_ok());
}

#[test]
Expand All @@ -947,10 +948,10 @@ fn signed_claim_surcharge_contract_removals() {
#[test]
fn claim_surcharge_malus() {
// Test surcharge malus for inherent
claim_surcharge(4, || Contracts::claim_surcharge(Origin::NONE, BOB, Some(ALICE)).is_ok(), true);
claim_surcharge(3, || Contracts::claim_surcharge(Origin::NONE, BOB, Some(ALICE)).is_ok(), true);
claim_surcharge(2, || Contracts::claim_surcharge(Origin::NONE, BOB, Some(ALICE)).is_ok(), true);
claim_surcharge(1, || Contracts::claim_surcharge(Origin::NONE, BOB, Some(ALICE)).is_ok(), false);
claim_surcharge(4, || Contracts::claim_surcharge(Origin::none(), BOB, Some(ALICE)).is_ok(), true);
claim_surcharge(3, || Contracts::claim_surcharge(Origin::none(), BOB, Some(ALICE)).is_ok(), true);
claim_surcharge(2, || Contracts::claim_surcharge(Origin::none(), BOB, Some(ALICE)).is_ok(), true);
claim_surcharge(1, || Contracts::claim_surcharge(Origin::none(), BOB, Some(ALICE)).is_ok(), false);

// Test surcharge malus for signed
claim_surcharge(4, || Contracts::claim_surcharge(Origin::signed(ALICE), BOB, None).is_ok(), true);
Expand Down
1 change: 1 addition & 0 deletions frame/democracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
Expand Down
6 changes: 3 additions & 3 deletions frame/democracy/src/tests/cancellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn cancel_referendum_should_work() {
0
);
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
assert_ok!(Democracy::cancel_referendum(Origin::ROOT, r.into()));
assert_ok!(Democracy::cancel_referendum(Origin::root(), r.into()));

next_block();
next_block();
Expand All @@ -53,8 +53,8 @@ fn cancel_queued_should_work() {

assert!(pallet_scheduler::Agenda::<Test>::get(6)[0].is_some());

assert_noop!(Democracy::cancel_queued(Origin::ROOT, 1), Error::<Test>::ProposalMissing);
assert_ok!(Democracy::cancel_queued(Origin::ROOT, 0));
assert_noop!(Democracy::cancel_queued(Origin::root(), 1), Error::<Test>::ProposalMissing);
assert_ok!(Democracy::cancel_queued(Origin::root(), 0));
assert!(pallet_scheduler::Agenda::<Test>::get(6)[0].is_none());
});
}
Expand Down
18 changes: 8 additions & 10 deletions frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,10 +1070,11 @@ mod tests {
}

impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
type Call = ();
type Call = Call;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
Expand Down Expand Up @@ -1376,11 +1377,8 @@ mod tests {
// historical note: helper function was created in a period of time in which the API of vote
// call was changing. Currently it is a wrapper for the original call and does not do much.
// Nonetheless, totally harmless.
if let Origin::system(frame_system::RawOrigin::Signed(_account)) = origin {
Elections::vote(origin, votes, stake)
} else {
panic!("vote origin must be signed");
}
ensure_signed(origin.clone()).expect("vote origin must be signed");
Elections::vote(origin, votes, stake)
}

fn votes_of(who: &u64) -> Vec<u64> {
Expand Down Expand Up @@ -2358,7 +2356,7 @@ mod tests {
assert_ok!(submit_candidacy(Origin::signed(3)));
assert_ok!(vote(Origin::signed(3), vec![3], 30));

assert_ok!(Elections::remove_member(Origin::ROOT, 4, false));
assert_ok!(Elections::remove_member(Origin::root(), 4, false));

assert_eq!(balances(&4), (35, 2)); // slashed
assert_eq!(Elections::election_rounds(), 2); // new election round
Expand All @@ -2381,7 +2379,7 @@ mod tests {

// no replacement yet.
assert_err_with_weight!(
Elections::remove_member(Origin::ROOT, 4, true),
Elections::remove_member(Origin::root(), 4, true),
Error::<Test>::InvalidReplacement,
Some(6000000),
);
Expand All @@ -2403,7 +2401,7 @@ mod tests {

// there is a replacement! and this one needs a weight refund.
assert_err_with_weight!(
Elections::remove_member(Origin::ROOT, 4, false),
Elections::remove_member(Origin::root(), 4, false),
Error::<Test>::InvalidReplacement,
Some(6000000) // only thing that matters for now is that it is NOT the full block.
);
Expand Down Expand Up @@ -2562,7 +2560,7 @@ mod tests {
Elections::end_block(System::block_number());

assert_eq!(Elections::members_ids(), vec![2, 4]);
assert_ok!(Elections::remove_member(Origin::ROOT, 2, true));
assert_ok!(Elections::remove_member(Origin::root(), 2, true));
assert_eq!(Elections::members_ids(), vec![4, 5]);
});
}
Expand Down
3 changes: 2 additions & 1 deletion frame/elections/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Call = ();
type Call = Call;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
Expand Down
4 changes: 2 additions & 2 deletions frame/elections/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ fn retracting_active_voter_should_slash_reporter() {
assert_ok!(Elections::end_block(System::block_number()));

System::set_block_number(8);
assert_ok!(Elections::set_desired_seats(Origin::ROOT, 3));
assert_ok!(Elections::set_desired_seats(Origin::root(), 3));
assert_ok!(Elections::end_block(System::block_number()));

System::set_block_number(10);
Expand Down Expand Up @@ -1245,7 +1245,7 @@ fn election_second_tally_should_use_runners_up() {

System::set_block_number(8);
assert_ok!(Elections::set_approvals(Origin::signed(6), vec![false, false, true, false], 1, 0, 60));
assert_ok!(Elections::set_desired_seats(Origin::ROOT, 3));
assert_ok!(Elections::set_desired_seats(Origin::root(), 3));
assert_ok!(Elections::end_block(System::block_number()));

System::set_block_number(10);
Expand Down
1 change: 1 addition & 0 deletions frame/example-offchain-worker/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
type BasicCallFilter = ();
type Origin = Origin;
type Call = ();
type Index = u64;
Expand Down
Loading

0 comments on commit 353e0fd

Please sign in to comment.