Expose commit in externalities.

Also refactor `TestExternalities` into a single place.
This commit is contained in:
Gav
2018-01-30 18:29:26 +01:00
parent 8e554129ec
commit e2a2936408
14 changed files with 77 additions and 74 deletions
@@ -16,30 +16,9 @@
//! Testing helpers.
use std::collections::HashMap;
use runtime_std::{Externalities, ExternalitiesError};
use primitives::AccountID;
use super::statichex::StaticHexInto;
#[derive(Debug, Default)]
/// Simple externaties implementation.
pub struct TestExternalities {
/// The storage map.
pub storage: HashMap<Vec<u8>, Vec<u8>>,
}
impl Externalities for TestExternalities {
fn storage(&self, key: &[u8]) -> Result<&[u8], ExternalitiesError> {
Ok(self.storage.get(&key.to_vec()).map_or(&[] as &[u8], Vec::as_slice))
}
fn set_storage(&mut self, key: Vec<u8>, value: Vec<u8>) {
self.storage.insert(key, value);
}
fn chain_id(&self) -> u64 { 42 }
}
#[macro_export]
macro_rules! map {
($( $name:expr => $value:expr ),*) => (