Skip to content

Commit

Permalink
test: Add test of AMMR's batch leaf mutation
Browse files Browse the repository at this point in the history
This method, like the rest of MMR, was very thoroughly tested when it
lived in twenty-first but apparently some of the tests got lost when
the `ArchivalMmr` data structure was migrated to this repository.
  • Loading branch information
Sword-Smith committed Apr 7, 2024
1 parent ac9f61c commit 91bb776
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/util_types/mutator_set/archival_mmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ pub(crate) mod mmr_test {

use itertools::*;
use rand::random;
use rand::thread_rng;
use test_strategy::proptest;

use crate::database::storage::storage_schema::traits::*;
Expand Down Expand Up @@ -606,6 +607,47 @@ pub(crate) mod mmr_test {
bag_peaks_gen::<Tip5>().await;
}

#[tokio::test]
async fn compare_batch_and_individual_leaf_mutation() {
type H = Tip5;
use rand::seq::SliceRandom;

let mut rng = thread_rng();
for size in 0..25 {
let init_digests = random_elements(size);
let mut archival_batch_mut: ArchivalMmr<H, Storage> =
mock::get_ammr_from_digests::<H>(init_digests.clone()).await;
let mut archival_individual_mut = mock::get_ammr_from_digests::<H>(init_digests).await;

for max_mutation_count in 0..size {
let all_indices = (0..size as u64).collect_vec();
let mutated_indices = (0..max_mutation_count)
.map(|_| *all_indices.choose(&mut rng).unwrap())
.collect_vec();
let mutated_indices = mutated_indices.into_iter().unique().collect_vec();
let new_leafs = random_elements(max_mutation_count);
let mutation_data = mutated_indices
.clone()
.into_iter()
.zip(new_leafs.into_iter())
.collect_vec();

archival_batch_mut
.batch_mutate_leaf_and_update_mps(&mut [], mutation_data.clone())
.await;

for (index, new_leaf) in mutation_data {
archival_individual_mut.mutate_leaf(index, new_leaf).await;
}

assert_eq!(
archival_batch_mut.get_peaks().await,
archival_individual_mut.get_peaks().await
);
}
}
}

#[tokio::test]
async fn accumulator_mmr_mutate_leaf_test() {
type H = blake3::Hasher;
Expand Down

0 comments on commit 91bb776

Please sign in to comment.