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
+3 -5
View File
@@ -313,9 +313,7 @@ impl<T: Trait, D: AsRef<[u8]>> support::traits::KeyOwnerProofSystem<(KeyTypeId,
mod tests {
use super::*;
use primitives::crypto::key_types::DUMMY;
use sr_primitives::{
traits::OnInitialize, testing::UintAuthorityId, set_and_run_with_externalities,
};
use sr_primitives::{traits::OnInitialize, testing::UintAuthorityId};
use crate::mock::{
NEXT_VALIDATORS, force_new_session,
set_next_validators, Test, System, Session,
@@ -336,7 +334,7 @@ mod tests {
#[test]
fn generated_proof_is_good() {
set_and_run_with_externalities(&mut new_test_ext(), || {
new_test_ext().execute_with(|| {
set_next_validators(vec![1, 2]);
force_new_session();
@@ -377,7 +375,7 @@ mod tests {
#[test]
fn prune_up_to_works() {
set_and_run_with_externalities(&mut new_test_ext(), || {
new_test_ext().execute_with(|| {
for i in 1..101u64 {
set_next_validators(vec![i]);
force_new_session();