Add default constructors to MmrPeaks and PartialMmr (#409)
Some checks failed
build / Build for no-std (push) Has been cancelled
lint / clippy nightly on ubuntu-latest (push) Has been cancelled
lint / rustfmt check nightly on ubuntu-latest (push) Has been cancelled
lint / doc stable on ubuntu-latest (push) Has been cancelled
lint / check rust version consistency (push) Has been cancelled
test / test nightly on ubuntu with default (push) Has been cancelled
test / test stable on ubuntu with default (push) Has been cancelled
test / test nightly on ubuntu with no-std (push) Has been cancelled
test / test stable on ubuntu with no-std (push) Has been cancelled
test / test nightly on ubuntu with smt-hashmaps (push) Has been cancelled
test / test stable on ubuntu with smt-hashmaps (push) Has been cancelled
test / test-smt-concurrent nightly (push) Has been cancelled
test / test-smt-concurrent stable (push) Has been cancelled

This commit is contained in:
Serge Radinovich 2025-05-05 13:46:54 +12:00 committed by GitHub
parent e070fc19ce
commit 03647457d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 0 deletions

View file

@ -1,5 +1,6 @@
## 0.15.0 (TBD)
- Added default constructors to `MmrPeaks` and `PartialMmr` (#409).
## 0.14.0 (2025-03-15)

View file

@ -70,6 +70,18 @@ pub struct PartialMmr {
pub(crate) track_latest: bool,
}
impl Default for PartialMmr {
/// Creates a new [PartialMmr] with default values.
fn default() -> Self {
let forest = 0;
let peaks = Vec::new();
let nodes = BTreeMap::new();
let track_latest = false;
Self { forest, peaks, nodes, track_latest }
}
}
impl PartialMmr {
// CONSTRUCTORS
// --------------------------------------------------------------------------------------------

View file

@ -34,6 +34,13 @@ pub struct MmrPeaks {
peaks: Vec<RpoDigest>,
}
impl Default for MmrPeaks {
/// Returns new [`MmrPeaks`] instantiated from an empty vector of peaks and 0 leaves.
fn default() -> Self {
Self { num_leaves: 0, peaks: Vec::new() }
}
}
impl MmrPeaks {
// CONSTRUCTOR
// --------------------------------------------------------------------------------------------

View file

@ -12,6 +12,23 @@ use crate::{
merkle::{InOrderIndex, MerklePath, MerkleTree, MmrProof, NodeIndex, int_to_node},
};
#[test]
fn tests_empty_mmr_peaks() {
let peaks = MmrPeaks::default();
assert_eq!(peaks.num_peaks(), 0);
assert_eq!(peaks.num_leaves(), 0);
}
#[test]
fn test_empty_partial_mmr() {
let mmr = PartialMmr::default();
assert_eq!(mmr.num_leaves(), 0);
assert_eq!(mmr.forest(), 0);
assert_eq!(mmr.peaks(), MmrPeaks::default());
assert!(mmr.nodes.is_empty());
assert!(!mmr.track_latest);
}
#[test]
fn test_position_equal_or_higher_than_leafs_is_never_contained() {
let empty_forest = 0;