Skip to content

Commit

Permalink
fix: get rid of possible 'expect' (#5794)
Browse files Browse the repository at this point in the history
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

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->
  • Loading branch information
hansieodendaal authored Sep 22, 2023
1 parent 24b4324 commit 467a8d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
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

0 comments on commit 467a8d4

Please sign in to comment.