mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 17:47:56 +00:00
Bound uses of Call (#11649)
* Introduce preimages module in traits * Multisize Preimages * Len not actually necessary * Tweaks to the preimage API * Fixes * Get Scheduler building with new API * Scheduler tests pass * Bounded Scheduler 🎉 * Use Agenda holes and introduce IncompleteSince to avoid need to reschedule * Tests pass with new weight system * New benchmarks * Add missing file * Drop preimage when permenantly overeight * Drop preimage when permenantly overeight * Referenda uses latest preimage API * Testing ok * Adding tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add preimage migration Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Docs * Remove dbg * Refactor Democracy * Refactor Democracy * Add final MEL * Remove silly maps * Fixes * Minor refactor * Formatting * Fixes * Fixes * Fixes * Update frame/preimage/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Add migrations to Democracy * WIP Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Resolve conflicts Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Revert "Resolve conflicts" This reverts commit 734d66d69e54553471ffa54fa52e3e304dc8f106. * Undo wrong resolves... Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * WIP Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Make compile Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * massage clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * More clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * clippy annoyance Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * clippy annoyance Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix benchmarks Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * add missing file * Test <Preimage as QueryPreimage> Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * More tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Clippy harassment Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fixup tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove old stuff Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fmt Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Test <Scheduler as Anon> trait functions Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update pallet-ui tests Why is this needed? Should not be the case unless master is broken... Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * More scheduler trait test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * More tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Apply review suggestion Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Beauty fixes Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add Scheduler test migration_v3_to_v4_works Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Merge fixup Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Keep referenda benchmarks instantiatable Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update weights Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use new scheduler weight functions Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use new democracy weight functions Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use weight compare functions Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update pallet-ui tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * More renaming… Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * More renaming… Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add comment Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Implement OnRuntimeUpgrade for scheduler::v3_to_v4 migration Put the migration into a proper `MigrateToV4` struct and implement the OnRuntimeUpgrade hooks for it. Also move the test to use that instead. This should make it easier for adding it to Polkadot. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Clippy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Handle undecodable Agendas Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove trash Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use new OnRuntimeUpgrade functions Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * fix test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix BoundedSlice::truncate_from Co-authored-by: jakoblell Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix pre_upgrade hook return values Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add more error logging Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Find too large preimages in the pre_upgrade hook Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Test that too large Calls in agendas are ignored Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Use new OnRuntimeUpgrade hooks Why did the CI not catch this?! Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * works fine - just more logs Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix staking migration Causing issues on Kusama... Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix UI tests No idea why this is needed. This is actually undoing an earlier change. Maybe the CI has different rustc versions!? Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Remove multisig's Calls (#12072) * Remove multisig's Calls * Multisig: Fix tests and re-introduce reserve logic (#12241) * Fix tests and re-introduce reserve logic * fix benches * add todo * remove irrelevant bench * [Feature] Add a migration that drains and refunds stored calls (#12313) * [Feature] Add a migration that drains and refunds stored calls * migration fixes * fixes * address review comments * consume the whole block weight * fix assertions * license header * fix interface Co-authored-by: parity-processbot <> Co-authored-by: parity-processbot <> Co-authored-by: Roman Useinov <roman.useinov@gmail.com> * Fix test Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix multisig benchmarks Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * ".git/.scripts/bench-bot.sh" pallet dev pallet_democracy * ".git/.scripts/bench-bot.sh" pallet dev pallet_scheduler * ".git/.scripts/bench-bot.sh" pallet dev pallet_preimage Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: parity-processbot <> Co-authored-by: Roman Useinov <roman.useinov@gmail.com>
This commit is contained in:
@@ -24,7 +24,7 @@ fn cancel_referendum_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
@@ -42,37 +42,13 @@ fn cancel_referendum_should_work() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cancel_queued_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 1));
|
||||
|
||||
// start of 2 => next referendum scheduled.
|
||||
fast_forward_to(2);
|
||||
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), 0, aye(1)));
|
||||
|
||||
fast_forward_to(4);
|
||||
|
||||
assert!(pallet_scheduler::Agenda::<Test>::get(6)[0].is_some());
|
||||
|
||||
assert_noop!(
|
||||
Democracy::cancel_queued(RuntimeOrigin::root(), 1),
|
||||
Error::<Test>::ProposalMissing
|
||||
);
|
||||
assert_ok!(Democracy::cancel_queued(RuntimeOrigin::root(), 0));
|
||||
assert!(pallet_scheduler::Agenda::<Test>::get(6)[0].is_none());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn emergency_cancel_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
2,
|
||||
);
|
||||
@@ -86,7 +62,7 @@ fn emergency_cancel_should_work() {
|
||||
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
2,
|
||||
);
|
||||
|
||||
@@ -18,7 +18,10 @@
|
||||
//! The for various partial storage decoders
|
||||
|
||||
use super::*;
|
||||
use frame_support::storage::{migration, unhashed};
|
||||
use frame_support::{
|
||||
storage::{migration, unhashed},
|
||||
BoundedVec,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_decode_compact_u32_at() {
|
||||
@@ -42,7 +45,8 @@ fn test_decode_compact_u32_at() {
|
||||
fn len_of_deposit_of() {
|
||||
new_test_ext().execute_with(|| {
|
||||
for l in vec![0, 1, 200, 1000] {
|
||||
let value: (Vec<u64>, u64) = ((0..l).map(|_| Default::default()).collect(), 3u64);
|
||||
let value: (BoundedVec<u64, _>, u64) =
|
||||
((0..l).map(|_| Default::default()).collect::<Vec<_>>().try_into().unwrap(), 3u64);
|
||||
DepositOf::<Test>::insert(2, value);
|
||||
assert_eq!(Democracy::len_of_deposit_of(2), Some(l));
|
||||
}
|
||||
@@ -51,35 +55,3 @@ fn len_of_deposit_of() {
|
||||
assert_eq!(Democracy::len_of_deposit_of(2), None);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pre_image() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let key = Default::default();
|
||||
let missing = PreimageStatus::Missing(0);
|
||||
Preimages::<Test>::insert(key, missing);
|
||||
assert_noop!(Democracy::pre_image_data_len(key), Error::<Test>::PreimageMissing);
|
||||
assert_eq!(Democracy::check_pre_image_is_missing(key), Ok(()));
|
||||
|
||||
Preimages::<Test>::remove(key);
|
||||
assert_noop!(Democracy::pre_image_data_len(key), Error::<Test>::PreimageMissing);
|
||||
assert_noop!(Democracy::check_pre_image_is_missing(key), Error::<Test>::NotImminent);
|
||||
|
||||
for l in vec![0, 10, 100, 1000u32] {
|
||||
let available = PreimageStatus::Available {
|
||||
data: (0..l).map(|i| i as u8).collect(),
|
||||
provider: 0,
|
||||
deposit: 0,
|
||||
since: 0,
|
||||
expiry: None,
|
||||
};
|
||||
|
||||
Preimages::<Test>::insert(key, available);
|
||||
assert_eq!(Democracy::pre_image_data_len(key), Ok(l));
|
||||
assert_noop!(
|
||||
Democracy::check_pre_image_is_missing(key),
|
||||
Error::<Test>::DuplicatePreimage
|
||||
);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ fn single_proposal_should_work_with_delegation() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 1));
|
||||
assert_ok!(propose_set_balance(1, 2, 1));
|
||||
|
||||
fast_forward_to(2);
|
||||
|
||||
@@ -75,7 +75,7 @@ fn cyclic_delegation_should_unwind() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 1));
|
||||
assert_ok!(propose_set_balance(1, 2, 1));
|
||||
|
||||
fast_forward_to(2);
|
||||
|
||||
@@ -100,7 +100,7 @@ fn single_proposal_should_work_with_vote_and_delegation() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 1));
|
||||
assert_ok!(propose_set_balance(1, 2, 1));
|
||||
|
||||
fast_forward_to(2);
|
||||
|
||||
@@ -122,7 +122,7 @@ fn single_proposal_should_work_with_undelegation() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 1));
|
||||
assert_ok!(propose_set_balance(1, 2, 1));
|
||||
|
||||
// Delegate and undelegate vote.
|
||||
assert_ok!(Democracy::delegate(RuntimeOrigin::signed(2), 1, Conviction::None, 20));
|
||||
|
||||
@@ -23,35 +23,29 @@ use super::*;
|
||||
fn veto_external_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_ok!(Democracy::external_propose(
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
));
|
||||
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),));
|
||||
assert!(<NextExternal<Test>>::exists());
|
||||
|
||||
let h = set_balance_proposal_hash_and_note(2);
|
||||
let h = set_balance_proposal(2).hash();
|
||||
assert_ok!(Democracy::veto_external(RuntimeOrigin::signed(3), h));
|
||||
// cancelled.
|
||||
assert!(!<NextExternal<Test>>::exists());
|
||||
// fails - same proposal can't be resubmitted.
|
||||
assert_noop!(
|
||||
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal_hash(2),),
|
||||
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),),
|
||||
Error::<Test>::ProposalBlacklisted
|
||||
);
|
||||
|
||||
fast_forward_to(1);
|
||||
// fails as we're still in cooloff period.
|
||||
assert_noop!(
|
||||
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal_hash(2),),
|
||||
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),),
|
||||
Error::<Test>::ProposalBlacklisted
|
||||
);
|
||||
|
||||
fast_forward_to(2);
|
||||
// works; as we're out of the cooloff period.
|
||||
assert_ok!(Democracy::external_propose(
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
));
|
||||
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),));
|
||||
assert!(<NextExternal<Test>>::exists());
|
||||
|
||||
// 3 can't veto the same thing twice.
|
||||
@@ -68,14 +62,11 @@ fn veto_external_works() {
|
||||
fast_forward_to(3);
|
||||
// same proposal fails as we're still in cooloff
|
||||
assert_noop!(
|
||||
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal_hash(2),),
|
||||
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2)),
|
||||
Error::<Test>::ProposalBlacklisted
|
||||
);
|
||||
// different proposal works fine.
|
||||
assert_ok!(Democracy::external_propose(
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(3),
|
||||
));
|
||||
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(3),));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -84,22 +75,16 @@ fn external_blacklisting_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
|
||||
assert_ok!(Democracy::external_propose(
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
));
|
||||
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),));
|
||||
|
||||
let hash = set_balance_proposal_hash(2);
|
||||
let hash = set_balance_proposal(2).hash();
|
||||
assert_ok!(Democracy::blacklist(RuntimeOrigin::root(), hash, None));
|
||||
|
||||
fast_forward_to(2);
|
||||
assert_noop!(Democracy::referendum_status(0), Error::<Test>::ReferendumInvalid);
|
||||
|
||||
assert_noop!(
|
||||
Democracy::external_propose(
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
),
|
||||
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2)),
|
||||
Error::<Test>::ProposalBlacklisted,
|
||||
);
|
||||
});
|
||||
@@ -110,15 +95,12 @@ fn external_referendum_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_noop!(
|
||||
Democracy::external_propose(RuntimeOrigin::signed(1), set_balance_proposal_hash(2),),
|
||||
Democracy::external_propose(RuntimeOrigin::signed(1), set_balance_proposal(2),),
|
||||
BadOrigin,
|
||||
);
|
||||
assert_ok!(Democracy::external_propose(
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
));
|
||||
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2),));
|
||||
assert_noop!(
|
||||
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal_hash(1),),
|
||||
Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(1),),
|
||||
Error::<Test>::DuplicateProposal
|
||||
);
|
||||
fast_forward_to(2);
|
||||
@@ -126,7 +108,7 @@ fn external_referendum_works() {
|
||||
Democracy::referendum_status(0),
|
||||
Ok(ReferendumStatus {
|
||||
end: 4,
|
||||
proposal_hash: set_balance_proposal_hash(2),
|
||||
proposal: set_balance_proposal(2),
|
||||
threshold: VoteThreshold::SuperMajorityApprove,
|
||||
delay: 2,
|
||||
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
|
||||
@@ -140,22 +122,19 @@ fn external_majority_referendum_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_noop!(
|
||||
Democracy::external_propose_majority(
|
||||
RuntimeOrigin::signed(1),
|
||||
set_balance_proposal_hash(2)
|
||||
),
|
||||
Democracy::external_propose_majority(RuntimeOrigin::signed(1), set_balance_proposal(2)),
|
||||
BadOrigin,
|
||||
);
|
||||
assert_ok!(Democracy::external_propose_majority(
|
||||
RuntimeOrigin::signed(3),
|
||||
set_balance_proposal_hash_and_note(2)
|
||||
set_balance_proposal(2)
|
||||
));
|
||||
fast_forward_to(2);
|
||||
assert_eq!(
|
||||
Democracy::referendum_status(0),
|
||||
Ok(ReferendumStatus {
|
||||
end: 4,
|
||||
proposal_hash: set_balance_proposal_hash(2),
|
||||
proposal: set_balance_proposal(2),
|
||||
threshold: VoteThreshold::SimpleMajority,
|
||||
delay: 2,
|
||||
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
|
||||
@@ -169,22 +148,19 @@ fn external_default_referendum_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_noop!(
|
||||
Democracy::external_propose_default(
|
||||
RuntimeOrigin::signed(3),
|
||||
set_balance_proposal_hash(2)
|
||||
),
|
||||
Democracy::external_propose_default(RuntimeOrigin::signed(3), set_balance_proposal(2)),
|
||||
BadOrigin,
|
||||
);
|
||||
assert_ok!(Democracy::external_propose_default(
|
||||
RuntimeOrigin::signed(1),
|
||||
set_balance_proposal_hash_and_note(2)
|
||||
set_balance_proposal(2)
|
||||
));
|
||||
fast_forward_to(2);
|
||||
assert_eq!(
|
||||
Democracy::referendum_status(0),
|
||||
Ok(ReferendumStatus {
|
||||
end: 4,
|
||||
proposal_hash: set_balance_proposal_hash(2),
|
||||
proposal: set_balance_proposal(2),
|
||||
threshold: VoteThreshold::SuperMajorityAgainst,
|
||||
delay: 2,
|
||||
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
|
||||
@@ -197,11 +173,8 @@ fn external_default_referendum_works() {
|
||||
fn external_and_public_interleaving_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_ok!(Democracy::external_propose(
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(1),
|
||||
));
|
||||
assert_ok!(propose_set_balance_and_note(6, 2, 2));
|
||||
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(1),));
|
||||
assert_ok!(propose_set_balance(6, 2, 2));
|
||||
|
||||
fast_forward_to(2);
|
||||
|
||||
@@ -210,17 +183,14 @@ fn external_and_public_interleaving_works() {
|
||||
Democracy::referendum_status(0),
|
||||
Ok(ReferendumStatus {
|
||||
end: 4,
|
||||
proposal_hash: set_balance_proposal_hash_and_note(1),
|
||||
proposal: set_balance_proposal(1),
|
||||
threshold: VoteThreshold::SuperMajorityApprove,
|
||||
delay: 2,
|
||||
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
|
||||
})
|
||||
);
|
||||
// replenish external
|
||||
assert_ok!(Democracy::external_propose(
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(3),
|
||||
));
|
||||
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(3),));
|
||||
|
||||
fast_forward_to(4);
|
||||
|
||||
@@ -229,7 +199,7 @@ fn external_and_public_interleaving_works() {
|
||||
Democracy::referendum_status(1),
|
||||
Ok(ReferendumStatus {
|
||||
end: 6,
|
||||
proposal_hash: set_balance_proposal_hash_and_note(2),
|
||||
proposal: set_balance_proposal(2),
|
||||
threshold: VoteThreshold::SuperMajorityApprove,
|
||||
delay: 2,
|
||||
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
|
||||
@@ -244,17 +214,14 @@ fn external_and_public_interleaving_works() {
|
||||
Democracy::referendum_status(2),
|
||||
Ok(ReferendumStatus {
|
||||
end: 8,
|
||||
proposal_hash: set_balance_proposal_hash_and_note(3),
|
||||
proposal: set_balance_proposal(3),
|
||||
threshold: VoteThreshold::SuperMajorityApprove,
|
||||
delay: 2,
|
||||
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
|
||||
})
|
||||
);
|
||||
// replenish external
|
||||
assert_ok!(Democracy::external_propose(
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(5),
|
||||
));
|
||||
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(5),));
|
||||
|
||||
fast_forward_to(8);
|
||||
|
||||
@@ -263,18 +230,15 @@ fn external_and_public_interleaving_works() {
|
||||
Democracy::referendum_status(3),
|
||||
Ok(ReferendumStatus {
|
||||
end: 10,
|
||||
proposal_hash: set_balance_proposal_hash_and_note(5),
|
||||
proposal: set_balance_proposal(5),
|
||||
threshold: VoteThreshold::SuperMajorityApprove,
|
||||
delay: 2,
|
||||
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
|
||||
})
|
||||
);
|
||||
// replenish both
|
||||
assert_ok!(Democracy::external_propose(
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(7),
|
||||
));
|
||||
assert_ok!(propose_set_balance_and_note(6, 4, 2));
|
||||
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(7),));
|
||||
assert_ok!(propose_set_balance(6, 4, 2));
|
||||
|
||||
fast_forward_to(10);
|
||||
|
||||
@@ -283,16 +247,16 @@ fn external_and_public_interleaving_works() {
|
||||
Democracy::referendum_status(4),
|
||||
Ok(ReferendumStatus {
|
||||
end: 12,
|
||||
proposal_hash: set_balance_proposal_hash_and_note(4),
|
||||
proposal: set_balance_proposal(4),
|
||||
threshold: VoteThreshold::SuperMajorityApprove,
|
||||
delay: 2,
|
||||
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
|
||||
})
|
||||
);
|
||||
// replenish public again
|
||||
assert_ok!(propose_set_balance_and_note(6, 6, 2));
|
||||
assert_ok!(propose_set_balance(6, 6, 2));
|
||||
// cancel external
|
||||
let h = set_balance_proposal_hash_and_note(7);
|
||||
let h = set_balance_proposal(7).hash();
|
||||
assert_ok!(Democracy::veto_external(RuntimeOrigin::signed(3), h));
|
||||
|
||||
fast_forward_to(12);
|
||||
@@ -302,7 +266,7 @@ fn external_and_public_interleaving_works() {
|
||||
Democracy::referendum_status(5),
|
||||
Ok(ReferendumStatus {
|
||||
end: 14,
|
||||
proposal_hash: set_balance_proposal_hash_and_note(6),
|
||||
proposal: set_balance_proposal(6),
|
||||
threshold: VoteThreshold::SuperMajorityApprove,
|
||||
delay: 2,
|
||||
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
|
||||
|
||||
@@ -23,14 +23,14 @@ use super::*;
|
||||
fn fast_track_referendum_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
let h = set_balance_proposal_hash_and_note(2);
|
||||
let h = set_balance_proposal(2).hash();
|
||||
assert_noop!(
|
||||
Democracy::fast_track(RuntimeOrigin::signed(5), h, 3, 2),
|
||||
Error::<Test>::ProposalMissing
|
||||
);
|
||||
assert_ok!(Democracy::external_propose_majority(
|
||||
RuntimeOrigin::signed(3),
|
||||
set_balance_proposal_hash_and_note(2)
|
||||
set_balance_proposal(2)
|
||||
));
|
||||
assert_noop!(Democracy::fast_track(RuntimeOrigin::signed(1), h, 3, 2), BadOrigin);
|
||||
assert_ok!(Democracy::fast_track(RuntimeOrigin::signed(5), h, 2, 0));
|
||||
@@ -38,7 +38,7 @@ fn fast_track_referendum_works() {
|
||||
Democracy::referendum_status(0),
|
||||
Ok(ReferendumStatus {
|
||||
end: 2,
|
||||
proposal_hash: set_balance_proposal_hash_and_note(2),
|
||||
proposal: set_balance_proposal(2),
|
||||
threshold: VoteThreshold::SimpleMajority,
|
||||
delay: 0,
|
||||
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
|
||||
@@ -51,14 +51,14 @@ fn fast_track_referendum_works() {
|
||||
fn instant_referendum_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
let h = set_balance_proposal_hash_and_note(2);
|
||||
let h = set_balance_proposal(2).hash();
|
||||
assert_noop!(
|
||||
Democracy::fast_track(RuntimeOrigin::signed(5), h, 3, 2),
|
||||
Error::<Test>::ProposalMissing
|
||||
);
|
||||
assert_ok!(Democracy::external_propose_majority(
|
||||
RuntimeOrigin::signed(3),
|
||||
set_balance_proposal_hash_and_note(2)
|
||||
set_balance_proposal(2)
|
||||
));
|
||||
assert_noop!(Democracy::fast_track(RuntimeOrigin::signed(1), h, 3, 2), BadOrigin);
|
||||
assert_noop!(Democracy::fast_track(RuntimeOrigin::signed(5), h, 1, 0), BadOrigin);
|
||||
@@ -76,7 +76,7 @@ fn instant_referendum_works() {
|
||||
Democracy::referendum_status(0),
|
||||
Ok(ReferendumStatus {
|
||||
end: 1,
|
||||
proposal_hash: set_balance_proposal_hash_and_note(2),
|
||||
proposal: set_balance_proposal(2),
|
||||
threshold: VoteThreshold::SimpleMajority,
|
||||
delay: 0,
|
||||
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
|
||||
@@ -93,7 +93,7 @@ fn instant_next_block_referendum_backed() {
|
||||
let majority_origin_id = 3;
|
||||
let instant_origin_id = 6;
|
||||
let voting_period = 1;
|
||||
let proposal_hash = set_balance_proposal_hash_and_note(2);
|
||||
let proposal = set_balance_proposal(2);
|
||||
let delay = 2; // has no effect on test
|
||||
|
||||
// init
|
||||
@@ -103,13 +103,13 @@ fn instant_next_block_referendum_backed() {
|
||||
// propose with majority origin
|
||||
assert_ok!(Democracy::external_propose_majority(
|
||||
RuntimeOrigin::signed(majority_origin_id),
|
||||
proposal_hash
|
||||
proposal.clone()
|
||||
));
|
||||
|
||||
// fast track with instant origin and voting period pointing to the next block
|
||||
assert_ok!(Democracy::fast_track(
|
||||
RuntimeOrigin::signed(instant_origin_id),
|
||||
proposal_hash,
|
||||
proposal.hash(),
|
||||
voting_period,
|
||||
delay
|
||||
));
|
||||
@@ -119,7 +119,7 @@ fn instant_next_block_referendum_backed() {
|
||||
Democracy::referendum_status(0),
|
||||
Ok(ReferendumStatus {
|
||||
end: start_block_number + voting_period,
|
||||
proposal_hash,
|
||||
proposal,
|
||||
threshold: VoteThreshold::SimpleMajority,
|
||||
delay,
|
||||
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
|
||||
@@ -143,11 +143,8 @@ fn instant_next_block_referendum_backed() {
|
||||
fn fast_track_referendum_fails_when_no_simple_majority() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
let h = set_balance_proposal_hash_and_note(2);
|
||||
assert_ok!(Democracy::external_propose(
|
||||
RuntimeOrigin::signed(2),
|
||||
set_balance_proposal_hash_and_note(2)
|
||||
));
|
||||
let h = set_balance_proposal(2).hash();
|
||||
assert_ok!(Democracy::external_propose(RuntimeOrigin::signed(2), set_balance_proposal(2)));
|
||||
assert_noop!(
|
||||
Democracy::fast_track(RuntimeOrigin::signed(5), h, 3, 2),
|
||||
Error::<Test>::NotSimpleMajority
|
||||
|
||||
@@ -43,7 +43,7 @@ fn lock_voting_should_work() {
|
||||
System::set_block_number(0);
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
@@ -59,7 +59,7 @@ fn lock_voting_should_work() {
|
||||
assert_eq!(Balances::locks(i), vec![the_lock(i * 10)]);
|
||||
}
|
||||
|
||||
fast_forward_to(2);
|
||||
fast_forward_to(3);
|
||||
|
||||
// Referendum passed; 1 and 5 didn't get their way and can now reap and unlock.
|
||||
assert_ok!(Democracy::remove_vote(RuntimeOrigin::signed(1), r));
|
||||
@@ -126,13 +126,13 @@ fn no_locks_without_conviction_should_work() {
|
||||
System::set_block_number(0);
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(0, 10)));
|
||||
|
||||
fast_forward_to(2);
|
||||
fast_forward_to(3);
|
||||
|
||||
assert_eq!(Balances::free_balance(42), 2);
|
||||
assert_ok!(Democracy::remove_other_vote(RuntimeOrigin::signed(2), 1, r));
|
||||
@@ -146,7 +146,7 @@ fn lock_voting_should_work_with_delegation() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
@@ -167,28 +167,16 @@ fn lock_voting_should_work_with_delegation() {
|
||||
|
||||
fn setup_three_referenda() -> (u32, u32, u32) {
|
||||
System::set_block_number(0);
|
||||
let r1 = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
VoteThreshold::SimpleMajority,
|
||||
0,
|
||||
);
|
||||
let r1 =
|
||||
Democracy::inject_referendum(2, set_balance_proposal(2), VoteThreshold::SimpleMajority, 0);
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r1, aye(4, 10)));
|
||||
|
||||
let r2 = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
VoteThreshold::SimpleMajority,
|
||||
0,
|
||||
);
|
||||
let r2 =
|
||||
Democracy::inject_referendum(2, set_balance_proposal(2), VoteThreshold::SimpleMajority, 0);
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r2, aye(3, 20)));
|
||||
|
||||
let r3 = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
VoteThreshold::SimpleMajority,
|
||||
0,
|
||||
);
|
||||
let r3 =
|
||||
Democracy::inject_referendum(2, set_balance_proposal(2), VoteThreshold::SimpleMajority, 0);
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(5), r3, aye(2, 50)));
|
||||
|
||||
fast_forward_to(2);
|
||||
@@ -306,7 +294,7 @@ fn locks_should_persist_from_voting_to_delegation() {
|
||||
System::set_block_number(0);
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SimpleMajority,
|
||||
0,
|
||||
);
|
||||
|
||||
@@ -1,237 +0,0 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! The preimage tests.
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn missing_preimage_should_fail() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
|
||||
next_block();
|
||||
next_block();
|
||||
|
||||
assert_eq!(Balances::free_balance(42), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preimage_deposit_should_be_required_and_returned() {
|
||||
new_test_ext_execute_with_cond(|operational| {
|
||||
// fee of 100 is too much.
|
||||
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 100);
|
||||
assert_noop!(
|
||||
if operational {
|
||||
Democracy::note_preimage_operational(RuntimeOrigin::signed(6), vec![0; 500])
|
||||
} else {
|
||||
Democracy::note_preimage(RuntimeOrigin::signed(6), vec![0; 500])
|
||||
},
|
||||
BalancesError::<Test, _>::InsufficientBalance,
|
||||
);
|
||||
// fee of 1 is reasonable.
|
||||
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
|
||||
assert_eq!(Balances::reserved_balance(6), 12);
|
||||
|
||||
next_block();
|
||||
next_block();
|
||||
|
||||
assert_eq!(Balances::reserved_balance(6), 0);
|
||||
assert_eq!(Balances::free_balance(6), 60);
|
||||
assert_eq!(Balances::free_balance(42), 2);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preimage_deposit_should_be_reapable_earlier_by_owner() {
|
||||
new_test_ext_execute_with_cond(|operational| {
|
||||
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
|
||||
assert_ok!(if operational {
|
||||
Democracy::note_preimage_operational(RuntimeOrigin::signed(6), set_balance_proposal(2))
|
||||
} else {
|
||||
Democracy::note_preimage(RuntimeOrigin::signed(6), set_balance_proposal(2))
|
||||
});
|
||||
|
||||
assert_eq!(Balances::reserved_balance(6), 12);
|
||||
|
||||
next_block();
|
||||
assert_noop!(
|
||||
Democracy::reap_preimage(
|
||||
RuntimeOrigin::signed(6),
|
||||
set_balance_proposal_hash(2),
|
||||
u32::MAX
|
||||
),
|
||||
Error::<Test>::TooEarly
|
||||
);
|
||||
next_block();
|
||||
assert_ok!(Democracy::reap_preimage(
|
||||
RuntimeOrigin::signed(6),
|
||||
set_balance_proposal_hash(2),
|
||||
u32::MAX
|
||||
));
|
||||
|
||||
assert_eq!(Balances::free_balance(6), 60);
|
||||
assert_eq!(Balances::reserved_balance(6), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preimage_deposit_should_be_reapable() {
|
||||
new_test_ext_execute_with_cond(|operational| {
|
||||
assert_noop!(
|
||||
Democracy::reap_preimage(
|
||||
RuntimeOrigin::signed(5),
|
||||
set_balance_proposal_hash(2),
|
||||
u32::MAX
|
||||
),
|
||||
Error::<Test>::PreimageMissing
|
||||
);
|
||||
|
||||
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
|
||||
assert_ok!(if operational {
|
||||
Democracy::note_preimage_operational(RuntimeOrigin::signed(6), set_balance_proposal(2))
|
||||
} else {
|
||||
Democracy::note_preimage(RuntimeOrigin::signed(6), set_balance_proposal(2))
|
||||
});
|
||||
assert_eq!(Balances::reserved_balance(6), 12);
|
||||
|
||||
next_block();
|
||||
next_block();
|
||||
next_block();
|
||||
assert_noop!(
|
||||
Democracy::reap_preimage(
|
||||
RuntimeOrigin::signed(5),
|
||||
set_balance_proposal_hash(2),
|
||||
u32::MAX
|
||||
),
|
||||
Error::<Test>::TooEarly
|
||||
);
|
||||
|
||||
next_block();
|
||||
assert_ok!(Democracy::reap_preimage(
|
||||
RuntimeOrigin::signed(5),
|
||||
set_balance_proposal_hash(2),
|
||||
u32::MAX
|
||||
));
|
||||
assert_eq!(Balances::reserved_balance(6), 0);
|
||||
assert_eq!(Balances::free_balance(6), 48);
|
||||
assert_eq!(Balances::free_balance(5), 62);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn noting_imminent_preimage_for_free_should_work() {
|
||||
new_test_ext_execute_with_cond(|operational| {
|
||||
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
|
||||
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
1,
|
||||
);
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
|
||||
assert_noop!(
|
||||
if operational {
|
||||
Democracy::note_imminent_preimage_operational(
|
||||
RuntimeOrigin::signed(6),
|
||||
set_balance_proposal(2),
|
||||
)
|
||||
} else {
|
||||
Democracy::note_imminent_preimage(RuntimeOrigin::signed(6), set_balance_proposal(2))
|
||||
},
|
||||
Error::<Test>::NotImminent
|
||||
);
|
||||
|
||||
next_block();
|
||||
|
||||
// Now we're in the dispatch queue it's all good.
|
||||
assert_ok!(Democracy::note_imminent_preimage(
|
||||
RuntimeOrigin::signed(6),
|
||||
set_balance_proposal(2)
|
||||
));
|
||||
|
||||
next_block();
|
||||
|
||||
assert_eq!(Balances::free_balance(42), 2);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reaping_imminent_preimage_should_fail() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let h = set_balance_proposal_hash_and_note(2);
|
||||
let r = Democracy::inject_referendum(3, h, VoteThreshold::SuperMajorityApprove, 1);
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
next_block();
|
||||
next_block();
|
||||
assert_noop!(
|
||||
Democracy::reap_preimage(RuntimeOrigin::signed(6), h, u32::MAX),
|
||||
Error::<Test>::Imminent
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn note_imminent_preimage_can_only_be_successful_once() {
|
||||
new_test_ext().execute_with(|| {
|
||||
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
|
||||
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
1,
|
||||
);
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r, aye(1)));
|
||||
next_block();
|
||||
|
||||
// First time works
|
||||
assert_ok!(Democracy::note_imminent_preimage(
|
||||
RuntimeOrigin::signed(6),
|
||||
set_balance_proposal(2)
|
||||
));
|
||||
|
||||
// Second time fails
|
||||
assert_noop!(
|
||||
Democracy::note_imminent_preimage(RuntimeOrigin::signed(6), set_balance_proposal(2)),
|
||||
Error::<Test>::DuplicatePreimage
|
||||
);
|
||||
|
||||
// Fails from any user
|
||||
assert_noop!(
|
||||
Democracy::note_imminent_preimage(RuntimeOrigin::signed(5), set_balance_proposal(2)),
|
||||
Error::<Test>::DuplicatePreimage
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -22,9 +22,9 @@ use super::*;
|
||||
#[test]
|
||||
fn backing_for_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 2));
|
||||
assert_ok!(propose_set_balance_and_note(1, 4, 4));
|
||||
assert_ok!(propose_set_balance_and_note(1, 3, 3));
|
||||
assert_ok!(propose_set_balance(1, 2, 2));
|
||||
assert_ok!(propose_set_balance(1, 4, 4));
|
||||
assert_ok!(propose_set_balance(1, 3, 3));
|
||||
assert_eq!(Democracy::backing_for(0), Some(2));
|
||||
assert_eq!(Democracy::backing_for(1), Some(4));
|
||||
assert_eq!(Democracy::backing_for(2), Some(3));
|
||||
@@ -34,11 +34,11 @@ fn backing_for_should_work() {
|
||||
#[test]
|
||||
fn deposit_for_proposals_should_be_taken() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 5));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(2), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(propose_set_balance(1, 2, 5));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(2), 0));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
|
||||
assert_eq!(Balances::free_balance(1), 5);
|
||||
assert_eq!(Balances::free_balance(2), 15);
|
||||
assert_eq!(Balances::free_balance(5), 35);
|
||||
@@ -48,11 +48,11 @@ fn deposit_for_proposals_should_be_taken() {
|
||||
#[test]
|
||||
fn deposit_for_proposals_should_be_returned() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 5));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(2), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0, u32::MAX));
|
||||
assert_ok!(propose_set_balance(1, 2, 5));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(2), 0));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
|
||||
assert_ok!(Democracy::second(RuntimeOrigin::signed(5), 0));
|
||||
fast_forward_to(3);
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
assert_eq!(Balances::free_balance(2), 20);
|
||||
@@ -77,30 +77,19 @@ fn poor_proposer_should_not_work() {
|
||||
#[test]
|
||||
fn poor_seconder_should_not_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(2, 2, 11));
|
||||
assert_ok!(propose_set_balance(2, 2, 11));
|
||||
assert_noop!(
|
||||
Democracy::second(RuntimeOrigin::signed(1), 0, u32::MAX),
|
||||
Democracy::second(RuntimeOrigin::signed(1), 0),
|
||||
BalancesError::<Test, _>::InsufficientBalance
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_seconds_upper_bound_should_not_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 5));
|
||||
assert_noop!(
|
||||
Democracy::second(RuntimeOrigin::signed(2), 0, 0),
|
||||
Error::<Test>::WrongUpperBound
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cancel_proposal_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 2));
|
||||
assert_ok!(propose_set_balance_and_note(1, 4, 4));
|
||||
assert_ok!(propose_set_balance(1, 2, 2));
|
||||
assert_ok!(propose_set_balance(1, 4, 4));
|
||||
assert_noop!(Democracy::cancel_proposal(RuntimeOrigin::signed(1), 0), BadOrigin);
|
||||
assert_ok!(Democracy::cancel_proposal(RuntimeOrigin::root(), 0));
|
||||
System::assert_last_event(crate::Event::ProposalCanceled { prop_index: 0 }.into());
|
||||
@@ -113,10 +102,10 @@ fn cancel_proposal_should_work() {
|
||||
fn blacklisting_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
let hash = set_balance_proposal_hash(2);
|
||||
let hash = set_balance_proposal(2).hash();
|
||||
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 2));
|
||||
assert_ok!(propose_set_balance_and_note(1, 4, 4));
|
||||
assert_ok!(propose_set_balance(1, 2, 2));
|
||||
assert_ok!(propose_set_balance(1, 4, 4));
|
||||
|
||||
assert_noop!(Democracy::blacklist(RuntimeOrigin::signed(1), hash, None), BadOrigin);
|
||||
assert_ok!(Democracy::blacklist(RuntimeOrigin::root(), hash, None));
|
||||
@@ -124,11 +113,11 @@ fn blacklisting_should_work() {
|
||||
assert_eq!(Democracy::backing_for(0), None);
|
||||
assert_eq!(Democracy::backing_for(1), Some(4));
|
||||
|
||||
assert_noop!(propose_set_balance_and_note(1, 2, 2), Error::<Test>::ProposalBlacklisted);
|
||||
assert_noop!(propose_set_balance(1, 2, 2), Error::<Test>::ProposalBlacklisted);
|
||||
|
||||
fast_forward_to(2);
|
||||
|
||||
let hash = set_balance_proposal_hash(4);
|
||||
let hash = set_balance_proposal(4).hash();
|
||||
assert_ok!(Democracy::referendum_status(0));
|
||||
assert_ok!(Democracy::blacklist(RuntimeOrigin::root(), hash, Some(0)));
|
||||
assert_noop!(Democracy::referendum_status(0), Error::<Test>::ReferendumInvalid);
|
||||
@@ -139,9 +128,9 @@ fn blacklisting_should_work() {
|
||||
fn runners_up_should_come_after() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 2));
|
||||
assert_ok!(propose_set_balance_and_note(1, 4, 4));
|
||||
assert_ok!(propose_set_balance_and_note(1, 3, 3));
|
||||
assert_ok!(propose_set_balance(1, 2, 2));
|
||||
assert_ok!(propose_set_balance(1, 4, 4));
|
||||
assert_ok!(propose_set_balance(1, 3, 3));
|
||||
fast_forward_to(2);
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), 0, aye(1)));
|
||||
fast_forward_to(4);
|
||||
|
||||
@@ -24,7 +24,7 @@ fn simple_passing_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
@@ -43,7 +43,7 @@ fn simple_failing_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
@@ -62,13 +62,13 @@ fn ooo_inject_referendums_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r1 = Democracy::inject_referendum(
|
||||
3,
|
||||
set_balance_proposal_hash_and_note(3),
|
||||
set_balance_proposal(3),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
let r2 = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
@@ -77,11 +77,13 @@ fn ooo_inject_referendums_should_work() {
|
||||
assert_eq!(tally(r2), Tally { ayes: 1, nays: 0, turnout: 10 });
|
||||
|
||||
next_block();
|
||||
assert_eq!(Balances::free_balance(42), 2);
|
||||
|
||||
assert_ok!(Democracy::vote(RuntimeOrigin::signed(1), r1, aye(1)));
|
||||
assert_eq!(tally(r1), Tally { ayes: 1, nays: 0, turnout: 10 });
|
||||
|
||||
next_block();
|
||||
assert_eq!(Balances::free_balance(42), 2);
|
||||
|
||||
next_block();
|
||||
assert_eq!(Balances::free_balance(42), 3);
|
||||
});
|
||||
@@ -92,7 +94,7 @@ fn delayed_enactment_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
1,
|
||||
);
|
||||
@@ -118,19 +120,19 @@ fn lowest_unbaked_should_be_sensible() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r1 = Democracy::inject_referendum(
|
||||
3,
|
||||
set_balance_proposal_hash_and_note(1),
|
||||
set_balance_proposal(1),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
let r2 = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
let r3 = Democracy::inject_referendum(
|
||||
10,
|
||||
set_balance_proposal_hash_and_note(3),
|
||||
set_balance_proposal(3),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
@@ -141,16 +143,19 @@ fn lowest_unbaked_should_be_sensible() {
|
||||
assert_eq!(Democracy::lowest_unbaked(), 0);
|
||||
|
||||
next_block();
|
||||
|
||||
// r2 is approved
|
||||
assert_eq!(Balances::free_balance(42), 2);
|
||||
// r2 ends with approval
|
||||
assert_eq!(Democracy::lowest_unbaked(), 0);
|
||||
|
||||
next_block();
|
||||
|
||||
// r1 is approved
|
||||
assert_eq!(Balances::free_balance(42), 1);
|
||||
// r1 ends with approval
|
||||
assert_eq!(Democracy::lowest_unbaked(), 3);
|
||||
assert_eq!(Democracy::lowest_unbaked(), Democracy::referendum_count());
|
||||
|
||||
// r2 is executed
|
||||
assert_eq!(Balances::free_balance(42), 2);
|
||||
|
||||
next_block();
|
||||
// r1 is executed
|
||||
assert_eq!(Balances::free_balance(42), 1);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ fn split_vote_cancellation_should_work() {
|
||||
fn single_proposal_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::set_block_number(0);
|
||||
assert_ok!(propose_set_balance_and_note(1, 2, 1));
|
||||
assert_ok!(propose_set_balance(1, 2, 1));
|
||||
let r = 0;
|
||||
assert!(Democracy::referendum_info(r).is_none());
|
||||
|
||||
@@ -76,7 +76,7 @@ fn single_proposal_should_work() {
|
||||
Democracy::referendum_status(0),
|
||||
Ok(ReferendumStatus {
|
||||
end: 4,
|
||||
proposal_hash: set_balance_proposal_hash_and_note(2),
|
||||
proposal: set_balance_proposal(2),
|
||||
threshold: VoteThreshold::SuperMajorityApprove,
|
||||
delay: 2,
|
||||
tally: Tally { ayes: 1, nays: 0, turnout: 10 },
|
||||
@@ -106,7 +106,7 @@ fn controversial_voting_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
@@ -132,7 +132,7 @@ fn controversial_low_turnout_voting_should_work() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
@@ -156,7 +156,7 @@ fn passing_low_turnout_voting_should_work() {
|
||||
|
||||
let r = Democracy::inject_referendum(
|
||||
2,
|
||||
set_balance_proposal_hash_and_note(2),
|
||||
set_balance_proposal(2),
|
||||
VoteThreshold::SuperMajorityApprove,
|
||||
0,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user