mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 10:01:17 +00:00
Test for overlaying and storage root calculation.
This commit is contained in:
@@ -67,6 +67,18 @@ pub struct InMemory {
|
||||
inner: MemoryState, // keeps all the state in memory.
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl InMemory {
|
||||
/// Create a new instance from a given storage map.
|
||||
pub fn from(storage: ::std::collections::HashMap<Vec<u8>, Vec<u8>>) -> Self {
|
||||
InMemory {
|
||||
inner: MemoryState {
|
||||
storage
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Backend for InMemory {
|
||||
type Error = Void;
|
||||
|
||||
|
||||
@@ -218,7 +218,9 @@ pub fn execute<B: backend::Backend, Exec: CodeExecutor>(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{OverlayedChanges, Externalities, TestExternalities};
|
||||
use super::*;
|
||||
use super::backend::InMemory;
|
||||
use super::ext::Ext;
|
||||
|
||||
#[test]
|
||||
fn overlayed_storage_works() {
|
||||
@@ -264,4 +266,34 @@ mod tests {
|
||||
ext.set_storage(b"con:aut:\x01\0\0\0".to_vec(), b"second".to_vec());
|
||||
assert_eq!(ext.authorities(), Ok(vec![&b"first"[..], &b"second"[..]]));
|
||||
}
|
||||
|
||||
macro_rules! map {
|
||||
($( $name:expr => $value:expr ),*) => (
|
||||
vec![ $( ( $name, $value ) ),* ].into_iter().collect()
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overlayed_storage_root_works() {
|
||||
let mut backend = InMemory::from(map![
|
||||
b"doe".to_vec() => b"reindeer".to_vec(),
|
||||
b"dog".to_vec() => b"puppyXXX".to_vec(),
|
||||
b"dogglesworth".to_vec() => b"catXXX".to_vec()
|
||||
]);
|
||||
let mut overlay = OverlayedChanges {
|
||||
committed: MemoryState { storage: map![
|
||||
b"dog".to_vec() => b"puppy".to_vec(),
|
||||
b"dogglesworth".to_vec() => b"catYYY".to_vec()
|
||||
], },
|
||||
prospective: MemoryState { storage: map![
|
||||
b"dogglesworth".to_vec() => b"cat".to_vec()
|
||||
], },
|
||||
};
|
||||
let ext = Ext {
|
||||
backend: &mut backend,
|
||||
overlay: &mut overlay,
|
||||
};
|
||||
const ROOT: [u8; 32] = hex!("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3");
|
||||
assert_eq!(ext.storage_root(), ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user