Prevent events from being emitted during genesis construction (#5463)

* Don't populate runtime events in genesis

* typo

* Change to block zero

* Fix vesting tests

* Update frame/system/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/system/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Add test

* Fix test

* Fix contract tests

* Fix phragmen tests

* Fix Generic Assets Tests

* Fix offences tests

* Fix im-online

* fix recovery

* Fix utility tests

* Shorter

* Use ext

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Shawn Tabrizi
2020-03-31 15:57:08 +02:00
committed by GitHub
parent b472d60a52
commit 2e76e2a74d
22 changed files with 72 additions and 109 deletions
@@ -181,9 +181,8 @@ fn submitted_transaction_should_be_valid() {
priority: 2_411_002_000_000,
requires: vec![],
provides: vec![(address, 0).encode()],
longevity: 127,
longevity: 128,
propagate: true,
});
});
}
+4 -15
View File
@@ -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());
});
@@ -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);
@@ -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)));
@@ -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)));
@@ -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;
@@ -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;
@@ -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;
@@ -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())),
@@ -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())));
@@ -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;
@@ -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())));
@@ -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())));
@@ -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())));
+3 -1
View File
@@ -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
}
}
+3 -1
View File
@@ -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>;
@@ -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),
@@ -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),
@@ -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),
@@ -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!(
@@ -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)));
@@ -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
@@ -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(
@@ -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)));
@@ -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));
@@ -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));
@@ -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));
@@ -65,7 +62,6 @@ 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);
});
}
@@ -73,7 +69,6 @@ fn proposal_with_deposit_below_minimum_should_not_work() {
#[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);
});
}
@@ -81,7 +76,6 @@ fn poor_proposer_should_not_work() {
#[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);
});
@@ -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),
@@ -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),
@@ -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),
@@ -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),
@@ -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),
@@ -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),
@@ -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),
+13 -16
View File
@@ -1040,7 +1040,7 @@ mod tests {
VOTING_BOND.with(|v| *v.borrow_mut() = self.voter_bond);
TERM_DURATION.with(|v| *v.borrow_mut() = self.term_duration);
DESIRED_RUNNERS_UP.with(|v| *v.borrow_mut() = self.desired_runners_up);
GenesisConfig {
let mut ext: sp_io::TestExternalities = GenesisConfig {
pallet_balances: Some(pallet_balances::GenesisConfig::<Test>{
balances: vec![
(1, 10 * self.balance_factor),
@@ -1051,7 +1051,9 @@ mod tests {
(6, 60 * self.balance_factor)
],
}),
}.build_storage().unwrap().into()
}.build_storage().unwrap().into();
ext.execute_with(|| System::set_block_number(1));
ext
}
}
@@ -1072,7 +1074,6 @@ mod tests {
#[test]
fn params_should_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_eq!(Elections::desired_members(), 2);
assert_eq!(Elections::term_duration(), 5);
assert_eq!(Elections::election_rounds(), 0);
@@ -1096,7 +1097,6 @@ mod tests {
.build()
.execute_with(||
{
System::set_block_number(1);
assert_eq!(Elections::term_duration(), 0);
assert_eq!(Elections::desired_members(), 2);
assert_eq!(Elections::election_rounds(), 0);
@@ -1537,10 +1537,9 @@ mod tests {
assert_eq!(balances(&5), (45, 5));
assert_ok!(Elections::report_defunct_voter(Origin::signed(5), 3));
assert_eq!(
System::events()[7].event,
Event::elections(RawEvent::VoterReported(3, 5, true))
);
assert!(System::events().iter().any(|event| {
event.event == Event::elections(RawEvent::VoterReported(3, 5, true))
}));
assert_eq!(balances(&3), (28, 0));
assert_eq!(balances(&5), (47, 5));
@@ -1566,10 +1565,9 @@ mod tests {
assert_eq!(balances(&5), (45, 5));
assert_ok!(Elections::report_defunct_voter(Origin::signed(5), 4));
assert_eq!(
System::events()[7].event,
Event::elections(RawEvent::VoterReported(4, 5, false))
);
assert!(System::events().iter().any(|event| {
event.event == Event::elections(RawEvent::VoterReported(4, 5, false))
}));
assert_eq!(balances(&4), (35, 5));
assert_eq!(balances(&5), (45, 3));
@@ -1977,10 +1975,9 @@ mod tests {
// 5 is an outgoing loser. will also get slashed.
assert_eq!(balances(&5), (45, 2));
assert_eq!(
System::events()[6].event,
Event::elections(RawEvent::NewTerm(vec![(4, 40), (5, 50)])),
);
assert!(System::events().iter().any(|event| {
event.event == Event::elections(RawEvent::NewTerm(vec![(4, 40), (5, 50)]))
}));
})
}
+4 -2
View File
@@ -208,7 +208,7 @@ impl ExtBuilder {
VOTING_FEE.with(|v| *v.borrow_mut() = self.voting_fee);
PRESENT_SLASH_PER_VOTER.with(|v| *v.borrow_mut() = self.bad_presentation_punishment);
DECAY_RATIO.with(|v| *v.borrow_mut() = self.decay_ratio);
GenesisConfig {
let mut ext: sp_io::TestExternalities = GenesisConfig {
pallet_balances: Some(pallet_balances::GenesisConfig::<Test>{
balances: vec![
(1, 10 * self.balance_factor),
@@ -225,7 +225,9 @@ impl ExtBuilder {
presentation_duration: 2,
term_duration: 5,
}),
}.build_storage().unwrap().into()
}.build_storage().unwrap().into();
ext.execute_with(|| System::set_block_number(1));
ext
}
}
-24
View File
@@ -26,7 +26,6 @@ use frame_support::{assert_ok, assert_err, assert_noop};
#[test]
fn params_should_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_eq!(Elections::next_vote_from(1), 4);
assert_eq!(Elections::next_vote_from(4), 4);
assert_eq!(Elections::next_vote_from(5), 8);
@@ -408,8 +407,6 @@ fn voting_locking_stake_and_reserving_bond_works() {
#[test]
fn voting_without_any_candidate_count_should_not_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_eq!(Elections::candidates().len(), 0);
assert_noop!(
@@ -422,8 +419,6 @@ fn voting_without_any_candidate_count_should_not_work() {
#[test]
fn voting_setting_an_approval_vote_count_more_than_candidate_count_should_not_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 0));
assert_eq!(Elections::candidates().len(), 1);
@@ -437,8 +432,6 @@ fn voting_setting_an_approval_vote_count_more_than_candidate_count_should_not_wo
#[test]
fn voting_resubmitting_approvals_should_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 0));
assert_ok!(Elections::set_approvals(Origin::signed(4), vec![true], 0, 0, 40));
@@ -456,8 +449,6 @@ fn voting_resubmitting_approvals_should_work() {
#[test]
fn voting_retracting_voter_should_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 0));
assert_eq!(Elections::candidates().len(), 1);
@@ -501,7 +492,6 @@ fn voting_retracting_voter_should_work() {
#[test]
fn voting_invalid_retraction_index_should_not_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_ok!(Elections::submit_candidacy(Origin::signed(3), 0));
assert_ok!(Elections::set_approvals(Origin::signed(1), vec![true], 0, 0, 10));
@@ -514,7 +504,6 @@ fn voting_invalid_retraction_index_should_not_work() {
#[test]
fn voting_overflow_retraction_index_should_not_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_ok!(Elections::submit_candidacy(Origin::signed(3), 0));
assert_ok!(Elections::set_approvals(Origin::signed(1), vec![true], 0, 0, 10));
@@ -525,7 +514,6 @@ fn voting_overflow_retraction_index_should_not_work() {
#[test]
fn voting_non_voter_retraction_should_not_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_ok!(Elections::submit_candidacy(Origin::signed(3), 0));
assert_ok!(Elections::set_approvals(Origin::signed(1), vec![true], 0, 0, 10));
@@ -740,7 +728,6 @@ fn retracting_inactive_voter_by_nonvoter_should_not_work() {
#[test]
fn candidacy_simple_candidate_submission_should_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_eq!(Elections::candidates(), Vec::<u64>::new());
assert_eq!(Elections::candidate_reg_info(1), None);
assert_eq!(Elections::candidate_reg_info(2), None);
@@ -768,7 +755,6 @@ fn candidacy_submission_using_free_slot_should_work() {
let mut t = new_test_ext_with_candidate_holes();
t.execute_with(|| {
System::set_block_number(1);
assert_eq!(Elections::candidates(), vec![0, 0, 1]);
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 1));
@@ -784,7 +770,6 @@ fn candidacy_submission_using_alternative_free_slot_should_work() {
let mut t = new_test_ext_with_candidate_holes();
t.execute_with(|| {
System::set_block_number(1);
assert_eq!(Elections::candidates(), vec![0, 0, 1]);
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
@@ -800,7 +785,6 @@ fn candidacy_submission_not_using_free_slot_should_not_work() {
let mut t = new_test_ext_with_candidate_holes();
t.execute_with(|| {
System::set_block_number(1);
assert_noop!(
Elections::submit_candidacy(Origin::signed(4), 3),
Error::<Test>::InvalidCandidateSlot
@@ -811,7 +795,6 @@ fn candidacy_submission_not_using_free_slot_should_not_work() {
#[test]
fn candidacy_bad_candidate_slot_submission_should_not_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_eq!(Elections::candidates(), Vec::<u64>::new());
assert_noop!(
Elections::submit_candidacy(Origin::signed(1), 1),
@@ -823,7 +806,6 @@ fn candidacy_bad_candidate_slot_submission_should_not_work() {
#[test]
fn candidacy_non_free_candidate_slot_submission_should_not_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_eq!(Elections::candidates(), Vec::<u64>::new());
assert_ok!(Elections::submit_candidacy(Origin::signed(1), 0));
assert_eq!(Elections::candidates(), vec![1]);
@@ -837,7 +819,6 @@ fn candidacy_non_free_candidate_slot_submission_should_not_work() {
#[test]
fn candidacy_dupe_candidate_submission_should_not_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_eq!(Elections::candidates(), Vec::<u64>::new());
assert_ok!(Elections::submit_candidacy(Origin::signed(1), 0));
assert_eq!(Elections::candidates(), vec![1]);
@@ -851,7 +832,6 @@ fn candidacy_dupe_candidate_submission_should_not_work() {
#[test]
fn candidacy_poor_candidate_submission_should_not_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_eq!(Elections::candidates(), Vec::<u64>::new());
assert_noop!(
Elections::submit_candidacy(Origin::signed(7), 0),
@@ -863,8 +843,6 @@ fn candidacy_poor_candidate_submission_should_not_work() {
#[test]
fn election_voting_should_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 0));
assert_ok!(Elections::set_approvals(Origin::signed(1), vec![true], 0, 0, 10));
@@ -892,8 +870,6 @@ fn election_voting_should_work() {
#[test]
fn election_proxy_voting_should_work() {
ExtBuilder::default().build().execute_with(|| {
System::set_block_number(1);
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 0));
<Proxy<Test>>::insert(11, 1);
+10 -9
View File
@@ -127,16 +127,17 @@ impl ExtBuilder {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
GenesisConfig::<Test> {
assets: vec![self.asset_id],
endowed_accounts: self.accounts,
initial_balance: self.initial_balance,
next_asset_id: self.next_asset_id,
staking_asset_id: 16000,
spending_asset_id: 16001,
}
.assimilate_storage(&mut t).unwrap();
assets: vec![self.asset_id],
endowed_accounts: self.accounts,
initial_balance: self.initial_balance,
next_asset_id: self.next_asset_id,
staking_asset_id: 16000,
spending_asset_id: 16001,
}.assimilate_storage(&mut t).unwrap();
t.into()
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}
}
+1 -1
View File
@@ -175,7 +175,7 @@ pub type System = frame_system::Module<Runtime>;
pub type Session = pallet_session::Module<Runtime>;
pub fn advance_session() {
let now = System::block_number();
let now = System::block_number().max(1);
System::set_block_number(now + 1);
Session::rotate_session();
assert_eq!(Session::current_index(), (now / Period::get()) as u32);
+3 -1
View File
@@ -128,7 +128,9 @@ impl_outer_event! {
pub fn new_test_ext() -> sp_io::TestExternalities {
let t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
t.into()
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}
/// Offences module.
+2 -2
View File
@@ -240,7 +240,7 @@ fn initiate_recovery_works() {
assert_eq!(Balances::reserved_balance(1), 10);
// Recovery status object is created correctly
let recovery_status = ActiveRecovery {
created: 1,
created: 0,
deposit: 10,
friends: vec![],
};
@@ -288,7 +288,7 @@ fn vouch_recovery_works() {
assert_ok!(Recovery::vouch_recovery(Origin::signed(3), 5, 1));
// Final recovery status object is updated correctly
let recovery_status = ActiveRecovery {
created: 1,
created: 0,
deposit: 10,
friends: vec![2, 3, 4],
};
+1
View File
@@ -489,6 +489,7 @@ impl ExtBuilder {
// This must be ensured by having `timestamp::on_initialize` called before
// `staking::on_initialize`
ext.execute_with(|| {
System::set_block_number(1);
Timestamp::set_timestamp(INIT_TIMESTAMP);
});
-1
View File
@@ -1706,7 +1706,6 @@ fn new_era_elects_correct_number_of_validators() {
assert_eq!(Staking::validator_count(), 1);
assert_eq!(validator_controllers().len(), 1);
System::set_block_number(1);
Session::on_initialize(System::block_number());
assert_eq!(validator_controllers().len(), 1);
+21 -3
View File
@@ -366,7 +366,7 @@ decl_storage! {
ExtrinsicData get(fn extrinsic_data): map hasher(twox_64_concat) u32 => Vec<u8>;
/// The current block number being processed. Set by `execute_block`.
Number get(fn block_number) build(|_| 1.into()): T::BlockNumber;
Number get(fn block_number): T::BlockNumber;
/// Hash of the previous block.
ParentHash get(fn parent_hash) build(|_| hash69()): T::Hash;
@@ -749,6 +749,10 @@ impl<T: Trait> Module<T> {
/// This will update storage entries that correspond to the specified topics.
/// It is expected that light-clients could subscribe to this topics.
pub fn deposit_event_indexed(topics: &[T::Hash], event: T::Event) {
let block_number = Self::block_number();
// Don't populate events on genesis.
if block_number.is_zero() { return }
let phase = ExecutionPhase::get().unwrap_or_default();
let event = EventRecord {
phase,
@@ -781,10 +785,9 @@ impl<T: Trait> Module<T> {
return;
}
let block_no = Self::block_number();
for topic in topics {
// The same applies here.
if <EventTopics<T>>::append(topic, &[(block_no, event_idx)]).is_err() {
if <EventTopics<T>>::append(topic, &[(block_number, event_idx)]).is_err() {
return;
}
}
@@ -2041,6 +2044,7 @@ mod tests {
let mut ext = new_test_ext();
ext.register_extension(sp_core::traits::CallInWasmExt::new(executor));
ext.execute_with(|| {
System::set_block_number(1);
System::set_code(
RawOrigin::Root.into(),
substrate_test_runtime_client::runtime::WASM_BINARY.to_vec(),
@@ -2068,4 +2072,18 @@ mod tests {
).unwrap();
});
}
#[test]
fn events_not_emitted_during_genesis() {
new_test_ext().execute_with(|| {
// Block Number is zero at genesis
assert!(System::block_number().is_zero());
System::on_created_account(Default::default());
assert!(System::events().is_empty());
// Events will be emitted starting on block 1
System::set_block_number(1);
System::on_created_account(Default::default());
assert!(System::events().len() == 1);
});
}
}
+3 -1
View File
@@ -661,7 +661,9 @@ mod tests {
pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10), (2, 10), (3, 10), (4, 10), (5, 10)],
}.assimilate_storage(&mut t).unwrap();
t.into()
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}
fn last_event() -> TestEvent {
+3 -9
View File
@@ -452,7 +452,9 @@ mod tests {
(12, 10, 20, 5 * self.existential_deposit)
],
}.assimilate_storage(&mut t).unwrap();
t.into()
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}
}
@@ -462,7 +464,6 @@ mod tests {
.existential_deposit(256)
.build()
.execute_with(|| {
assert_eq!(System::block_number(), 1);
let user1_free_balance = Balances::free_balance(&1);
let user2_free_balance = Balances::free_balance(&2);
let user12_free_balance = Balances::free_balance(&12);
@@ -521,7 +522,6 @@ mod tests {
.existential_deposit(10)
.build()
.execute_with(|| {
assert_eq!(System::block_number(), 1);
let user1_free_balance = Balances::free_balance(&1);
assert_eq!(user1_free_balance, 100); // Account 1 has free balance
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
@@ -539,7 +539,6 @@ mod tests {
.existential_deposit(10)
.build()
.execute_with(|| {
assert_eq!(System::block_number(), 1);
let user1_free_balance = Balances::free_balance(&1);
assert_eq!(user1_free_balance, 100); // Account 1 has free balance
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
@@ -555,7 +554,6 @@ mod tests {
.existential_deposit(10)
.build()
.execute_with(|| {
assert_eq!(System::block_number(), 1);
let user1_free_balance = Balances::free_balance(&1);
assert_eq!(user1_free_balance, 100); // Account 1 has free balance
// Account 1 has only 5 units vested at block 1 (plus 50 unvested)
@@ -571,7 +569,6 @@ mod tests {
.existential_deposit(10)
.build()
.execute_with(|| {
assert_eq!(System::block_number(), 1);
assert_ok!(Balances::transfer(Some(3).into(), 1, 100));
assert_ok!(Balances::transfer(Some(3).into(), 2, 100));
@@ -599,7 +596,6 @@ mod tests {
.existential_deposit(256)
.build()
.execute_with(|| {
assert_eq!(System::block_number(), 1);
let user12_free_balance = Balances::free_balance(&12);
assert_eq!(user12_free_balance, 2560); // Account 12 has free balance
@@ -625,7 +621,6 @@ mod tests {
.existential_deposit(256)
.build()
.execute_with(|| {
assert_eq!(System::block_number(), 1);
let user3_free_balance = Balances::free_balance(&3);
let user4_free_balance = Balances::free_balance(&4);
assert_eq!(user3_free_balance, 256 * 30);
@@ -669,7 +664,6 @@ mod tests {
.existential_deposit(256)
.build()
.execute_with(|| {
assert_eq!(System::block_number(), 1);
let user2_free_balance = Balances::free_balance(&2);
let user4_free_balance = Balances::free_balance(&4);
assert_eq!(user2_free_balance, 256 * 20);