mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 03:21:06 +00:00
Several tweaks needed for Governance 2.0 (#11124)
* Add stepped curve for referenda * Treasury SpendOrigin * Add tests * Better Origin Or-gating * Reciprocal curve * Tests for reciprical and rounding in PerThings * Tweaks and new quad curve * Const derivation of reciprocal curve parameters * Remove some unneeded code * Actually useful linear curve * Fixes * Provisional curves * Rejig 'turnout' as 'support' * Use TypedGet * Fixes * Enable curve's ceil to be configured * Formatting * Fixes * Fixes * Fixes * Remove EnsureOneOf * Fixes * Fixes * Fixes * Formatting * Fixes * Update frame/support/src/traits/dispatch.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Grumbles * Formatting * Fixes * APIs of VoteTally should include class * Fixes * Fix overlay prefix removal result * Second part of the overlay prefix removal fix. * Formatting * Fixes * Add some tests and make clear rounding algo * Fixes * Formatting * Revert questionable fix * Introduce test for kill_prefix * Fixes * Formatting * Fixes * Fix possible overflow * Docs * Add benchmark test * Formatting * Update frame/referenda/src/types.rs Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * Docs * Fixes * Use latest API in tests * Formatting * Whitespace * Use latest API in tests Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
@@ -24,7 +24,7 @@ use std::cell::RefCell;
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
traits::{BadOrigin, BlakeTwo256, IdentityLookup},
|
||||
};
|
||||
|
||||
use frame_support::{
|
||||
@@ -101,8 +101,26 @@ parameter_types! {
|
||||
pub const ProposalBond: Permill = Permill::from_percent(5);
|
||||
pub const Burn: Permill = Permill::from_percent(50);
|
||||
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
|
||||
pub const MaxApprovals: u32 = 100;
|
||||
}
|
||||
pub struct TestSpendOrigin;
|
||||
impl frame_support::traits::EnsureOrigin<Origin> 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 {
|
||||
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)),
|
||||
})
|
||||
}
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> Origin {
|
||||
Origin::root()
|
||||
}
|
||||
}
|
||||
|
||||
impl Config for Test {
|
||||
type PalletId = TreasuryPalletId;
|
||||
type Currency = pallet_balances::Pallet<Test>;
|
||||
@@ -119,6 +137,7 @@ impl Config for Test {
|
||||
type WeightInfo = ();
|
||||
type SpendFunds = ();
|
||||
type MaxApprovals = ConstU32<100>;
|
||||
type SpendOrigin = TestSpendOrigin;
|
||||
}
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
@@ -141,6 +160,51 @@ 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(Origin::signed(10), 6, 1),
|
||||
Error::<Test>::InsufficientPermission
|
||||
);
|
||||
assert_noop!(
|
||||
Treasury::spend(Origin::signed(11), 11, 1),
|
||||
Error::<Test>::InsufficientPermission
|
||||
);
|
||||
assert_noop!(
|
||||
Treasury::spend(Origin::signed(12), 21, 1),
|
||||
Error::<Test>::InsufficientPermission
|
||||
);
|
||||
assert_noop!(
|
||||
Treasury::spend(Origin::signed(13), 51, 1),
|
||||
Error::<Test>::InsufficientPermission
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
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));
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(1);
|
||||
assert_eq!(Balances::free_balance(6), 0);
|
||||
|
||||
<Treasury as OnInitialize<u64>>::on_initialize(2);
|
||||
assert_eq!(Balances::free_balance(6), 100);
|
||||
assert_eq!(Treasury::pot(), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn minting_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
@@ -372,7 +436,7 @@ fn max_approvals_limited() {
|
||||
Balances::make_free_balance_be(&Treasury::account_id(), u64::MAX);
|
||||
Balances::make_free_balance_be(&0, u64::MAX);
|
||||
|
||||
for _ in 0..MaxApprovals::get() {
|
||||
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user