Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 1f173bd

Browse files
authored
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 <>
1 parent d186854 commit 1f173bd

File tree

6 files changed

+31
-32
lines changed

6 files changed

+31
-32
lines changed

Cargo.lock

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ members = [
4040
"cli",
4141
"core-primitives",
4242
"erasure-coding",
43+
"erasure-coding/fuzzer",
4344
"primitives",
4445
"primitives/test-helpers",
4546
"runtime/common",

erasure-coding/fuzzer/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "erasure_coding_fuzzer"
33
version.workspace = true
44
authors.workspace = true
55
edition.workspace = true
6+
publish = false
67

78
[dependencies]
89
polkadot-erasure-coding = { path = ".." }
@@ -17,5 +18,3 @@ path = "src/reconstruct.rs"
1718
[[bin]]
1819
name = "round_trip"
1920
path = "src/round_trip.rs"
20-
21-
[workspace]

erasure-coding/fuzzer/src/reconstruct.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use honggfuzz::fuzz;
1718
use polkadot_erasure_coding::*;
1819
use primitives::AvailableData;
19-
use honggfuzz::fuzz;
2020

2121
fn main() {
2222
loop {
2323
fuzz!(|data: (usize, Vec<(Vec<u8>, usize)>)| {
2424
let (num_validators, chunk_input) = data;
2525
let reconstructed: Result<AvailableData, _> = reconstruct_v1(
2626
num_validators,
27-
chunk_input.iter().map(|t| (&*t.0, t.1)).collect::<Vec<(&[u8], usize)>>()
27+
chunk_input.iter().map(|t| (&*t.0, t.1)).collect::<Vec<(&[u8], usize)>>(),
2828
);
2929
println!("reconstructed {:?}", reconstructed);
3030
});

erasure-coding/fuzzer/src/round_trip.rs

+9-17
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,33 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use honggfuzz::fuzz;
1718
use polkadot_erasure_coding::*;
19+
use polkadot_primitives::PersistedValidationData;
1820
use primitives::{AvailableData, BlockData, PoV};
1921
use std::sync::Arc;
20-
use honggfuzz::fuzz;
21-
use polkadot_primitives::PersistedValidationData;
22-
2322

2423
fn main() {
2524
loop {
2625
fuzz!(|data: &[u8]| {
27-
let pov_block = PoV {
28-
block_data: BlockData(data.iter().cloned().collect()),
29-
};
26+
let pov_block = PoV { block_data: BlockData(data.iter().cloned().collect()) };
3027

3128
let available_data = AvailableData {
3229
pov: Arc::new(pov_block),
3330
validation_data: PersistedValidationData::default(),
3431
};
35-
let chunks = obtain_chunks_v1(
36-
10,
37-
&available_data,
38-
).unwrap();
32+
let chunks = obtain_chunks_v1(10, &available_data).unwrap();
3933

4034
assert_eq!(chunks.len(), 10);
4135

4236
// any 4 chunks should work.
4337
let reconstructed: AvailableData = reconstruct_v1(
4438
10,
45-
[
46-
(&*chunks[1], 1),
47-
(&*chunks[4], 4),
48-
(&*chunks[6], 6),
49-
(&*chunks[9], 9),
50-
].iter().cloned(),
51-
).unwrap();
39+
[(&*chunks[1], 1), (&*chunks[4], 4), (&*chunks[6], 6), (&*chunks[9], 9)]
40+
.iter()
41+
.cloned(),
42+
)
43+
.unwrap();
5244

5345
assert_eq!(reconstructed, available_data);
5446
println!("{:?}", reconstructed);

xcm/src/v3/multilocation.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,10 @@ mod tests {
599599
fn append_with_works() {
600600
let acc = AccountIndex64 { network: None, index: 23 };
601601
let mut m = MultiLocation { parents: 1, interior: X1(Parachain(42)) };
602-
assert_eq!(m.append_with(X2(PalletInstance(3), acc.clone())), Ok(()));
602+
assert_eq!(m.append_with(X2(PalletInstance(3), acc)), Ok(()));
603603
assert_eq!(
604604
m,
605-
MultiLocation {
606-
parents: 1,
607-
interior: X3(Parachain(42), PalletInstance(3), acc.clone())
608-
}
605+
MultiLocation { parents: 1, interior: X3(Parachain(42), PalletInstance(3), acc) }
609606
);
610607

611608
// cannot append to create overly long multilocation
@@ -614,8 +611,8 @@ mod tests {
614611
parents: 254,
615612
interior: X5(Parachain(42), OnlyChild, OnlyChild, OnlyChild, OnlyChild),
616613
};
617-
let suffix: MultiLocation = (PalletInstance(3), acc.clone(), OnlyChild, OnlyChild).into();
618-
assert_eq!(m.clone().append_with(suffix.clone()), Err(suffix));
614+
let suffix: MultiLocation = (PalletInstance(3), acc, OnlyChild, OnlyChild).into();
615+
assert_eq!(m.clone().append_with(suffix), Err(suffix));
619616
}
620617

621618
#[test]
@@ -636,7 +633,7 @@ mod tests {
636633
// cannot prepend to create overly long multilocation
637634
let mut m = MultiLocation { parents: 254, interior: X1(Parachain(42)) };
638635
let prefix = MultiLocation { parents: 2, interior: Here };
639-
assert_eq!(m.prepend_with(prefix.clone()), Err(prefix));
636+
assert_eq!(m.prepend_with(prefix), Err(prefix));
640637

641638
let prefix = MultiLocation { parents: 1, interior: Here };
642639
assert_eq!(m.prepend_with(prefix), Ok(()));
@@ -658,11 +655,11 @@ mod tests {
658655
assert_eq!(second, &Parachain(3));
659656

660657
let res = Here
661-
.pushed_with(first.clone())
658+
.pushed_with(*first)
662659
.unwrap()
663-
.pushed_with(second.clone())
660+
.pushed_with(*second)
664661
.unwrap()
665-
.pushed_with(third.clone())
662+
.pushed_with(*third)
666663
.unwrap();
667664
assert_eq!(m, res);
668665

0 commit comments

Comments
 (0)