Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use ext
  • Loading branch information
shawntabrizi committed Mar 31, 2020
commit bd7894795ddff8c31ab56d17b803bf86a59fbf51
19 changes: 4 additions & 15 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,19 +590,20 @@ mod tests {
);

fn make_ext() -> sp_io::TestExternalities {
GenesisConfig {
let mut ext: sp_io::TestExternalities = GenesisConfig {
collective_Instance1: Some(collective::GenesisConfig {
members: vec![1, 2, 3],
phantom: Default::default(),
}),
collective: None,
}.build_storage().unwrap().into()
}.build_storage().unwrap().into();
ext.execute_with(|| System::set_block_number(1));
ext
}

#[test]
fn motions_basic_environment_works() {
make_ext().execute_with(|| {
System::set_block_number(1);
assert_eq!(Collective::members(), vec![1, 2, 3]);
assert_eq!(Collective::proposals(), Vec::<H256>::new());
});
Expand All @@ -615,7 +616,6 @@ mod tests {
#[test]
fn close_works() {
make_ext().execute_with(|| {
System::set_block_number(1);
let proposal = make_proposal(42);
let hash = BlakeTwo256::hash_of(&proposal);

Expand Down Expand Up @@ -644,7 +644,6 @@ mod tests {
#[test]
fn close_with_prime_works() {
make_ext().execute_with(|| {
System::set_block_number(1);
let proposal = make_proposal(42);
let hash = BlakeTwo256::hash_of(&proposal);
assert_ok!(Collective::set_members(Origin::ROOT, vec![1, 2, 3], Some(3)));
Expand All @@ -668,7 +667,6 @@ mod tests {
#[test]
fn close_with_voting_prime_works() {
make_ext().execute_with(|| {
System::set_block_number(1);
let proposal = make_proposal(42);
let hash = BlakeTwo256::hash_of(&proposal);
assert_ok!(Collective::set_members(Origin::ROOT, vec![1, 2, 3], Some(1)));
Expand All @@ -693,7 +691,6 @@ mod tests {
#[test]
fn removal_of_old_voters_votes_works() {
make_ext().execute_with(|| {
System::set_block_number(1);
let proposal = make_proposal(42);
let hash = BlakeTwo256::hash_of(&proposal);
let end = 4;
Expand Down Expand Up @@ -728,7 +725,6 @@ mod tests {
#[test]
fn removal_of_old_voters_votes_works_with_set_members() {
make_ext().execute_with(|| {
System::set_block_number(1);
let proposal = make_proposal(42);
let hash = BlakeTwo256::hash_of(&proposal);
let end = 4;
Expand Down Expand Up @@ -763,7 +759,6 @@ mod tests {
#[test]
fn propose_works() {
make_ext().execute_with(|| {
System::set_block_number(1);
let proposal = make_proposal(42);
let hash = proposal.blake2_256().into();
let end = 4;
Expand Down Expand Up @@ -793,7 +788,6 @@ mod tests {
#[test]
fn motions_ignoring_non_collective_proposals_works() {
make_ext().execute_with(|| {
System::set_block_number(1);
let proposal = make_proposal(42);
assert_noop!(
Collective::propose(Origin::signed(42), 3, Box::new(proposal.clone())),
Expand All @@ -805,7 +799,6 @@ mod tests {
#[test]
fn motions_ignoring_non_collective_votes_works() {
make_ext().execute_with(|| {
System::set_block_number(1);
let proposal = make_proposal(42);
let hash: H256 = proposal.blake2_256().into();
assert_ok!(Collective::propose(Origin::signed(1), 3, Box::new(proposal.clone())));
Expand Down Expand Up @@ -833,7 +826,6 @@ mod tests {
#[test]
fn motions_revoting_works() {
make_ext().execute_with(|| {
System::set_block_number(1);
let proposal = make_proposal(42);
let hash: H256 = proposal.blake2_256().into();
let end = 4;
Expand Down Expand Up @@ -885,7 +877,6 @@ mod tests {
#[test]
fn motions_reproposing_disapproved_works() {
make_ext().execute_with(|| {
System::set_block_number(1);
let proposal = make_proposal(42);
let hash: H256 = proposal.blake2_256().into();
assert_ok!(Collective::propose(Origin::signed(1), 3, Box::new(proposal.clone())));
Expand All @@ -899,7 +890,6 @@ mod tests {
#[test]
fn motions_disapproval_works() {
make_ext().execute_with(|| {
System::set_block_number(1);
let proposal = make_proposal(42);
let hash: H256 = proposal.blake2_256().into();
assert_ok!(Collective::propose(Origin::signed(1), 3, Box::new(proposal.clone())));
Expand Down Expand Up @@ -942,7 +932,6 @@ mod tests {
#[test]
fn motions_approval_works() {
make_ext().execute_with(|| {
System::set_block_number(1);
let proposal = make_proposal(42);
let hash: H256 = proposal.blake2_256().into();
assert_ok!(Collective::propose(Origin::signed(1), 2, Box::new(proposal.clone())));
Expand Down
11 changes: 3 additions & 8 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ impl ExtBuilder {
},
gas_price: self.gas_price,
}.assimilate_storage(&mut t).unwrap();
sp_io::TestExternalities::new(t)
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}
}

Expand Down Expand Up @@ -415,7 +417,6 @@ fn instantiate_and_call_and_deposit_event() {
let (wasm, code_hash) = compile_module::<Test>(CODE_RETURN_FROM_START_FN).unwrap();

ExtBuilder::default().existential_deposit(100).build().execute_with(|| {
System::set_block_number(1);
Balances::deposit_creating(&ALICE, 1_000_000);

assert_ok!(Contracts::put_code(Origin::signed(ALICE), 100_000, wasm));
Expand Down Expand Up @@ -506,7 +507,6 @@ fn dispatch_call() {
let (wasm, code_hash) = compile_module::<Test>(CODE_DISPATCH_CALL).unwrap();

ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
System::set_block_number(1);
Balances::deposit_creating(&ALICE, 1_000_000);

assert_ok!(Contracts::put_code(Origin::signed(ALICE), 100_000, wasm));
Expand Down Expand Up @@ -645,7 +645,6 @@ fn dispatch_call_not_dispatched_after_top_level_transaction_failure() {
let (wasm, code_hash) = compile_module::<Test>(CODE_DISPATCH_CALL_THEN_TRAP).unwrap();

ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
System::set_block_number(1);
Balances::deposit_creating(&ALICE, 1_000_000);

assert_ok!(Contracts::put_code(Origin::signed(ALICE), 100_000, wasm));
Expand Down Expand Up @@ -902,7 +901,6 @@ fn test_set_rent_code_and_hash() {
let (wasm, code_hash) = compile_module::<Test>(CODE_SET_RENT).unwrap();

ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
System::set_block_number(1);
Balances::deposit_creating(&ALICE, 1_000_000);
assert_ok!(Contracts::put_code(Origin::signed(ALICE), 100_000, wasm));

Expand Down Expand Up @@ -971,7 +969,6 @@ fn deduct_blocks() {
let (wasm, code_hash) = compile_module::<Test>(CODE_SET_RENT).unwrap();

ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
System::set_block_number(1);
// Create
Balances::deposit_creating(&ALICE, 1_000_000);
assert_ok!(Contracts::put_code(Origin::signed(ALICE), 100_000, wasm));
Expand Down Expand Up @@ -1066,7 +1063,6 @@ fn claim_surcharge(blocks: u64, trigger_call: impl Fn() -> bool, removes: bool)
let (wasm, code_hash) = compile_module::<Test>(CODE_SET_RENT).unwrap();

ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
System::set_block_number(1);
// Create
Balances::deposit_creating(&ALICE, 1_000_000);
assert_ok!(Contracts::put_code(Origin::signed(ALICE), 100_000, wasm));
Expand Down Expand Up @@ -1420,7 +1416,6 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage:
compile_module::<Test>(CODE_RESTORATION).unwrap();

ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
System::set_block_number(1);
Balances::deposit_creating(&ALICE, 1_000_000);
assert_ok!(Contracts::put_code(Origin::signed(ALICE), 100_000, restoration_wasm));
assert_ok!(Contracts::put_code(Origin::signed(ALICE), 100_000, set_rent_wasm));
Expand Down
4 changes: 3 additions & 1 deletion frame/democracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ fn new_test_ext() -> sp_io::TestExternalities {
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
}.assimilate_storage(&mut t).unwrap();
GenesisConfig::default().assimilate_storage(&mut t).unwrap();
sp_io::TestExternalities::new(t)
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}

type System = frame_system::Module<Test>;
Expand Down
1 change: 0 additions & 1 deletion frame/democracy/src/tests/cancellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use super::*;
#[test]
fn cancel_referendum_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
Expand Down
1 change: 0 additions & 1 deletion frame/democracy/src/tests/lock_voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ fn no_locks_without_conviction_should_work() {
#[test]
fn lock_voting_should_work_with_delegation() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
Expand Down
6 changes: 0 additions & 6 deletions frame/democracy/src/tests/preimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use super::*;
#[test]
fn missing_preimage_should_fail() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash(2),
Expand All @@ -40,7 +39,6 @@ fn missing_preimage_should_fail() {
#[test]
fn preimage_deposit_should_be_required_and_returned() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
// fee of 100 is too much.
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 100);
assert_noop!(
Expand Down Expand Up @@ -71,7 +69,6 @@ fn preimage_deposit_should_be_required_and_returned() {
#[test]
fn preimage_deposit_should_be_reapable_earlier_by_owner() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);
assert_ok!(Democracy::note_preimage(Origin::signed(6), set_balance_proposal(2)));

Expand All @@ -93,7 +90,6 @@ fn preimage_deposit_should_be_reapable_earlier_by_owner() {
#[test]
fn preimage_deposit_should_be_reapable() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
assert_noop!(
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2)),
Error::<Test>::PreimageMissing
Expand Down Expand Up @@ -122,7 +118,6 @@ fn preimage_deposit_should_be_reapable() {
#[test]
fn noting_imminent_preimage_for_free_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
PREIMAGE_BYTE_DEPOSIT.with(|v| *v.borrow_mut() = 1);

let r = Democracy::inject_referendum(
Expand Down Expand Up @@ -152,7 +147,6 @@ fn noting_imminent_preimage_for_free_should_work() {
#[test]
fn reaping_imminent_preimage_should_fail() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
let h = set_balance_proposal_hash_and_note(2);
let r = Democracy::inject_referendum(3, h, VoteThreshold::SuperMajorityApprove, 1);
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
Expand Down
6 changes: 0 additions & 6 deletions frame/democracy/src/tests/public_proposals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use super::*;
#[test]
fn backing_for_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
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));
Expand All @@ -34,7 +33,6 @@ fn backing_for_should_work() {
#[test]
fn deposit_for_proposals_should_be_taken() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
assert_ok!(propose_set_balance_and_note(1, 2, 5));
assert_ok!(Democracy::second(Origin::signed(2), 0));
assert_ok!(Democracy::second(Origin::signed(5), 0));
Expand All @@ -49,7 +47,6 @@ fn deposit_for_proposals_should_be_taken() {
#[test]
fn deposit_for_proposals_should_be_returned() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
assert_ok!(propose_set_balance_and_note(1, 2, 5));
assert_ok!(Democracy::second(Origin::signed(2), 0));
assert_ok!(Democracy::second(Origin::signed(5), 0));
Expand All @@ -65,23 +62,20 @@ fn deposit_for_proposals_should_be_returned() {
#[test]
fn proposal_with_deposit_below_minimum_should_not_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
assert_noop!(propose_set_balance(1, 2, 0), Error::<Test>::ValueLow);
});
}

#[test]
fn poor_proposer_should_not_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
assert_noop!(propose_set_balance(1, 2, 11), BalancesError::<Test, _>::InsufficientBalance);
});
}

#[test]
fn poor_seconder_should_not_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
assert_ok!(propose_set_balance_and_note(2, 2, 11));
assert_noop!(Democracy::second(Origin::signed(1), 0), BalancesError::<Test, _>::InsufficientBalance);
});
Expand Down
4 changes: 0 additions & 4 deletions frame/democracy/src/tests/scheduling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use super::*;
#[test]
fn simple_passing_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
Expand All @@ -39,7 +38,6 @@ fn simple_passing_should_work() {
#[test]
fn simple_failing_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
Expand All @@ -59,7 +57,6 @@ fn simple_failing_should_work() {
#[test]
fn ooo_inject_referendums_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
let r1 = Democracy::inject_referendum(
3,
set_balance_proposal_hash_and_note(3),
Expand Down Expand Up @@ -90,7 +87,6 @@ fn ooo_inject_referendums_should_work() {
#[test]
fn delayed_enactment_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
Expand Down
3 changes: 0 additions & 3 deletions frame/democracy/src/tests/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ fn single_proposal_should_work() {
#[test]
fn controversial_voting_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
Expand All @@ -126,7 +125,6 @@ fn controversial_voting_should_work() {
#[test]
fn controversial_low_turnout_voting_should_work() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
Expand All @@ -151,7 +149,6 @@ fn passing_low_turnout_voting_should_work() {
assert_eq!(Balances::free_balance(42), 0);
assert_eq!(Balances::total_issuance(), 210);

System::set_block_number(1);
let r = Democracy::inject_referendum(
2,
set_balance_proposal_hash_and_note(2),
Expand Down
Loading