Skip to content

Commit

Permalink
archive/tests: Check childtrie results
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandru Vasile <[email protected]>
  • Loading branch information
lexnv committed Nov 27, 2024
1 parent 39aab7a commit b14a4bd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
47 changes: 47 additions & 0 deletions substrate/client/rpc-spec-v2/src/archive/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,53 @@ async fn archive_storage_hashes_values() {
);
}

#[tokio::test]
async fn archive_storage_hashes_values_child_trie() {
let (client, api) = setup_api();

// Get child storage values set in `setup_api`.
let child_info = hex_string(&CHILD_STORAGE_KEY);
let key = hex_string(&KEY);
let genesis_hash = format!("{:?}", client.genesis_hash());
let expected_hash = format!("{:?}", Blake2Hasher::hash(&CHILD_VALUE));
let expected_value = hex_string(&CHILD_VALUE);

let items: Vec<StorageQuery<String>> = vec![
StorageQuery { key: key.clone(), query_type: StorageQueryType::DescendantsHashes },
StorageQuery { key: key.clone(), query_type: StorageQueryType::DescendantsValues },
];
let mut sub = api
.subscribe_unbounded(
"archive_unstable_storage",
rpc_params![&genesis_hash, items, &child_info],
)
.await
.unwrap();

assert_eq!(
get_next_event::<ArchiveStorageEvent>(&mut sub).await,
ArchiveStorageEvent::Storage(StorageResult {
key: key.clone(),
result: StorageResultType::Hash(expected_hash.clone()),
child_trie_key: Some(child_info.clone()),
})
);

assert_eq!(
get_next_event::<ArchiveStorageEvent>(&mut sub).await,
ArchiveStorageEvent::Storage(StorageResult {
key: key.clone(),
result: StorageResultType::Value(expected_value.clone()),
child_trie_key: Some(child_info.clone()),
})
);

assert_eq!(
get_next_event::<ArchiveStorageEvent>(&mut sub).await,
ArchiveStorageEvent::StorageDone,
);
}

#[tokio::test]
async fn archive_storage_closest_merkle_value() {
let (client, api) = setup_api();
Expand Down
1 change: 1 addition & 0 deletions substrate/client/rpc-spec-v2/src/chain_head/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ mod tests {
items: vec![StorageResult {
key: "0x1".into(),
result: StorageResultType::Value("0x123".to_string()),
child_trie_key: None,
}],
});

Expand Down
15 changes: 11 additions & 4 deletions substrate/client/rpc-spec-v2/src/common/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,11 @@ mod tests {
#[test]
fn storage_result() {
// Item with Value.
let item =
StorageResult { key: "0x1".into(), result: StorageResultType::Value("res".into()) };
let item = StorageResult {
key: "0x1".into(),
result: StorageResultType::Value("res".into()),
child_trie_key: None,
};
// Encode
let ser = serde_json::to_string(&item).unwrap();
let exp = r#"{"key":"0x1","value":"res"}"#;
Expand All @@ -387,8 +390,11 @@ mod tests {
assert_eq!(dec, item);

// Item with Hash.
let item =
StorageResult { key: "0x1".into(), result: StorageResultType::Hash("res".into()) };
let item = StorageResult {
key: "0x1".into(),
result: StorageResultType::Hash("res".into()),
child_trie_key: None,
};
// Encode
let ser = serde_json::to_string(&item).unwrap();
let exp = r#"{"key":"0x1","hash":"res"}"#;
Expand All @@ -401,6 +407,7 @@ mod tests {
let item = StorageResult {
key: "0x1".into(),
result: StorageResultType::ClosestDescendantMerkleValue("res".into()),
child_trie_key: None,
};
// Encode
let ser = serde_json::to_string(&item).unwrap();
Expand Down

0 comments on commit b14a4bd

Please sign in to comment.