Add erasure-coding/fuzzer to workspace (#7210)

* Add to workspace

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove dumb clones

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update Cargo.lock

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: parity-processbot <>
This commit is contained in:
Oliver Tale-Yazdi
2023-05-12 00:55:45 +02:00
committed by GitHub
parent 7f391adf44
commit 7d8ecced0e
6 changed files with 31 additions and 32 deletions
+10
View File
@@ -2156,6 +2156,16 @@ dependencies = [
"serde",
]
[[package]]
name = "erasure_coding_fuzzer"
version = "0.9.41"
dependencies = [
"honggfuzz",
"polkadot-erasure-coding",
"polkadot-node-primitives",
"polkadot-primitives",
]
[[package]]
name = "errno"
version = "0.2.8"
+1
View File
@@ -40,6 +40,7 @@ members = [
"cli",
"core-primitives",
"erasure-coding",
"erasure-coding/fuzzer",
"primitives",
"primitives/test-helpers",
"runtime/common",
+1 -2
View File
@@ -3,6 +3,7 @@ name = "erasure_coding_fuzzer"
version.workspace = true
authors.workspace = true
edition.workspace = true
publish = false
[dependencies]
polkadot-erasure-coding = { path = ".." }
@@ -17,5 +18,3 @@ path = "src/reconstruct.rs"
[[bin]]
name = "round_trip"
path = "src/round_trip.rs"
[workspace]
@@ -14,9 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use honggfuzz::fuzz;
use polkadot_erasure_coding::*;
use primitives::AvailableData;
use honggfuzz::fuzz;
fn main() {
loop {
@@ -24,7 +24,7 @@ fn main() {
let (num_validators, chunk_input) = data;
let reconstructed: Result<AvailableData, _> = reconstruct_v1(
num_validators,
chunk_input.iter().map(|t| (&*t.0, t.1)).collect::<Vec<(&[u8], usize)>>()
chunk_input.iter().map(|t| (&*t.0, t.1)).collect::<Vec<(&[u8], usize)>>(),
);
println!("reconstructed {:?}", reconstructed);
});
@@ -14,41 +14,33 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use honggfuzz::fuzz;
use polkadot_erasure_coding::*;
use polkadot_primitives::PersistedValidationData;
use primitives::{AvailableData, BlockData, PoV};
use std::sync::Arc;
use honggfuzz::fuzz;
use polkadot_primitives::PersistedValidationData;
fn main() {
loop {
fuzz!(|data: &[u8]| {
let pov_block = PoV {
block_data: BlockData(data.iter().cloned().collect()),
};
let pov_block = PoV { block_data: BlockData(data.iter().cloned().collect()) };
let available_data = AvailableData {
pov: Arc::new(pov_block),
validation_data: PersistedValidationData::default(),
};
let chunks = obtain_chunks_v1(
10,
&available_data,
).unwrap();
let chunks = obtain_chunks_v1(10, &available_data).unwrap();
assert_eq!(chunks.len(), 10);
// any 4 chunks should work.
let reconstructed: AvailableData = reconstruct_v1(
10,
[
(&*chunks[1], 1),
(&*chunks[4], 4),
(&*chunks[6], 6),
(&*chunks[9], 9),
].iter().cloned(),
).unwrap();
[(&*chunks[1], 1), (&*chunks[4], 4), (&*chunks[6], 6), (&*chunks[9], 9)]
.iter()
.cloned(),
)
.unwrap();
assert_eq!(reconstructed, available_data);
println!("{:?}", reconstructed);
+8 -11
View File
@@ -599,13 +599,10 @@ mod tests {
fn append_with_works() {
let acc = AccountIndex64 { network: None, index: 23 };
let mut m = MultiLocation { parents: 1, interior: X1(Parachain(42)) };
assert_eq!(m.append_with(X2(PalletInstance(3), acc.clone())), Ok(()));
assert_eq!(m.append_with(X2(PalletInstance(3), acc)), Ok(()));
assert_eq!(
m,
MultiLocation {
parents: 1,
interior: X3(Parachain(42), PalletInstance(3), acc.clone())
}
MultiLocation { parents: 1, interior: X3(Parachain(42), PalletInstance(3), acc) }
);
// cannot append to create overly long multilocation
@@ -614,8 +611,8 @@ mod tests {
parents: 254,
interior: X5(Parachain(42), OnlyChild, OnlyChild, OnlyChild, OnlyChild),
};
let suffix: MultiLocation = (PalletInstance(3), acc.clone(), OnlyChild, OnlyChild).into();
assert_eq!(m.clone().append_with(suffix.clone()), Err(suffix));
let suffix: MultiLocation = (PalletInstance(3), acc, OnlyChild, OnlyChild).into();
assert_eq!(m.clone().append_with(suffix), Err(suffix));
}
#[test]
@@ -636,7 +633,7 @@ mod tests {
// cannot prepend to create overly long multilocation
let mut m = MultiLocation { parents: 254, interior: X1(Parachain(42)) };
let prefix = MultiLocation { parents: 2, interior: Here };
assert_eq!(m.prepend_with(prefix.clone()), Err(prefix));
assert_eq!(m.prepend_with(prefix), Err(prefix));
let prefix = MultiLocation { parents: 1, interior: Here };
assert_eq!(m.prepend_with(prefix), Ok(()));
@@ -658,11 +655,11 @@ mod tests {
assert_eq!(second, &Parachain(3));
let res = Here
.pushed_with(first.clone())
.pushed_with(*first)
.unwrap()
.pushed_with(second.clone())
.pushed_with(*second)
.unwrap()
.pushed_with(third.clone())
.pushed_with(*third)
.unwrap();
assert_eq!(m, res);