mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-19 19:15:41 +00:00
Expose commit in externalities.
Also refactor `TestExternalities` into a single place.
This commit is contained in:
@@ -114,9 +114,9 @@ pub mod internal {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use runtime_std::{with_externalities, twox_128};
|
||||
use runtime_std::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use support::{one, two, TestExternalities, with_env};
|
||||
use support::{one, two, with_env};
|
||||
use primitives::{AccountID, InternalFunction};
|
||||
use runtime::{staking, session};
|
||||
|
||||
|
||||
@@ -132,9 +132,9 @@ mod tests {
|
||||
use super::public::*;
|
||||
use super::privileged::*;
|
||||
use super::internal::*;
|
||||
use runtime_std::{with_externalities, twox_128};
|
||||
use runtime_std::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use support::{one, two, TestExternalities, with_env};
|
||||
use support::{one, two, with_env};
|
||||
use primitives::AccountID;
|
||||
use runtime::{consensus, session};
|
||||
|
||||
|
||||
@@ -206,9 +206,9 @@ mod tests {
|
||||
use super::public::*;
|
||||
use super::privileged::*;
|
||||
|
||||
use runtime_std::{with_externalities, twox_128};
|
||||
use runtime_std::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{KeyedVec, Joiner};
|
||||
use support::{one, two, TestExternalities, with_env};
|
||||
use support::{one, two, with_env};
|
||||
use primitives::AccountID;
|
||||
use runtime::{staking, session};
|
||||
|
||||
|
||||
@@ -127,9 +127,9 @@ mod tests {
|
||||
use super::*;
|
||||
use super::internal::*;
|
||||
|
||||
use runtime_std::{with_externalities, twox_128};
|
||||
use runtime_std::{with_externalities, twox_128, TestExternalities};
|
||||
use codec::{Joiner, KeyedVec, Slicable};
|
||||
use support::{StaticHexInto, TestExternalities, HexDisplay, one, two};
|
||||
use support::{StaticHexInto, HexDisplay, one, two};
|
||||
use primitives::{UncheckedTransaction, Transaction, Function};
|
||||
use runtime::staking;
|
||||
|
||||
|
||||
@@ -42,10 +42,9 @@ mod tests {
|
||||
use super::*;
|
||||
use super::public::*;
|
||||
|
||||
use runtime_std::{with_externalities, twox_128};
|
||||
use runtime_std::{with_externalities, twox_128, TestExternalities};
|
||||
use runtime::timestamp;
|
||||
use codec::{Joiner, KeyedVec};
|
||||
use support::TestExternalities;
|
||||
|
||||
#[test]
|
||||
fn timestamp_works() {
|
||||
|
||||
@@ -31,4 +31,4 @@ pub use self::hashable::Hashable;
|
||||
#[cfg(feature = "with-std")]
|
||||
pub use self::statichex::{StaticHexConversion, StaticHexInto};
|
||||
#[cfg(feature = "with-std")]
|
||||
pub use self::testing::{AsBytesRef, HexDisplay, TestExternalities, one, two};
|
||||
pub use self::testing::{AsBytesRef, HexDisplay, one, two};
|
||||
|
||||
@@ -146,9 +146,8 @@ pub trait StorageVec {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
use runtime_std::with_externalities;
|
||||
use support::{TestExternalities, HexDisplay};
|
||||
use runtime_std::{storage, twox_128};
|
||||
use support::HexDisplay;
|
||||
use runtime_std::{storage, twox_128, TestExternalities, with_externalities};
|
||||
|
||||
#[test]
|
||||
fn integers_can_be_stored() {
|
||||
|
||||
@@ -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 ),*) => (
|
||||
|
||||
Reference in New Issue
Block a user