From 7d8ecced0e0c07334f7eaac6dc495f47704929b8 Mon Sep 17 00:00:00 2001
From: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Date: Fri, 12 May 2023 00:55:45 +0200
Subject: [PATCH] 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 <>
---
 polkadot/Cargo.lock                           | 10 +++++++
 polkadot/Cargo.toml                           |  1 +
 polkadot/erasure-coding/fuzzer/Cargo.toml     |  3 +--
 .../erasure-coding/fuzzer/src/reconstruct.rs  |  4 +--
 .../erasure-coding/fuzzer/src/round_trip.rs   | 26 +++++++------------
 polkadot/xcm/src/v3/multilocation.rs          | 19 ++++++--------
 6 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock
index 93c642dd92d..8a5b1c96b48 100644
--- a/polkadot/Cargo.lock
+++ b/polkadot/Cargo.lock
@@ -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"
diff --git a/polkadot/Cargo.toml b/polkadot/Cargo.toml
index 886b489a502..2dbadbadfea 100644
--- a/polkadot/Cargo.toml
+++ b/polkadot/Cargo.toml
@@ -40,6 +40,7 @@ members = [
 	"cli",
 	"core-primitives",
 	"erasure-coding",
+	"erasure-coding/fuzzer",
 	"primitives",
 	"primitives/test-helpers",
 	"runtime/common",
diff --git a/polkadot/erasure-coding/fuzzer/Cargo.toml b/polkadot/erasure-coding/fuzzer/Cargo.toml
index bd8632a185f..e67a00cb0c1 100644
--- a/polkadot/erasure-coding/fuzzer/Cargo.toml
+++ b/polkadot/erasure-coding/fuzzer/Cargo.toml
@@ -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]
diff --git a/polkadot/erasure-coding/fuzzer/src/reconstruct.rs b/polkadot/erasure-coding/fuzzer/src/reconstruct.rs
index f6a95a9d3e9..b2f9690a6fd 100644
--- a/polkadot/erasure-coding/fuzzer/src/reconstruct.rs
+++ b/polkadot/erasure-coding/fuzzer/src/reconstruct.rs
@@ -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);
 		});
diff --git a/polkadot/erasure-coding/fuzzer/src/round_trip.rs b/polkadot/erasure-coding/fuzzer/src/round_trip.rs
index e1be4c49e20..2e38becf651 100644
--- a/polkadot/erasure-coding/fuzzer/src/round_trip.rs
+++ b/polkadot/erasure-coding/fuzzer/src/round_trip.rs
@@ -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);
diff --git a/polkadot/xcm/src/v3/multilocation.rs b/polkadot/xcm/src/v3/multilocation.rs
index aee0d24061f..7a2f3eb0ca3 100644
--- a/polkadot/xcm/src/v3/multilocation.rs
+++ b/polkadot/xcm/src/v3/multilocation.rs
@@ -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);
 
-- 
GitLab