Allow operational recovery path if on_initialize use fullblock. (#6089)

* note_preimage using operational

* Update frame/democracy/src/lib.rs

Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
thiolliere
2020-05-21 13:51:47 +02:00
committed by GitHub
parent 6c47b130e8
commit b50c3338d6
4 changed files with 138 additions and 67 deletions
+24 -16
View File
@@ -39,13 +39,14 @@ fn missing_preimage_should_fail() {
#[test]
fn preimage_deposit_should_be_required_and_returned() {
new_test_ext().execute_with(|| {
new_test_ext_execute_with_cond(|operational| {
// fee of 100 is too much.
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 100);
assert_noop!(
Democracy::note_preimage(Origin::signed(6), vec![0; 500]),
BalancesError::<Test, _>::InsufficientBalance,
);
if operational { Democracy::note_preimage_operational(Origin::signed(6), vec![0; 500]) }
else { Democracy::note_preimage(Origin::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(
@@ -69,17 +70,20 @@ fn preimage_deposit_should_be_required_and_returned() {
#[test]
fn preimage_deposit_should_be_reapable_earlier_by_owner() {
new_test_ext().execute_with(|| {
new_test_ext_execute_with_cond(|operational| {
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
assert_ok!(Democracy::note_preimage(Origin::signed(6), set_balance_proposal(2)));
assert_ok!(
if operational { Democracy::note_preimage_operational(Origin::signed(6), set_balance_proposal(2)) }
else { Democracy::note_preimage(Origin::signed(6), set_balance_proposal(2)) }
);
assert_eq!(Balances::reserved_balance(6), 12);
next_block();
assert_noop!(
Democracy::reap_preimage(Origin::signed(6), set_balance_proposal_hash(2), u32::max_value()),
Error::<Test>::TooEarly
);
Democracy::reap_preimage(Origin::signed(6), set_balance_proposal_hash(2), u32::max_value()),
Error::<Test>::TooEarly
);
next_block();
assert_ok!(Democracy::reap_preimage(Origin::signed(6), set_balance_proposal_hash(2), u32::max_value()));
@@ -90,14 +94,17 @@ fn preimage_deposit_should_be_reapable_earlier_by_owner() {
#[test]
fn preimage_deposit_should_be_reapable() {
new_test_ext().execute_with(|| {
new_test_ext_execute_with_cond(|operational| {
assert_noop!(
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::max_value()),
Error::<Test>::PreimageMissing
);
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
assert_ok!(Democracy::note_preimage(Origin::signed(6), set_balance_proposal(2)));
assert_ok!(
if operational { Democracy::note_preimage_operational(Origin::signed(6), set_balance_proposal(2)) }
else { Democracy::note_preimage(Origin::signed(6), set_balance_proposal(2)) }
);
assert_eq!(Balances::reserved_balance(6), 12);
next_block();
@@ -118,7 +125,7 @@ fn preimage_deposit_should_be_reapable() {
#[test]
fn noting_imminent_preimage_for_free_should_work() {
new_test_ext().execute_with(|| {
new_test_ext_execute_with_cond(|operational| {
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
let r = Democracy::inject_referendum(
@@ -130,14 +137,15 @@ fn noting_imminent_preimage_for_free_should_work() {
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
assert_noop!(
Democracy::note_imminent_preimage(Origin::signed(7), set_balance_proposal(2)),
Error::<Test>::NotImminent
);
if operational { Democracy::note_imminent_preimage_operational(Origin::signed(6), set_balance_proposal(2)) }
else { Democracy::note_imminent_preimage(Origin::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(Origin::signed(7), set_balance_proposal(2)));
assert_ok!(Democracy::note_imminent_preimage(Origin::signed(6), set_balance_proposal(2)));
next_block();