Add execute_with to TestExternalities (#3793)

This function executes the given closure in a context where the test
externalities are set. This makes the srml tests easier to write, as the
test externalities need to be created anyway.
This commit is contained in:
Bastian Köcher
2019-10-10 15:01:30 +02:00
committed by GitHub
parent 34c7338211
commit 4dbc9265ee
44 changed files with 2369 additions and 2645 deletions
+2 -3
View File
@@ -25,8 +25,7 @@ use support::{
};
use primitives::H256;
use sr_primitives::{
Perbill, BuildStorage, set_and_run_with_externalities, testing::Header,
traits::{BlakeTwo256, IdentityLookup, Block as BlockT},
Perbill, BuildStorage, testing::Header, traits::{BlakeTwo256, IdentityLookup, Block as BlockT},
};
use crate as elections;
@@ -283,7 +282,7 @@ pub(crate) fn locks(who: &u64) -> Vec<u64> {
pub(crate) fn new_test_ext_with_candidate_holes() -> runtime_io::TestExternalities {
let mut t = ExtBuilder::default().build();
set_and_run_with_externalities(&mut t, || {
t.execute_with(|| {
<elections::Candidates<Test>>::put(vec![0, 0, 1]);
elections::CandidateCount::put(1);
<elections::RegisterInfoOf<Test>>::insert(1, (0, 2));