mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 05:51:02 +00:00
Parse substrate message proof (#479)
* parse substrate message proof * unfinalized_header
This commit is contained in:
committed by
Bastian Köcher
parent
b0a5e75ff4
commit
2d7eacf6e2
@@ -65,15 +65,24 @@ pub enum Error {
|
||||
StorageValueUnavailable,
|
||||
}
|
||||
|
||||
impl<T: crate::Trait> From<Error> for crate::Error<T> {
|
||||
fn from(error: Error) -> Self {
|
||||
match error {
|
||||
Error::StorageRootMismatch => crate::Error::StorageRootMismatch,
|
||||
Error::StorageValueUnavailable => crate::Error::StorageValueUnavailable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
pub mod tests {
|
||||
use super::*;
|
||||
|
||||
use sp_core::{Blake2Hasher, H256};
|
||||
use sp_state_machine::{backend::Backend, prove_read, InMemoryBackend};
|
||||
|
||||
#[test]
|
||||
fn storage_proof_check() {
|
||||
/// Return valid storage proof and state root.
|
||||
pub fn craft_valid_storage_proof() -> (H256, StorageProof) {
|
||||
// construct storage proof
|
||||
let backend = <InMemoryBackend<Blake2Hasher>>::from(vec![
|
||||
(None, vec![(b"key1".to_vec(), Some(b"value1".to_vec()))]),
|
||||
@@ -90,6 +99,13 @@ mod tests {
|
||||
.collect(),
|
||||
);
|
||||
|
||||
(root, proof)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn storage_proof_check() {
|
||||
let (root, proof) = craft_valid_storage_proof();
|
||||
|
||||
// check proof in runtime
|
||||
let checker = <StorageProofChecker<Blake2Hasher>>::new(root, proof.clone()).unwrap();
|
||||
assert_eq!(checker.read_value(b"key1"), Ok(Some(b"value1".to_vec())));
|
||||
|
||||
Reference in New Issue
Block a user