mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
BREAKING: Rename Origin (#12258)
* BREAKING: Rename Origin * more renaming * a bit more renaming * fix * more fixing * fix in frame_support * even more fixes * fix * small fix * ... * update .stderr * docs * update docs * update docs * docs
This commit is contained in:
@@ -100,7 +100,7 @@ benchmarks_instance_pallet! {
|
||||
)?;
|
||||
let proposal_id = Treasury::<T, _>::proposal_count() - 1;
|
||||
let reject_origin = T::RejectOrigin::successful_origin();
|
||||
}: _<T::Origin>(reject_origin, proposal_id)
|
||||
}: _<T::RuntimeOrigin>(reject_origin, proposal_id)
|
||||
|
||||
approve_proposal {
|
||||
let p in 0 .. T::MaxApprovals::get() - 1;
|
||||
@@ -113,7 +113,7 @@ benchmarks_instance_pallet! {
|
||||
)?;
|
||||
let proposal_id = Treasury::<T, _>::proposal_count() - 1;
|
||||
let approve_origin = T::ApproveOrigin::successful_origin();
|
||||
}: _<T::Origin>(approve_origin, proposal_id)
|
||||
}: _<T::RuntimeOrigin>(approve_origin, proposal_id)
|
||||
|
||||
remove_approval {
|
||||
let (caller, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
|
||||
@@ -125,7 +125,7 @@ benchmarks_instance_pallet! {
|
||||
let proposal_id = Treasury::<T, _>::proposal_count() - 1;
|
||||
Treasury::<T, I>::approve_proposal(RawOrigin::Root.into(), proposal_id)?;
|
||||
let reject_origin = T::RejectOrigin::successful_origin();
|
||||
}: _<T::Origin>(reject_origin, proposal_id)
|
||||
}: _<T::RuntimeOrigin>(reject_origin, proposal_id)
|
||||
|
||||
on_initialize_proposals {
|
||||
let p in 0 .. T::MaxApprovals::get();
|
||||
|
||||
@@ -149,10 +149,10 @@ pub mod pallet {
|
||||
type Currency: Currency<Self::AccountId> + ReservableCurrency<Self::AccountId>;
|
||||
|
||||
/// Origin from which approvals must come.
|
||||
type ApproveOrigin: EnsureOrigin<Self::Origin>;
|
||||
type ApproveOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Origin from which rejections must come.
|
||||
type RejectOrigin: EnsureOrigin<Self::Origin>;
|
||||
type RejectOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The overarching event type.
|
||||
type RuntimeEvent: From<Event<Self, I>>
|
||||
@@ -204,7 +204,7 @@ pub mod pallet {
|
||||
/// The origin required for approving spends from the treasury outside of the proposal
|
||||
/// process. The `Success` value is the maximum amount that this origin is allowed to
|
||||
/// spend at a time.
|
||||
type SpendOrigin: EnsureOrigin<Self::Origin, Success = BalanceOf<Self, I>>;
|
||||
type SpendOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = BalanceOf<Self, I>>;
|
||||
}
|
||||
|
||||
/// Number of proposals that have been made.
|
||||
|
||||
@@ -60,7 +60,7 @@ impl frame_system::Config for Test {
|
||||
type BlockWeights = ();
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
@@ -98,21 +98,21 @@ parameter_types! {
|
||||
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
|
||||
}
|
||||
pub struct TestSpendOrigin;
|
||||
impl frame_support::traits::EnsureOrigin<Origin> for TestSpendOrigin {
|
||||
impl frame_support::traits::EnsureOrigin<RuntimeOrigin> for TestSpendOrigin {
|
||||
type Success = u64;
|
||||
fn try_origin(o: Origin) -> Result<Self::Success, Origin> {
|
||||
Result::<frame_system::RawOrigin<_>, Origin>::from(o).and_then(|o| match o {
|
||||
fn try_origin(o: RuntimeOrigin) -> Result<Self::Success, RuntimeOrigin> {
|
||||
Result::<frame_system::RawOrigin<_>, RuntimeOrigin>::from(o).and_then(|o| match o {
|
||||
frame_system::RawOrigin::Root => Ok(u64::max_value()),
|
||||
frame_system::RawOrigin::Signed(10) => Ok(5),
|
||||
frame_system::RawOrigin::Signed(11) => Ok(10),
|
||||
frame_system::RawOrigin::Signed(12) => Ok(20),
|
||||
frame_system::RawOrigin::Signed(13) => Ok(50),
|
||||
r => Err(Origin::from(r)),
|
||||
r => Err(RuntimeOrigin::from(r)),
|
||||
})
|
||||
}
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn try_successful_origin() -> Result<Origin, ()> {
|
||||
Ok(Origin::root())
|
||||
fn try_successful_origin() -> Result<RuntimeOrigin, ()> {
|
||||
Ok(RuntimeOrigin::root())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,21 +158,21 @@ fn genesis_config_works() {
|
||||
#[test]
|
||||
fn spend_origin_permissioning_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Treasury::spend(Origin::signed(1), 1, 1), BadOrigin);
|
||||
assert_noop!(Treasury::spend(RuntimeOrigin::signed(1), 1, 1), BadOrigin);
|
||||
assert_noop!(
|
||||
Treasury::spend(Origin::signed(10), 6, 1),
|
||||
Treasury::spend(RuntimeOrigin::signed(10), 6, 1),
|
||||
Error::<Test>::InsufficientPermission
|
||||
);
|
||||
assert_noop!(
|
||||
Treasury::spend(Origin::signed(11), 11, 1),
|
||||
Treasury::spend(RuntimeOrigin::signed(11), 11, 1),
|
||||
Error::<Test>::InsufficientPermission
|
||||
);
|
||||
assert_noop!(
|
||||
Treasury::spend(Origin::signed(12), 21, 1),
|
||||
Treasury::spend(RuntimeOrigin::signed(12), 21, 1),
|
||||
Error::<Test>::InsufficientPermission
|
||||
);
|
||||
assert_noop!(
|
||||
Treasury::spend(Origin::signed(13), 51, 1),
|
||||
Treasury::spend(RuntimeOrigin::signed(13), 51, 1),
|
||||
Error::<Test>::InsufficientPermission
|
||||
);
|
||||
});
|
||||
@@ -183,13 +183,13 @@ fn spend_origin_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Check that accumulate works when we have Some value in Dummy already.
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_ok!(Treasury::spend(Origin::signed(10), 5, 6));
|
||||
assert_ok!(Treasury::spend(Origin::signed(10), 5, 6));
|
||||
assert_ok!(Treasury::spend(Origin::signed(10), 5, 6));
|
||||
assert_ok!(Treasury::spend(Origin::signed(10), 5, 6));
|
||||
assert_ok!(Treasury::spend(Origin::signed(11), 10, 6));
|
||||
assert_ok!(Treasury::spend(Origin::signed(12), 20, 6));
|
||||
assert_ok!(Treasury::spend(Origin::signed(13), 50, 6));
|
||||
assert_ok!(Treasury::spend(RuntimeOrigin::signed(10), 5, 6));
|
||||
assert_ok!(Treasury::spend(RuntimeOrigin::signed(10), 5, 6));
|
||||
assert_ok!(Treasury::spend(RuntimeOrigin::signed(10), 5, 6));
|
||||
assert_ok!(Treasury::spend(RuntimeOrigin::signed(10), 5, 6));
|
||||
assert_ok!(Treasury::spend(RuntimeOrigin::signed(11), 10, 6));
|
||||
assert_ok!(Treasury::spend(RuntimeOrigin::signed(12), 20, 6));
|
||||
assert_ok!(Treasury::spend(RuntimeOrigin::signed(13), 50, 6));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(1);
|
||||
assert_eq!(Balances::free_balance(6), 0);
|
||||
@@ -212,7 +212,7 @@ fn minting_works() {
|
||||
#[test]
|
||||
fn spend_proposal_takes_min_deposit() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 1, 3));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 1, 3));
|
||||
assert_eq!(Balances::free_balance(0), 99);
|
||||
assert_eq!(Balances::reserved_balance(0), 1);
|
||||
});
|
||||
@@ -221,7 +221,7 @@ fn spend_proposal_takes_min_deposit() {
|
||||
#[test]
|
||||
fn spend_proposal_takes_proportional_deposit() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_eq!(Balances::free_balance(0), 95);
|
||||
assert_eq!(Balances::reserved_balance(0), 5);
|
||||
});
|
||||
@@ -231,7 +231,7 @@ fn spend_proposal_takes_proportional_deposit() {
|
||||
fn spend_proposal_fails_when_proposer_poor() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
Treasury::propose_spend(Origin::signed(2), 100, 3),
|
||||
Treasury::propose_spend(RuntimeOrigin::signed(2), 100, 3),
|
||||
Error::<Test, _>::InsufficientProposersBalance,
|
||||
);
|
||||
});
|
||||
@@ -242,8 +242,8 @@ fn accepted_spend_proposal_ignored_outside_spend_period() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 0));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(1);
|
||||
assert_eq!(Balances::free_balance(3), 0);
|
||||
@@ -269,8 +269,8 @@ fn rejected_spend_proposal_ignored_on_spend_period() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(RuntimeOrigin::root(), 0));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
assert_eq!(Balances::free_balance(3), 0);
|
||||
@@ -283,23 +283,32 @@ fn reject_already_rejected_spend_proposal_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(Origin::root(), 0));
|
||||
assert_noop!(Treasury::reject_proposal(Origin::root(), 0), Error::<Test, _>::InvalidIndex);
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(RuntimeOrigin::root(), 0));
|
||||
assert_noop!(
|
||||
Treasury::reject_proposal(RuntimeOrigin::root(), 0),
|
||||
Error::<Test, _>::InvalidIndex
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reject_non_existent_spend_proposal_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Treasury::reject_proposal(Origin::root(), 0), Error::<Test, _>::InvalidIndex);
|
||||
assert_noop!(
|
||||
Treasury::reject_proposal(RuntimeOrigin::root(), 0),
|
||||
Error::<Test, _>::InvalidIndex
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accept_non_existent_spend_proposal_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(Treasury::approve_proposal(Origin::root(), 0), Error::<Test, _>::InvalidIndex);
|
||||
assert_noop!(
|
||||
Treasury::approve_proposal(RuntimeOrigin::root(), 0),
|
||||
Error::<Test, _>::InvalidIndex
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -308,9 +317,12 @@ fn accept_already_rejected_spend_proposal_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(Origin::root(), 0));
|
||||
assert_noop!(Treasury::approve_proposal(Origin::root(), 0), Error::<Test, _>::InvalidIndex);
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::reject_proposal(RuntimeOrigin::root(), 0));
|
||||
assert_noop!(
|
||||
Treasury::approve_proposal(RuntimeOrigin::root(), 0),
|
||||
Error::<Test, _>::InvalidIndex
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -320,8 +332,8 @@ fn accepted_spend_proposal_enacted_on_spend_period() {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 0));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
assert_eq!(Balances::free_balance(3), 100);
|
||||
@@ -335,8 +347,8 @@ fn pot_underflow_should_not_diminish() {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 150, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 150, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 0));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
assert_eq!(Treasury::pot(), 100); // Pot hasn't changed
|
||||
@@ -357,14 +369,14 @@ fn treasury_account_doesnt_get_deleted() {
|
||||
assert_eq!(Treasury::pot(), 100);
|
||||
let treasury_balance = Balances::free_balance(&Treasury::account_id());
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), treasury_balance, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), treasury_balance, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 0));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
assert_eq!(Treasury::pot(), 100); // Pot hasn't changed
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), Treasury::pot(), 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 1));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), Treasury::pot(), 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 1));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(4);
|
||||
assert_eq!(Treasury::pot(), 0); // Pot is emptied
|
||||
@@ -387,10 +399,10 @@ fn inexistent_account_works() {
|
||||
assert_eq!(Balances::free_balance(Treasury::account_id()), 0); // Account does not exist
|
||||
assert_eq!(Treasury::pot(), 0); // Pot is empty
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 99, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 1, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 1));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 99, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 1, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 1));
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
assert_eq!(Treasury::pot(), 0); // Pot hasn't changed
|
||||
assert_eq!(Balances::free_balance(3), 0); // Balance of `3` hasn't changed
|
||||
@@ -432,14 +444,14 @@ fn max_approvals_limited() {
|
||||
Balances::make_free_balance_be(&0, u64::MAX);
|
||||
|
||||
for _ in 0..<Test as Config>::MaxApprovals::get() {
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 0));
|
||||
}
|
||||
|
||||
// One too many will fail
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_noop!(
|
||||
Treasury::approve_proposal(Origin::root(), 0),
|
||||
Treasury::approve_proposal(RuntimeOrigin::root(), 0),
|
||||
Error::<Test, _>::TooManyApprovals
|
||||
);
|
||||
});
|
||||
@@ -450,14 +462,14 @@ fn remove_already_removed_approval_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), 101);
|
||||
|
||||
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(Origin::root(), 0));
|
||||
assert_ok!(Treasury::propose_spend(RuntimeOrigin::signed(0), 100, 3));
|
||||
assert_ok!(Treasury::approve_proposal(RuntimeOrigin::root(), 0));
|
||||
assert_eq!(Treasury::approvals(), vec![0]);
|
||||
assert_ok!(Treasury::remove_approval(Origin::root(), 0));
|
||||
assert_ok!(Treasury::remove_approval(RuntimeOrigin::root(), 0));
|
||||
assert_eq!(Treasury::approvals(), vec![]);
|
||||
|
||||
assert_noop!(
|
||||
Treasury::remove_approval(Origin::root(), 0),
|
||||
Treasury::remove_approval(RuntimeOrigin::root(), 0),
|
||||
Error::<Test, _>::ProposalNotApproved
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user