mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Add childstate_getStorageEntries RPC (#9459)
* Add storage query functions for multiple keys fixes #9203 * Query all keys in one request and add more tests * Make it compatible with stable release channel * Update to new futures * Update client/rpc/src/state/state_full.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/rpc/src/state/state_full.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/rpc/src/state/state_full.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/rpc/src/state/state_full.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/rpc/src/state/state_full.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/rpc/src/state/state_light.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/rpc/src/state/state_light.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Satisfy borrowck * Remove non-RPC `storage_entries` functions. * Revert "Remove non-RPC `storage_entries` functions." This reverts commit d840015c59ce865f879178594088c79082e8d151. * Revert "Revert "Remove non-RPC `storage_entries` functions."" This reverts commit 5813b439a4b467e022c627e3fe60cf2fa5520db4. * Finally some formatting Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
9245bfbbc2
commit
c9197a2c6a
@@ -93,6 +93,54 @@ fn should_return_storage() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_return_storage_entries() {
|
||||
const KEY1: &[u8] = b":mock";
|
||||
const KEY2: &[u8] = b":turtle";
|
||||
const VALUE: &[u8] = b"hello world";
|
||||
const CHILD_VALUE1: &[u8] = b"hello world !";
|
||||
const CHILD_VALUE2: &[u8] = b"hello world !";
|
||||
|
||||
let child_info = ChildInfo::new_default(STORAGE_KEY);
|
||||
let client = TestClientBuilder::new()
|
||||
.add_extra_storage(KEY1.to_vec(), VALUE.to_vec())
|
||||
.add_extra_child_storage(&child_info, KEY1.to_vec(), CHILD_VALUE1.to_vec())
|
||||
.add_extra_child_storage(&child_info, KEY2.to_vec(), CHILD_VALUE2.to_vec())
|
||||
.build();
|
||||
let genesis_hash = client.genesis_hash();
|
||||
let (_client, child) = new_full(
|
||||
Arc::new(client),
|
||||
SubscriptionManager::new(Arc::new(TaskExecutor)),
|
||||
DenyUnsafe::No,
|
||||
None,
|
||||
);
|
||||
|
||||
let keys = &[StorageKey(KEY1.to_vec()), StorageKey(KEY2.to_vec())];
|
||||
assert_eq!(
|
||||
executor::block_on(child.storage_entries(
|
||||
prefixed_storage_key(),
|
||||
keys.to_vec(),
|
||||
Some(genesis_hash).into()
|
||||
))
|
||||
.map(|x| x.into_iter().map(|x| x.map(|x| x.0.len()).unwrap()).sum::<usize>())
|
||||
.unwrap(),
|
||||
CHILD_VALUE1.len() + CHILD_VALUE2.len()
|
||||
);
|
||||
|
||||
// should fail if not all keys exist.
|
||||
let mut failing_keys = vec![StorageKey(b":soup".to_vec())];
|
||||
failing_keys.extend_from_slice(keys);
|
||||
assert_matches!(
|
||||
executor::block_on(child.storage_entries(
|
||||
prefixed_storage_key(),
|
||||
failing_keys,
|
||||
Some(genesis_hash).into()
|
||||
))
|
||||
.map(|x| x.iter().all(|x| x.is_some())),
|
||||
Ok(false)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_return_child_storage() {
|
||||
let child_info = ChildInfo::new_default(STORAGE_KEY);
|
||||
@@ -115,6 +163,19 @@ fn should_return_child_storage() {
|
||||
)),
|
||||
Ok(Some(StorageData(ref d))) if d[0] == 42 && d.len() == 1
|
||||
);
|
||||
|
||||
// should fail if key does not exist.
|
||||
let failing_key = StorageKey(b":soup".to_vec());
|
||||
assert_matches!(
|
||||
executor::block_on(child.storage(
|
||||
prefixed_storage_key(),
|
||||
failing_key,
|
||||
Some(genesis_hash).into()
|
||||
))
|
||||
.map(|x| x.is_some()),
|
||||
Ok(false)
|
||||
);
|
||||
|
||||
assert_matches!(
|
||||
executor::block_on(child.storage_hash(
|
||||
child_key.clone(),
|
||||
@@ -130,6 +191,53 @@ fn should_return_child_storage() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_return_child_storage_entries() {
|
||||
let child_info = ChildInfo::new_default(STORAGE_KEY);
|
||||
let client = Arc::new(
|
||||
substrate_test_runtime_client::TestClientBuilder::new()
|
||||
.add_child_storage(&child_info, "key1", vec![42_u8])
|
||||
.add_child_storage(&child_info, "key2", vec![43_u8, 44])
|
||||
.build(),
|
||||
);
|
||||
let genesis_hash = client.genesis_hash();
|
||||
let (_client, child) =
|
||||
new_full(client, SubscriptionManager::new(Arc::new(TaskExecutor)), DenyUnsafe::No, None);
|
||||
let child_key = prefixed_storage_key();
|
||||
let keys = vec![StorageKey(b"key1".to_vec()), StorageKey(b"key2".to_vec())];
|
||||
|
||||
let res = executor::block_on(child.storage_entries(
|
||||
child_key.clone(),
|
||||
keys.clone(),
|
||||
Some(genesis_hash).into(),
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
assert_matches!(
|
||||
res[0],
|
||||
Some(StorageData(ref d))
|
||||
if d[0] == 42 && d.len() == 1
|
||||
);
|
||||
assert_matches!(
|
||||
res[1],
|
||||
Some(StorageData(ref d))
|
||||
if d[0] == 43 && d[1] == 44 && d.len() == 2
|
||||
);
|
||||
assert_matches!(
|
||||
executor::block_on(child.storage_hash(
|
||||
child_key.clone(),
|
||||
keys[0].clone(),
|
||||
Some(genesis_hash).into()
|
||||
))
|
||||
.map(|x| x.is_some()),
|
||||
Ok(true)
|
||||
);
|
||||
assert_matches!(
|
||||
executor::block_on(child.storage_size(child_key.clone(), keys[0].clone(), None)),
|
||||
Ok(Some(1))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_call_contract() {
|
||||
let client = Arc::new(substrate_test_runtime_client::new());
|
||||
|
||||
Reference in New Issue
Block a user