From 467a8d4f4493814f1102d6863fc844896e94a8ec Mon Sep 17 00:00:00 2001 From: Hansie Odendaal <39146854+hansieodendaal@users.noreply.github.com> Date: Fri, 22 Sep 2023 08:19:35 +0200 Subject: [PATCH] fix: get rid of possible 'expect' (#5794) Description --- Get rid of possible 'expect' Motivation and Context --- Better pattern to use How Has This Been Tested? --- Unit tests What process can a PR reviewer use to test or verify this change? --- Code walk through Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify --- base_layer/mmr/src/sparse_merkle_tree/proofs.rs | 6 +++--- comms/core/src/message/mod.rs | 7 +------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/base_layer/mmr/src/sparse_merkle_tree/proofs.rs b/base_layer/mmr/src/sparse_merkle_tree/proofs.rs index 43760ad980..cf7b3405fe 100644 --- a/base_layer/mmr/src/sparse_merkle_tree/proofs.rs +++ b/base_layer/mmr/src/sparse_merkle_tree/proofs.rs @@ -335,7 +335,7 @@ mod test { // feature?) assert!(proof.validate(&NodeKey::from([67u8; 32]), tree.hash())); // Use an exclusion proof to try and give an invalid validation for a key that does exist - assert_eq!(proof.validate(&NodeKey::from([64u8; 32]), tree.hash()), false); + assert!(!proof.validate(&NodeKey::from([64u8; 32]), tree.hash())); // A tree with branches tree.upsert(NodeKey::from([96u8; 32]), ValueHash::from([1u8; 32])) @@ -352,11 +352,11 @@ mod test { // Does not validate against invalid root hash assert!(!proof.validate(&NodeKey::from([99u8; 32]), &NodeHash::default())); // Not all non-existent keys will validate. (bug or feature?) - assert_eq!(proof.validate(&NodeKey::from([65; 32]), tree.hash()), false); + assert!(!proof.validate(&NodeKey::from([65; 32]), tree.hash())); // But any keys with prefix 011 (that is not 96) will validate assert!(proof.validate(&NodeKey::from([0b0110_0011; 32]), tree.hash())); assert!(proof.validate(&NodeKey::from([0b0111_0001; 32]), tree.hash())); // The key 96 does exist.. - assert_eq!(proof.validate(&NodeKey::from([0b0110_0000; 32]), tree.hash()), false); + assert!(!proof.validate(&NodeKey::from([0b0110_0000; 32]), tree.hash())); } } diff --git a/comms/core/src/message/mod.rs b/comms/core/src/message/mod.rs index 99172105fc..a68638d8f5 100644 --- a/comms/core/src/message/mod.rs +++ b/comms/core/src/message/mod.rs @@ -47,12 +47,7 @@ pub trait MessageExt: prost::Message { /// Encodes a message, allocating the buffer on the heap as necessary fn to_encoded_bytes(&self) -> Vec where Self: Sized { - let mut buf = Vec::with_capacity(self.encoded_len()); - self.encode(&mut buf).expect( - "prost::Message::encode documentation says it is infallible unless the buffer has insufficient capacity. \ - This buffer's capacity was set with encoded_len", - ); - buf + self.encode_to_vec() } /// Encodes a message into a BytesMut, allocating the buffer on the heap as necessary.