Make use of child storage for testExternalities and basicExternalities (#3009)

* impl test using both storage and child_storage

* few fixes

* remove unused code

* impl PartialEq with children keys

* fmt

* implementation of basic with children + rename new

* assert and test

* no panic in runtime

* address comments

* fix
This commit is contained in:
thiolliere
2019-07-09 21:07:58 +02:00
committed by Gavin Wood
parent 6639ab339a
commit d00a2b28ac
12 changed files with 242 additions and 161 deletions
+25 -2
View File
@@ -435,9 +435,32 @@ pub type ChildrenStorageOverlay = HashMap<Vec<u8>, StorageOverlay>;
pub fn with_storage<R, F: FnOnce() -> R>(storage: &mut StorageOverlay, f: F) -> R {
let mut alt_storage = Default::default();
rstd::mem::swap(&mut alt_storage, storage);
let mut ext: BasicExternalities = alt_storage.into();
let mut ext = BasicExternalities::new(alt_storage);
let r = ext::using(&mut ext, f);
*storage = ext.into();
*storage = ext.into_storages().0;
r
}
/// Execute the given closure with global functions available whose functionality routes into
/// externalities that draw from and populate `storage` and `children_storage`.
/// Forwards the value that the closure returns.
pub fn with_storage_and_children<R, F: FnOnce() -> R>(
storage: &mut StorageOverlay,
children_storage: &mut ChildrenStorageOverlay,
f: F
) -> R {
let mut alt_storage = Default::default();
let mut alt_children_storage = Default::default();
rstd::mem::swap(&mut alt_storage, storage);
rstd::mem::swap(&mut alt_children_storage, children_storage);
let mut ext = BasicExternalities::new_with_children(alt_storage, alt_children_storage);
let r = ext::using(&mut ext, f);
let storage_tuple = ext.into_storages();
*storage = storage_tuple.0;
*children_storage = storage_tuple.1;
r
}