Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
@@ -26,7 +26,7 @@ fn cancel_referendum_should_work() {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
assert_ok!(Democracy::cancel_referendum(Origin::root(), r.into()));
@@ -67,7 +67,7 @@ fn emergency_cancel_should_work() {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
2
2,
);
assert!(Democracy::referendum_status(r).is_ok());
@@ -81,7 +81,7 @@ fn emergency_cancel_should_work() {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
2
2,
);
assert!(Democracy::referendum_status(r).is_ok());
assert_noop!(
@@ -66,7 +66,7 @@ fn pre_image() {
assert_noop!(Democracy::check_pre_image_is_missing(key), Error::<Test>::NotImminent);
for l in vec![0, 10, 100, 1000u32] {
let available = PreimageStatus::Available{
let available = PreimageStatus::Available {
data: (0..l).map(|i| i as u8).collect(),
provider: 0,
deposit: 0,
@@ -76,8 +76,10 @@ fn pre_image() {
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);
assert_noop!(
Democracy::check_pre_image_is_missing(key),
Error::<Test>::DuplicatePreimage
);
}
})
}
@@ -34,17 +34,17 @@ fn veto_external_works() {
// cancelled.
assert!(!<NextExternal<Test>>::exists());
// fails - same proposal can't be resubmitted.
assert_noop!(Democracy::external_propose(
Origin::signed(2),
set_balance_proposal_hash(2),
), Error::<Test>::ProposalBlacklisted);
assert_noop!(
Democracy::external_propose(Origin::signed(2), set_balance_proposal_hash(2),),
Error::<Test>::ProposalBlacklisted
);
fast_forward_to(1);
// fails as we're still in cooloff period.
assert_noop!(Democracy::external_propose(
Origin::signed(2),
set_balance_proposal_hash(2),
), Error::<Test>::ProposalBlacklisted);
assert_noop!(
Democracy::external_propose(Origin::signed(2), set_balance_proposal_hash(2),),
Error::<Test>::ProposalBlacklisted
);
fast_forward_to(2);
// works; as we're out of the cooloff period.
@@ -67,10 +67,10 @@ fn veto_external_works() {
fast_forward_to(3);
// same proposal fails as we're still in cooloff
assert_noop!(Democracy::external_propose(
Origin::signed(2),
set_balance_proposal_hash(2),
), Error::<Test>::ProposalBlacklisted);
assert_noop!(
Democracy::external_propose(Origin::signed(2), set_balance_proposal_hash(2),),
Error::<Test>::ProposalBlacklisted
);
// different proposal works fine.
assert_ok!(Democracy::external_propose(
Origin::signed(2),
@@ -96,10 +96,7 @@ fn external_blacklisting_should_work() {
assert_noop!(Democracy::referendum_status(0), Error::<Test>::ReferendumInvalid);
assert_noop!(
Democracy::external_propose(
Origin::signed(2),
set_balance_proposal_hash_and_note(2),
),
Democracy::external_propose(Origin::signed(2), set_balance_proposal_hash_and_note(2),),
Error::<Test>::ProposalBlacklisted,
);
});
@@ -110,20 +107,17 @@ fn external_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_noop!(
Democracy::external_propose(
Origin::signed(1),
set_balance_proposal_hash(2),
),
Democracy::external_propose(Origin::signed(1), set_balance_proposal_hash(2),),
BadOrigin,
);
assert_ok!(Democracy::external_propose(
Origin::signed(2),
set_balance_proposal_hash_and_note(2),
));
assert_noop!(Democracy::external_propose(
Origin::signed(2),
set_balance_proposal_hash(1),
), Error::<Test>::DuplicateProposal);
assert_noop!(
Democracy::external_propose(Origin::signed(2), set_balance_proposal_hash(1),),
Error::<Test>::DuplicateProposal
);
fast_forward_to(2);
assert_eq!(
Democracy::referendum_status(0),
@@ -143,10 +137,7 @@ fn external_majority_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_noop!(
Democracy::external_propose_majority(
Origin::signed(1),
set_balance_proposal_hash(2)
),
Democracy::external_propose_majority(Origin::signed(1), set_balance_proposal_hash(2)),
BadOrigin,
);
assert_ok!(Democracy::external_propose_majority(
@@ -172,10 +163,7 @@ fn external_default_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
assert_noop!(
Democracy::external_propose_default(
Origin::signed(3),
set_balance_proposal_hash(2)
),
Democracy::external_propose_default(Origin::signed(3), set_balance_proposal_hash(2)),
BadOrigin,
);
assert_ok!(Democracy::external_propose_default(
@@ -196,7 +184,6 @@ fn external_default_referendum_works() {
});
}
#[test]
fn external_and_public_interleaving_works() {
new_test_ext().execute_with(|| {
@@ -222,9 +209,9 @@ fn external_and_public_interleaving_works() {
);
// replenish external
assert_ok!(Democracy::external_propose(
Origin::signed(2),
set_balance_proposal_hash_and_note(3),
));
Origin::signed(2),
set_balance_proposal_hash_and_note(3),
));
fast_forward_to(4);
@@ -256,9 +243,9 @@ fn external_and_public_interleaving_works() {
);
// replenish external
assert_ok!(Democracy::external_propose(
Origin::signed(2),
set_balance_proposal_hash_and_note(5),
));
Origin::signed(2),
set_balance_proposal_hash_and_note(5),
));
fast_forward_to(8);
@@ -24,7 +24,10 @@ fn fast_track_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let h = set_balance_proposal_hash_and_note(2);
assert_noop!(Democracy::fast_track(Origin::signed(5), h, 3, 2), Error::<Test>::ProposalMissing);
assert_noop!(
Democracy::fast_track(Origin::signed(5), h, 3, 2),
Error::<Test>::ProposalMissing
);
assert_ok!(Democracy::external_propose_majority(
Origin::signed(3),
set_balance_proposal_hash_and_note(2)
@@ -49,14 +52,20 @@ fn instant_referendum_works() {
new_test_ext().execute_with(|| {
System::set_block_number(0);
let h = set_balance_proposal_hash_and_note(2);
assert_noop!(Democracy::fast_track(Origin::signed(5), h, 3, 2), Error::<Test>::ProposalMissing);
assert_noop!(
Democracy::fast_track(Origin::signed(5), h, 3, 2),
Error::<Test>::ProposalMissing
);
assert_ok!(Democracy::external_propose_majority(
Origin::signed(3),
set_balance_proposal_hash_and_note(2)
));
assert_noop!(Democracy::fast_track(Origin::signed(1), h, 3, 2), BadOrigin);
assert_noop!(Democracy::fast_track(Origin::signed(5), h, 1, 0), BadOrigin);
assert_noop!(Democracy::fast_track(Origin::signed(6), h, 1, 0), Error::<Test>::InstantNotAllowed);
assert_noop!(
Democracy::fast_track(Origin::signed(6), h, 1, 0),
Error::<Test>::InstantNotAllowed
);
INSTANT_ALLOWED.with(|v| *v.borrow_mut() = true);
assert_ok!(Democracy::fast_track(Origin::signed(6), h, 1, 0));
assert_eq!(
@@ -23,23 +23,19 @@ use std::convert::TryFrom;
fn aye(x: u8, balance: u64) -> AccountVote<u64> {
AccountVote::Standard {
vote: Vote { aye: true, conviction: Conviction::try_from(x).unwrap() },
balance
balance,
}
}
fn nay(x: u8, balance: u64) -> AccountVote<u64> {
AccountVote::Standard {
vote: Vote { aye: false, conviction: Conviction::try_from(x).unwrap() },
balance
balance,
}
}
fn the_lock(amount: u64) -> BalanceLock<u64> {
BalanceLock {
id: DEMOCRACY_ID,
amount,
reasons: pallet_balances::Reasons::Misc,
}
BalanceLock { id: DEMOCRACY_ID, amount, reasons: pallet_balances::Reasons::Misc }
}
#[test]
@@ -50,7 +46,7 @@ fn lock_voting_should_work() {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(1), r, nay(5, 10)));
assert_ok!(Democracy::vote(Origin::signed(2), r, aye(4, 20)));
@@ -74,7 +70,10 @@ fn lock_voting_should_work() {
assert_ok!(Democracy::unlock(Origin::signed(2), 5));
// 2, 3, 4 got their way with the vote, so they cannot be reaped by others.
assert_noop!(Democracy::remove_other_vote(Origin::signed(1), 2, r), Error::<Test>::NoPermission);
assert_noop!(
Democracy::remove_other_vote(Origin::signed(1), 2, r),
Error::<Test>::NoPermission
);
// However, they can be unvoted by the owner, though it will make no difference to the lock.
assert_ok!(Democracy::remove_vote(Origin::signed(2), r));
assert_ok!(Democracy::unlock(Origin::signed(2), 2));
@@ -86,10 +85,12 @@ fn lock_voting_should_work() {
assert_eq!(Balances::locks(5), vec![]);
assert_eq!(Balances::free_balance(42), 2);
fast_forward_to(5);
// No change yet...
assert_noop!(Democracy::remove_other_vote(Origin::signed(1), 4, r), Error::<Test>::NoPermission);
assert_noop!(
Democracy::remove_other_vote(Origin::signed(1), 4, r),
Error::<Test>::NoPermission
);
assert_ok!(Democracy::unlock(Origin::signed(1), 4));
assert_eq!(Balances::locks(4), vec![the_lock(40)]);
fast_forward_to(6);
@@ -99,7 +100,10 @@ fn lock_voting_should_work() {
assert_eq!(Balances::locks(4), vec![]);
fast_forward_to(9);
assert_noop!(Democracy::remove_other_vote(Origin::signed(1), 3, r), Error::<Test>::NoPermission);
assert_noop!(
Democracy::remove_other_vote(Origin::signed(1), 3, r),
Error::<Test>::NoPermission
);
assert_ok!(Democracy::unlock(Origin::signed(1), 3));
assert_eq!(Balances::locks(3), vec![the_lock(30)]);
fast_forward_to(10);
@@ -145,7 +149,7 @@ fn lock_voting_should_work_with_delegation() {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(1), r, nay(5, 10)));
assert_ok!(Democracy::vote(Origin::signed(2), r, aye(4, 20)));
@@ -168,7 +172,7 @@ fn setup_three_referenda() -> (u32, u32, u32) {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SimpleMajority,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(5), r1, aye(4, 10)));
@@ -176,7 +180,7 @@ fn setup_three_referenda() -> (u32, u32, u32) {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SimpleMajority,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(5), r2, aye(3, 20)));
@@ -184,7 +188,7 @@ fn setup_three_referenda() -> (u32, u32, u32) {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SimpleMajority,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(5), r3, aye(2, 50)));
@@ -202,7 +206,10 @@ fn prior_lockvotes_should_be_enforced() {
// r.2 locked 50 until #6.
fast_forward_to(5);
assert_noop!(Democracy::remove_other_vote(Origin::signed(1), 5, r.2), Error::<Test>::NoPermission);
assert_noop!(
Democracy::remove_other_vote(Origin::signed(1), 5, r.2),
Error::<Test>::NoPermission
);
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
assert_eq!(Balances::locks(5), vec![the_lock(50)]);
fast_forward_to(6);
@@ -210,7 +217,10 @@ fn prior_lockvotes_should_be_enforced() {
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
assert_eq!(Balances::locks(5), vec![the_lock(20)]);
fast_forward_to(9);
assert_noop!(Democracy::remove_other_vote(Origin::signed(1), 5, r.1), Error::<Test>::NoPermission);
assert_noop!(
Democracy::remove_other_vote(Origin::signed(1), 5, r.1),
Error::<Test>::NoPermission
);
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
assert_eq!(Balances::locks(5), vec![the_lock(20)]);
fast_forward_to(10);
@@ -218,7 +228,10 @@ fn prior_lockvotes_should_be_enforced() {
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
assert_eq!(Balances::locks(5), vec![the_lock(10)]);
fast_forward_to(17);
assert_noop!(Democracy::remove_other_vote(Origin::signed(1), 5, r.0), Error::<Test>::NoPermission);
assert_noop!(
Democracy::remove_other_vote(Origin::signed(1), 5, r.0),
Error::<Test>::NoPermission
);
assert_ok!(Democracy::unlock(Origin::signed(5), 5));
assert_eq!(Balances::locks(5), vec![the_lock(10)]);
fast_forward_to(18);
@@ -296,7 +309,7 @@ fn locks_should_persist_from_voting_to_delegation() {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SimpleMajority,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(5), r, aye(4, 10)));
fast_forward_to(2);
+47 -25
View File
@@ -26,7 +26,7 @@ fn missing_preimage_should_fail() {
2,
set_balance_proposal_hash(2),
VoteThreshold::SuperMajorityApprove,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
@@ -43,8 +43,11 @@ fn preimage_deposit_should_be_required_and_returned() {
// fee of 100 is too much.
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 100);
assert_noop!(
if operational { Democracy::note_preimage_operational(Origin::signed(6), vec![0; 500]) }
else { Democracy::note_preimage(Origin::signed(6), vec![0; 500]) },
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.
@@ -53,7 +56,7 @@ fn preimage_deposit_should_be_required_and_returned() {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
@@ -72,10 +75,11 @@ fn preimage_deposit_should_be_required_and_returned() {
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(Origin::signed(6), set_balance_proposal(2)) }
else { 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);
@@ -85,7 +89,11 @@ fn preimage_deposit_should_be_reapable_earlier_by_owner() {
Error::<Test>::TooEarly
);
next_block();
assert_ok!(Democracy::reap_preimage(Origin::signed(6), set_balance_proposal_hash(2), u32::MAX));
assert_ok!(Democracy::reap_preimage(
Origin::signed(6),
set_balance_proposal_hash(2),
u32::MAX
));
assert_eq!(Balances::free_balance(6), 60);
assert_eq!(Balances::reserved_balance(6), 0);
@@ -96,27 +104,32 @@ fn preimage_deposit_should_be_reapable_earlier_by_owner() {
fn preimage_deposit_should_be_reapable() {
new_test_ext_execute_with_cond(|operational| {
assert_noop!(
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::MAX),
Error::<Test>::PreimageMissing
);
Democracy::reap_preimage(Origin::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(Origin::signed(6), set_balance_proposal(2)) }
else { 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();
next_block();
next_block();
assert_noop!(
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::MAX),
Error::<Test>::TooEarly
);
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::MAX),
Error::<Test>::TooEarly
);
next_block();
assert_ok!(Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::MAX));
assert_ok!(Democracy::reap_preimage(
Origin::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);
@@ -132,13 +145,19 @@ fn noting_imminent_preimage_for_free_should_work() {
2,
set_balance_proposal_hash(2),
VoteThreshold::SuperMajorityApprove,
1
1,
);
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
assert_noop!(
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)) },
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
);
@@ -161,7 +180,10 @@ fn reaping_imminent_preimage_should_fail() {
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
next_block();
next_block();
assert_noop!(Democracy::reap_preimage(Origin::signed(6), h, u32::MAX), Error::<Test>::Imminent);
assert_noop!(
Democracy::reap_preimage(Origin::signed(6), h, u32::MAX),
Error::<Test>::Imminent
);
});
}
@@ -174,7 +196,7 @@ fn note_imminent_preimage_can_only_be_successful_once() {
2,
set_balance_proposal_hash(2),
VoteThreshold::SuperMajorityApprove,
1
1,
);
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
next_block();
@@ -89,10 +89,7 @@ fn poor_seconder_should_not_work() {
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(Origin::signed(2), 0, 0),
Error::<Test>::WrongUpperBound
);
assert_noop!(Democracy::second(Origin::signed(2), 0, 0), Error::<Test>::WrongUpperBound);
});
}
@@ -26,7 +26,7 @@ fn simple_passing_should_work() {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
assert_eq!(tally(r), Tally { ayes: 1, nays: 0, turnout: 10 });
@@ -43,7 +43,7 @@ fn simple_failing_should_work() {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(1), r, nay(1)));
assert_eq!(tally(r), Tally { ayes: 0, nays: 1, turnout: 10 });
@@ -62,13 +62,13 @@ fn ooo_inject_referendums_should_work() {
3,
set_balance_proposal_hash_and_note(3),
VoteThreshold::SuperMajorityApprove,
0
0,
);
let r2 = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(1), r2, aye(1)));
@@ -92,7 +92,7 @@ fn delayed_enactment_should_work() {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
1
1,
);
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
assert_ok!(Democracy::vote(Origin::signed(2), r, aye(2)));
@@ -23,7 +23,10 @@ use super::*;
fn overvoting_should_fail() {
new_test_ext().execute_with(|| {
let r = begin_referendum();
assert_noop!(Democracy::vote(Origin::signed(1), r, aye(2)), Error::<Test>::InsufficientFunds);
assert_noop!(
Democracy::vote(Origin::signed(1), r, aye(2)),
Error::<Test>::InsufficientFunds
);
});
}
@@ -102,7 +105,7 @@ fn controversial_voting_should_work() {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(1), r, big_aye(1)));
@@ -128,7 +131,7 @@ fn controversial_low_turnout_voting_should_work() {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(5), r, big_nay(5)));
assert_ok!(Democracy::vote(Origin::signed(6), r, big_aye(6)));
@@ -152,7 +155,7 @@ fn passing_low_turnout_voting_should_work() {
2,
set_balance_proposal_hash_and_note(2),
VoteThreshold::SuperMajorityApprove,
0
0,
);
assert_ok!(Democracy::vote(Origin::signed(4), r, big_aye(4)));
assert_ok!(Democracy::vote(Origin::signed(5), r, big_nay(5)));