mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 14:01:02 +00:00
Merge commit '392447f5c8f986ded2559a78457f4cd87942f393' into update-bridges-subtree-r/w
This commit is contained in:
@@ -8,27 +8,17 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "2.0.0" }
|
||||
finality-grandpa = "0.14.4"
|
||||
hash-db = "0.15.2"
|
||||
honggfuzz = "0.5.54"
|
||||
log = "0.4.0"
|
||||
env_logger = "0.8.3"
|
||||
|
||||
# Bridge Dependencies
|
||||
|
||||
bp-header-chain = { path = "../../primitives/header-chain" }
|
||||
bp-runtime = { path = "../../primitives/runtime" }
|
||||
bp-test-utils = { path = "../../primitives/test-utils" }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
@@ -6,7 +6,10 @@ Install dependencies:
|
||||
```
|
||||
$ sudo apt install build-essential binutils-dev libunwind-dev
|
||||
```
|
||||
|
||||
or on nix:
|
||||
```
|
||||
$ nix-shell -p honggfuzz
|
||||
```
|
||||
|
||||
Install `cargo hfuzz` plugin:
|
||||
```
|
||||
@@ -29,4 +32,3 @@ HFUZZ_RUN_ARGS="-t 1 -n 12 -v -N 1000000 --exit_upon_crash" cargo hfuzz run exam
|
||||
```
|
||||
|
||||
More details in the [official documentation](https://docs.rs/honggfuzz/0.5.52/honggfuzz/#about-honggfuzz).
|
||||
|
||||
|
||||
@@ -28,10 +28,8 @@ use sp_trie::StorageProof;
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn craft_known_storage_proof(input_vec: Vec<(Vec<u8>, Vec<u8>)>) -> (H256, StorageProof) {
|
||||
let storage_proof_vec = vec![(
|
||||
None,
|
||||
input_vec.iter().map(|x| (x.0.clone(), Some(x.1.clone()))).collect(),
|
||||
)];
|
||||
let storage_proof_vec =
|
||||
vec![(None, input_vec.iter().map(|x| (x.0.clone(), Some(x.1.clone()))).collect())];
|
||||
log::info!("Storage proof vec {:?}", storage_proof_vec);
|
||||
let backend = <InMemoryBackend<Blake2Hasher>>::from(storage_proof_vec);
|
||||
let root = backend.storage_root(std::iter::empty()).0;
|
||||
@@ -47,7 +45,7 @@ fn craft_known_storage_proof(input_vec: Vec<(Vec<u8>, Vec<u8>)>) -> (H256, Stora
|
||||
fn transform_into_unique(input_vec: Vec<(Vec<u8>, Vec<u8>)>) -> Vec<(Vec<u8>, Vec<u8>)> {
|
||||
let mut output_hashmap = HashMap::new();
|
||||
let mut output_vec = Vec::new();
|
||||
for key_value_pair in input_vec.clone() {
|
||||
for key_value_pair in input_vec {
|
||||
output_hashmap.insert(key_value_pair.0, key_value_pair.1); //Only 1 value per key
|
||||
}
|
||||
for (key, val) in output_hashmap.iter() {
|
||||
@@ -59,18 +57,16 @@ fn transform_into_unique(input_vec: Vec<(Vec<u8>, Vec<u8>)>) -> Vec<(Vec<u8>, Ve
|
||||
fn run_fuzzer() {
|
||||
fuzz!(|input_vec: Vec<(Vec<u8>, Vec<u8>)>| {
|
||||
if input_vec.is_empty() {
|
||||
return;
|
||||
return
|
||||
}
|
||||
let unique_input_vec = transform_into_unique(input_vec);
|
||||
let (root, craft_known_storage_proof) = craft_known_storage_proof(unique_input_vec.clone());
|
||||
let checker = <bp_runtime::StorageProofChecker<Blake2Hasher>>::new(root, craft_known_storage_proof)
|
||||
.expect("Valid proof passed; qed");
|
||||
let checker =
|
||||
<bp_runtime::StorageProofChecker<Blake2Hasher>>::new(root, craft_known_storage_proof)
|
||||
.expect("Valid proof passed; qed");
|
||||
for key_value_pair in unique_input_vec {
|
||||
log::info!("Reading value for pair {:?}", key_value_pair);
|
||||
assert_eq!(
|
||||
checker.read_value(&key_value_pair.0),
|
||||
Ok(Some(key_value_pair.1.clone()))
|
||||
);
|
||||
assert_eq!(checker.read_value(&key_value_pair.0), Ok(Some(key_value_pair.1.clone())));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user