From 8c64ee427e7d4fe84b65c1bc43ddd7bc81e56685 Mon Sep 17 00:00:00 2001 From: Anton Suprunchuk Date: Thu, 11 Jan 2024 19:46:46 +0700 Subject: [PATCH 1/4] run cargo fix --- src/prelude.rs | 8 ++++---- tests/merkle_proof_test.rs | 2 +- tests/merkle_tree_test.rs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/prelude.rs b/src/prelude.rs index 8ab04f3..61237be 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,7 +1,7 @@ pub use core::prelude::v1::*; -pub use alloc::borrow::ToOwned; -pub use alloc::boxed::Box; + + pub use alloc::string::{String, ToString}; pub use alloc::vec::Vec; @@ -9,5 +9,5 @@ pub use alloc::format; pub use alloc::vec; // Those are exported by default in the std prelude in Rust 2021 -pub use core::convert::{TryFrom, TryInto}; -pub use core::iter::FromIterator; + + diff --git a/tests/merkle_proof_test.rs b/tests/merkle_proof_test.rs index b40b712..b46fb2c 100644 --- a/tests/merkle_proof_test.rs +++ b/tests/merkle_proof_test.rs @@ -173,7 +173,7 @@ pub mod to_bytes { } pub mod from_bytes { - use crate::common; + use rs_merkle::{algorithms::Sha256, Error, MerkleProof}; #[test] diff --git a/tests/merkle_tree_test.rs b/tests/merkle_tree_test.rs index f3da7b6..abeba9a 100644 --- a/tests/merkle_tree_test.rs +++ b/tests/merkle_tree_test.rs @@ -67,7 +67,7 @@ pub mod proof { pub mod commit { use crate::common; - use rs_merkle::{algorithms::Sha256, Error, Hasher, MerkleTree}; + use rs_merkle::{algorithms::Sha256, Hasher, MerkleTree}; #[test] pub fn should_give_correct_root_after_commit() { @@ -197,7 +197,7 @@ pub mod commit { } pub mod rollback { - use crate::common; + use rs_merkle::{algorithms::Sha256, Hasher, MerkleTree}; #[test] From 48745daab5d83bb72e22fbb52e20c61591f41abf Mon Sep 17 00:00:00 2001 From: Anton Suprunchuk Date: Thu, 11 Jan 2024 19:47:09 +0700 Subject: [PATCH 2/4] clippy fix --- src/utils/collections.rs | 2 +- tests/common.rs | 6 +++--- tests/merkle_proof_test.rs | 2 +- tests/merkle_tree_test.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils/collections.rs b/src/utils/collections.rs index 541573f..29a3d6c 100644 --- a/src/utils/collections.rs +++ b/src/utils/collections.rs @@ -15,5 +15,5 @@ pub fn to_hex_string>>(bytes: &T) -> String { /// containing the difference. This function preserves the first /// vector order. pub fn difference(a: &[T], b: &[T]) -> Vec { - a.iter().cloned().filter(|x| !b.contains(x)).collect() + a.iter().filter(|&x| !b.contains(x)).cloned().collect() } diff --git a/tests/common.rs b/tests/common.rs index 42f5a4d..6a578b9 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -27,7 +27,7 @@ fn combine(active: Vec, rest: Vec, mut combinations: Vec> } else { let mut next = active.clone(); - if let Some(first) = rest.get(0) { + if let Some(first) = rest.first() { next.push(first.clone()); } @@ -123,8 +123,8 @@ pub fn setup_proof_test_cases() -> Vec { .collect(); let merkle_tree = MerkleTree::::from_leaves(&leaves); - let case = ProofTestCases { merkle_tree, cases }; - case + + ProofTestCases { merkle_tree, cases } }) .collect() } diff --git a/tests/merkle_proof_test.rs b/tests/merkle_proof_test.rs index b46fb2c..087e89a 100644 --- a/tests/merkle_proof_test.rs +++ b/tests/merkle_proof_test.rs @@ -17,7 +17,7 @@ pub mod root { let leaves_to_prove: Vec<[u8; 32]> = indices_to_prove .iter() - .map(|i| leaf_hashes.get(*i).unwrap().clone()) + .map(|i| *leaf_hashes.get(*i).unwrap()) .collect(); let merkle_tree = MerkleTree::::from_leaves(&test_data.leaf_hashes); diff --git a/tests/merkle_tree_test.rs b/tests/merkle_tree_test.rs index abeba9a..e38caa0 100644 --- a/tests/merkle_tree_test.rs +++ b/tests/merkle_tree_test.rs @@ -78,7 +78,7 @@ pub mod commit { // Passing empty vec to create an empty tree let mut merkle_tree = MerkleTree::::from_leaves(&vec); - let merkle_tree2 = MerkleTree::::from_leaves(&leaf_hashes); + let merkle_tree2 = MerkleTree::::from_leaves(leaf_hashes); // Adding leaves merkle_tree.append(leaf_hashes.clone().as_mut()); let root = merkle_tree.uncommitted_root_hex(); From cc44a1429038484c690ecf1603b5beb96553b08a Mon Sep 17 00:00:00 2001 From: Anton Suprunchuk Date: Thu, 11 Jan 2024 19:48:23 +0700 Subject: [PATCH 3/4] run cargo fmt --- src/prelude.rs | 4 ---- tests/common.rs | 1 - tests/merkle_proof_test.rs | 2 +- tests/merkle_tree_test.rs | 2 +- 4 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/prelude.rs b/src/prelude.rs index 61237be..c0692bc 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,7 +1,5 @@ pub use core::prelude::v1::*; - - pub use alloc::string::{String, ToString}; pub use alloc::vec::Vec; @@ -9,5 +7,3 @@ pub use alloc::format; pub use alloc::vec; // Those are exported by default in the std prelude in Rust 2021 - - diff --git a/tests/common.rs b/tests/common.rs index 6a578b9..37f521f 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -123,7 +123,6 @@ pub fn setup_proof_test_cases() -> Vec { .collect(); let merkle_tree = MerkleTree::::from_leaves(&leaves); - ProofTestCases { merkle_tree, cases } }) .collect() diff --git a/tests/merkle_proof_test.rs b/tests/merkle_proof_test.rs index 087e89a..87e86ee 100644 --- a/tests/merkle_proof_test.rs +++ b/tests/merkle_proof_test.rs @@ -173,7 +173,7 @@ pub mod to_bytes { } pub mod from_bytes { - + use rs_merkle::{algorithms::Sha256, Error, MerkleProof}; #[test] diff --git a/tests/merkle_tree_test.rs b/tests/merkle_tree_test.rs index e38caa0..e983fd6 100644 --- a/tests/merkle_tree_test.rs +++ b/tests/merkle_tree_test.rs @@ -197,7 +197,7 @@ pub mod commit { } pub mod rollback { - + use rs_merkle::{algorithms::Sha256, Hasher, MerkleTree}; #[test] From ee889b600d0d0d8298ce760e6c5457dfeefb1299 Mon Sep 17 00:00:00 2001 From: Anton Suprunchuk Date: Thu, 11 Jan 2024 19:58:05 +0700 Subject: [PATCH 4/4] fix vector conversion for hashes --- src/proof_serializers/direct_hashes_order.rs | 3 +-- src/proof_serializers/reverse_hashes_order.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/proof_serializers/direct_hashes_order.rs b/src/proof_serializers/direct_hashes_order.rs index 6ab9733..cd1cdf4 100644 --- a/src/proof_serializers/direct_hashes_order.rs +++ b/src/proof_serializers/direct_hashes_order.rs @@ -32,8 +32,7 @@ impl MerkleProofSerializer for DirectHashesOrder { let slice = bytes .get(slice_start..slice_end) .ok_or_else(Error::vec_to_hash_conversion_error)?; - let vec = - Vec::::try_from(slice).map_err(|_| Error::vec_to_hash_conversion_error())?; + let vec = Vec::from(slice); match T::Hash::try_from(vec) { Ok(val) => proof_hashes_slices.push(val), Err(_) => return Err(Error::vec_to_hash_conversion_error()), diff --git a/src/proof_serializers/reverse_hashes_order.rs b/src/proof_serializers/reverse_hashes_order.rs index 231c0c4..5f8a4d1 100644 --- a/src/proof_serializers/reverse_hashes_order.rs +++ b/src/proof_serializers/reverse_hashes_order.rs @@ -34,8 +34,7 @@ impl MerkleProofSerializer for ReverseHashesOrder { let slice = bytes .get(slice_start..slice_end) .ok_or_else(Error::vec_to_hash_conversion_error)?; - let vec = - Vec::::try_from(slice).map_err(|_| Error::vec_to_hash_conversion_error())?; + let vec = Vec::from(slice); match T::Hash::try_from(vec) { Ok(val) => proof_hashes_slices.push(val), Err(_) => return Err(Error::vec_to_hash_conversion_error()),