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
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:
parent
e070fc19ce
commit
03647457d9
4 changed files with 37 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
## 0.15.0 (TBD)
|
||||
|
||||
- Added default constructors to `MmrPeaks` and `PartialMmr` (#409).
|
||||
|
||||
## 0.14.0 (2025-03-15)
|
||||
|
||||
|
|
|
@ -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
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -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
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue