mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 01:27:56 +00:00
Child trie api changes BREAKING (#4857)
Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
@@ -123,11 +123,12 @@ impl substrate_test_client::GenesisInit for GenesisParameters {
|
||||
|
||||
let mut storage = self.genesis_config().genesis_map();
|
||||
|
||||
let child_roots = storage.children.iter().map(|(sk, child_content)| {
|
||||
let child_roots = storage.children_default.iter().map(|(_sk, child_content)| {
|
||||
let state_root = <<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
child_content.data.clone().into_iter().collect()
|
||||
);
|
||||
(sk.clone(), state_root.encode())
|
||||
let prefixed_storage_key = child_content.child_info.prefixed_storage_key();
|
||||
(prefixed_storage_key.into_inner(), state_root.encode())
|
||||
});
|
||||
let state_root = <<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
storage.top.clone().into_iter().chain(child_roots).collect()
|
||||
@@ -192,22 +193,21 @@ pub trait TestClientBuilderExt<B>: Sized {
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the key is empty.
|
||||
fn add_extra_child_storage<SK: Into<Vec<u8>>, K: Into<Vec<u8>>, V: Into<Vec<u8>>>(
|
||||
fn add_extra_child_storage<K: Into<Vec<u8>>, V: Into<Vec<u8>>>(
|
||||
mut self,
|
||||
storage_key: SK,
|
||||
child_info: ChildInfo,
|
||||
child_info: &ChildInfo,
|
||||
key: K,
|
||||
value: V,
|
||||
) -> Self {
|
||||
let storage_key = storage_key.into();
|
||||
let storage_key = child_info.storage_key().to_vec();
|
||||
let key = key.into();
|
||||
assert!(!storage_key.is_empty());
|
||||
assert!(!key.is_empty());
|
||||
self.genesis_init_mut().extra_storage.children
|
||||
self.genesis_init_mut().extra_storage.children_default
|
||||
.entry(storage_key)
|
||||
.or_insert_with(|| StorageChild {
|
||||
data: Default::default(),
|
||||
child_info: child_info.to_owned(),
|
||||
child_info: child_info.clone(),
|
||||
}).data.insert(key, value.into());
|
||||
self
|
||||
}
|
||||
@@ -311,7 +311,10 @@ impl Fetcher<substrate_test_runtime::Block> for LightFetcher {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn remote_read_child(&self, _: RemoteReadChildRequest<substrate_test_runtime::Header>) -> Self::RemoteReadResult {
|
||||
fn remote_read_child(
|
||||
&self,
|
||||
_: RemoteReadChildRequest<substrate_test_runtime::Header>,
|
||||
) -> Self::RemoteReadResult {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ impl GenesisConfig {
|
||||
map.extend(self.extra_storage.top.clone().into_iter());
|
||||
|
||||
// Assimilate the system genesis config.
|
||||
let mut storage = Storage { top: map, children: self.extra_storage.children.clone()};
|
||||
let mut storage = Storage { top: map, children_default: self.extra_storage.children_default.clone()};
|
||||
let mut config = system::GenesisConfig::default();
|
||||
config.authorities = self.authorities.clone();
|
||||
config.assimilate_storage(&mut storage).expect("Adding `system::GensisConfig` to the genesis");
|
||||
@@ -85,7 +85,7 @@ impl GenesisConfig {
|
||||
pub fn insert_genesis_block(
|
||||
storage: &mut Storage,
|
||||
) -> sp_core::hash::H256 {
|
||||
let child_roots = storage.children.iter().map(|(sk, child_content)| {
|
||||
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
||||
let state_root = <<<crate::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
child_content.data.clone().into_iter().collect(),
|
||||
);
|
||||
|
||||
@@ -50,7 +50,6 @@ use sp_version::NativeVersion;
|
||||
use frame_support::{impl_outer_origin, parameter_types, weights::{Weight, RuntimeDbWeight}};
|
||||
use sp_inherents::{CheckInherentsResult, InherentData};
|
||||
use cfg_if::cfg_if;
|
||||
use sp_core::storage::ChildType;
|
||||
|
||||
// Ensure Babe and Aura use the same crypto to simplify things a bit.
|
||||
pub use sp_consensus_babe::{AuthorityId, SlotNumber};
|
||||
@@ -923,22 +922,17 @@ fn test_read_storage() {
|
||||
}
|
||||
|
||||
fn test_read_child_storage() {
|
||||
const CHILD_KEY: &[u8] = b":child_storage:default:read_child_storage";
|
||||
const UNIQUE_ID: &[u8] = b":unique_id";
|
||||
const STORAGE_KEY: &[u8] = b"unique_id_1";
|
||||
const KEY: &[u8] = b":read_child_storage";
|
||||
sp_io::storage::child_set(
|
||||
CHILD_KEY,
|
||||
UNIQUE_ID,
|
||||
ChildType::CryptoUniqueId as u32,
|
||||
sp_io::default_child_storage::set(
|
||||
STORAGE_KEY,
|
||||
KEY,
|
||||
b"test",
|
||||
);
|
||||
|
||||
let mut v = [0u8; 4];
|
||||
let r = sp_io::storage::child_read(
|
||||
CHILD_KEY,
|
||||
UNIQUE_ID,
|
||||
ChildType::CryptoUniqueId as u32,
|
||||
let r = sp_io::default_child_storage::read(
|
||||
STORAGE_KEY,
|
||||
KEY,
|
||||
&mut v,
|
||||
0,
|
||||
@@ -947,10 +941,8 @@ fn test_read_child_storage() {
|
||||
assert_eq!(&v, b"test");
|
||||
|
||||
let mut v = [0u8; 4];
|
||||
let r = sp_io::storage::child_read(
|
||||
CHILD_KEY,
|
||||
UNIQUE_ID,
|
||||
ChildType::CryptoUniqueId as u32,
|
||||
let r = sp_io::default_child_storage::read(
|
||||
STORAGE_KEY,
|
||||
KEY,
|
||||
&mut v,
|
||||
8,
|
||||
|
||||
@@ -373,7 +373,7 @@ mod tests {
|
||||
vec![111u8, 0, 0, 0, 0, 0, 0, 0]
|
||||
}
|
||||
],
|
||||
children: map![],
|
||||
children_default: map![],
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user