Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get rid of possible 'expect' #5794

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions base_layer/mmr/src/sparse_merkle_tree/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand All @@ -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()));
}
}
7 changes: 1 addition & 6 deletions comms/core/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>
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.
Expand Down