Skip to content

Commit

Permalink
Use sp_runtime::traits::BadOrigin (paritytech#5011)
Browse files Browse the repository at this point in the history
It says `Will be removed after July 2023` but that's not true 😃

---------

Co-authored-by: Oliver Tale-Yazdi <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
3 people authored and Jay Pan committed Dec 27, 2024
1 parent 038995f commit eb988b0
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 19 deletions.
3 changes: 2 additions & 1 deletion cumulus/parachains/pallets/collective-content/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
//! Tests.
use super::{mock::*, *};
use frame_support::{assert_noop, assert_ok, error::BadOrigin, pallet_prelude::Pays};
use frame_support::{assert_noop, assert_ok, pallet_prelude::Pays};
use sp_runtime::traits::BadOrigin;

/// returns CID hash of 68 bytes of given `i`.
fn create_cid(i: u8) -> OpaqueCid {
Expand Down
6 changes: 2 additions & 4 deletions polkadot/runtime/common/src/paras_registrar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,7 @@ mod tests {
mock::conclude_pvf_checking, paras_registrar, traits::Registrar as RegistrarTrait,
};
use frame_support::{
assert_noop, assert_ok, derive_impl,
error::BadOrigin,
parameter_types,
assert_noop, assert_ok, derive_impl, parameter_types,
traits::{OnFinalize, OnInitialize},
};
use frame_system::limits;
Expand All @@ -731,7 +729,7 @@ mod tests {
use sp_io::TestExternalities;
use sp_keyring::Sr25519Keyring;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
traits::{BadOrigin, BlakeTwo256, IdentityLookup},
transaction_validity::TransactionPriority,
BuildStorage, Perbill,
};
Expand Down
3 changes: 2 additions & 1 deletion polkadot/runtime/parachains/src/assigner_on_demand/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ use crate::{
},
paras::{ParaGenesisArgs, ParaKind},
};
use frame_support::{assert_noop, assert_ok, error::BadOrigin};
use frame_support::{assert_noop, assert_ok};
use pallet_balances::Error as BalancesError;
use polkadot_primitives::{
BlockNumber, SessionIndex, ValidationCode, ON_DEMAND_MAX_QUEUE_MAX_SIZE,
};
use sp_runtime::traits::BadOrigin;
use sp_std::{
cmp::{Ord, Ordering},
collections::btree_map::BTreeMap,
Expand Down
3 changes: 2 additions & 1 deletion polkadot/runtime/parachains/src/hrmp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ use crate::{
},
shared,
};
use frame_support::{assert_noop, assert_ok, error::BadOrigin};
use frame_support::{assert_noop, assert_ok};
use polkadot_primitives::{BlockNumber, InboundDownwardMessage};
use sp_runtime::traits::BadOrigin;
use std::collections::BTreeMap;

pub(crate) fn run_to_block(to: BlockNumber, new_session: Option<Vec<BlockNumber>>) {
Expand Down
29 changes: 29 additions & 0 deletions prdoc/pr_5011.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: "Use `BadOrigin` from `sp_runtime`"

doc:
- audience: Runtime Dev
description: |
This PR refactor usages of deprecated `frame_support::error::BadOrigin` to `sp_runtime::traits::BadOrigin`

crates:
- name: pallet-collective-content
bump: patch
- name: polkadot-runtime-common
bump: patch
- name: polkadot-runtime-parachains
bump: patch
- name: pallet-alliance
bump: patch
- name: pallet-contracts
bump: patch
- name: pallet-democracy
bump: patch
- name: pallet-nomination-pools
bump: patch
- name: pallet-ranked-collective
bump: patch
- name: pallet-utility
bump: patch
3 changes: 2 additions & 1 deletion substrate/frame/alliance/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

//! Tests for the alliance pallet.
use frame_support::{assert_noop, assert_ok, error::BadOrigin};
use frame_support::{assert_noop, assert_ok};
use frame_system::{EventRecord, Phase};
use sp_runtime::traits::BadOrigin;

use super::*;
use crate::{self as alliance, mock::*};
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ use environmental::*;
use frame_support::{
dispatch::{GetDispatchInfo, Pays, PostDispatchInfo, RawOrigin, WithPostDispatchInfo},
ensure,
error::BadOrigin,
traits::{
fungible::{Inspect, Mutate, MutateHold},
ConstU32, Contains, Get, Randomness, Time,
Expand All @@ -135,7 +134,7 @@ use frame_system::{
use scale_info::TypeInfo;
use smallvec::Array;
use sp_runtime::{
traits::{Convert, Dispatchable, Saturating, StaticLookup, Zero},
traits::{BadOrigin, Convert, Dispatchable, Saturating, StaticLookup, Zero},
DispatchError, RuntimeDebug,
};
use sp_std::{fmt::Debug, prelude::*};
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
use codec::{Decode, Encode};
use frame_support::{
ensure,
error::BadOrigin,
traits::{
defensive_prelude::*,
schedule::{v3::Named as ScheduleNamed, DispatchTime},
Expand All @@ -166,7 +165,7 @@ use frame_support::{
};
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
use sp_runtime::{
traits::{Bounded as ArithBounded, One, Saturating, StaticLookup, Zero},
traits::{BadOrigin, Bounded as ArithBounded, One, Saturating, StaticLookup, Zero},
ArithmeticError, DispatchError, DispatchResult,
};
use sp_std::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2600,7 +2600,7 @@ pub mod pallet {
) -> DispatchResult {
let mut bonded_pool = match ensure_root(origin.clone()) {
Ok(()) => BondedPool::<T>::get(pool_id).ok_or(Error::<T>::PoolNotFound)?,
Err(frame_support::error::BadOrigin) => {
Err(sp_runtime::traits::BadOrigin) => {
let who = ensure_signed(origin)?;
let bonded_pool =
BondedPool::<T>::get(pool_id).ok_or(Error::<T>::PoolNotFound)?;
Expand Down
6 changes: 2 additions & 4 deletions substrate/frame/ranked-collective/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
use std::collections::BTreeMap;

use frame_support::{
assert_noop, assert_ok, derive_impl,
error::BadOrigin,
parameter_types,
assert_noop, assert_ok, derive_impl, parameter_types,
traits::{ConstU16, EitherOf, MapSuccess, Polling},
};
use sp_core::Get;
use sp_runtime::{
traits::{MaybeConvert, ReduceBy, ReplaceWithDefault},
traits::{BadOrigin, MaybeConvert, ReduceBy, ReplaceWithDefault},
BuildStorage,
};

Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/utility/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ use crate as utility;
use frame_support::{
assert_err_ignore_postinfo, assert_noop, assert_ok, derive_impl,
dispatch::{DispatchErrorWithPostInfo, Pays},
error::BadOrigin,
parameter_types, storage,
traits::{ConstU64, Contains},
weights::Weight,
};
use pallet_collective::{EnsureProportionAtLeast, Instance1};
use sp_runtime::{
traits::{BlakeTwo256, Dispatchable, Hash},
traits::{BadOrigin, BlakeTwo256, Dispatchable, Hash},
BuildStorage, DispatchError, TokenError,
};

Expand Down

0 comments on commit eb988b0

Please sign in to comment.