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
+4 -5
View File
@@ -414,8 +414,7 @@ mod tests {
use super::*;
use primitives::H256;
use sr_primitives::{
set_and_run_with_externalities, traits::{BlakeTwo256, IdentityLookup}, testing::Header,
generic::DigestItem, Perbill,
traits::{BlakeTwo256, IdentityLookup}, testing::Header, generic::DigestItem, Perbill,
};
use support::{parameter_types, impl_outer_origin, ConsensusEngineId};
@@ -542,7 +541,7 @@ mod tests {
#[test]
fn prune_old_uncles_works() {
use UncleEntryItem::*;
set_and_run_with_externalities(&mut new_test_ext(), || {
new_test_ext().execute_with(|| {
let hash = Default::default();
let author = Default::default();
let uncles = vec![
@@ -561,7 +560,7 @@ mod tests {
#[test]
fn rejects_bad_uncles() {
set_and_run_with_externalities(&mut new_test_ext(), || {
new_test_ext().execute_with(|| {
let author_a = 69;
struct CanonChain {
@@ -674,7 +673,7 @@ mod tests {
#[test]
fn sets_author_lazily() {
set_and_run_with_externalities(&mut new_test_ext(), || {
new_test_ext().execute_with(|| {
let author = 42;
let mut header = seal_header(
create_header(1, Default::default(), [1; 32].into()),