From 50779d2bd543428bb3ef6daae61fa3621345eaf3 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Wed, 14 Dec 2022 19:39:10 -0700 Subject: [PATCH] Consolidate bridgetree tests. --- bridgetree/src/lib.rs | 61 +++++++++++++++++++++++++++++++++++---- bridgetree/src/testing.rs | 60 -------------------------------------- 2 files changed, 55 insertions(+), 66 deletions(-) delete mode 100644 bridgetree/src/testing.rs diff --git a/bridgetree/src/lib.rs b/bridgetree/src/lib.rs index afa0c9b..471c12c 100644 --- a/bridgetree/src/lib.rs +++ b/bridgetree/src/lib.rs @@ -30,9 +30,6 @@ //! reset the state to. //! //! In this module, the term "ommer" is used as for the sibling of a parent node in a binary tree. -#[cfg(any(bench, test, feature = "test-dependencies"))] -pub mod testing; - use serde::{Deserialize, Serialize}; use std::collections::{BTreeMap, BTreeSet}; use std::convert::TryFrom; @@ -1297,11 +1294,17 @@ impl BridgeTree { #[cfg(test)] mod tests { use proptest::prelude::*; + use std::fmt::Debug; use super::*; - use incrementalmerkletree::testing::{ - apply_operation, arb_operation, check_checkpoint_rewind, check_rewind_remove_mark, - check_root_hashes, check_witnesses, Frontier, Tree, + use incrementalmerkletree::{ + testing::{ + apply_operation, arb_operation, check_checkpoint_rewind, check_operations, + check_rewind_remove_mark, check_rewind_remove_mark_consistency, check_root_hashes, + check_witnesses, complete_tree::CompleteTree, CombinedTree, Frontier, SipHashable, + Tree, + }, + Hashable, }; impl Frontier for super::Frontier { @@ -1616,4 +1619,50 @@ mod tests { tree.rewind(); assert!(tree.root(0) != empty_root); } + + // Combined tree tests + fn new_combined_tree( + max_checkpoints: usize, + ) -> CombinedTree, BridgeTree> { + CombinedTree::new( + CompleteTree::new(4, max_checkpoints), + BridgeTree::::new(max_checkpoints), + ) + } + + #[test] + fn test_rewind_remove_mark() { + check_rewind_remove_mark(new_combined_tree); + } + + #[test] + fn test_rewind_remove_mark_consistency() { + check_rewind_remove_mark_consistency(new_combined_tree); + } + + proptest! { + #![proptest_config(ProptestConfig::with_cases(100000))] + + #[test] + fn check_randomized_u64_ops( + ops in proptest::collection::vec( + arb_operation((0..32u64).prop_map(SipHashable), 0usize..100), + 1..100 + ) + ) { + let tree = new_combined_tree(100); + check_operations(tree, 4, &ops)?; + } + + #[test] + fn check_randomized_str_ops( + ops in proptest::collection::vec( + arb_operation((97u8..123).prop_map(|c| char::from(c).to_string()), 0usize..100), + 1..100 + ) + ) { + let tree = new_combined_tree(100); + check_operations(tree, 4, &ops)?; + } + } } diff --git a/bridgetree/src/testing.rs b/bridgetree/src/testing.rs deleted file mode 100644 index 9403142..0000000 --- a/bridgetree/src/testing.rs +++ /dev/null @@ -1,60 +0,0 @@ -#[cfg(test)] -pub(crate) mod tests { - use proptest::prelude::*; - use std::fmt::Debug; - - use crate::BridgeTree; - use incrementalmerkletree::{ - testing::{ - arb_operation, check_operations, check_rewind_remove_mark, - check_rewind_remove_mark_consistency, complete_tree::CompleteTree, CombinedTree, - SipHashable, - }, - Hashable, - }; - - fn new_combined_tree( - max_checkpoints: usize, - ) -> CombinedTree, BridgeTree> { - CombinedTree::new( - CompleteTree::new(4, max_checkpoints), - BridgeTree::::new(max_checkpoints), - ) - } - - #[test] - fn test_rewind_remove_mark() { - check_rewind_remove_mark(new_combined_tree); - } - - #[test] - fn test_rewind_remove_mark_consistency() { - check_rewind_remove_mark_consistency(new_combined_tree); - } - - proptest! { - #![proptest_config(ProptestConfig::with_cases(100000))] - - #[test] - fn check_randomized_u64_ops( - ops in proptest::collection::vec( - arb_operation((0..32u64).prop_map(SipHashable), 0usize..100), - 1..100 - ) - ) { - let tree = new_combined_tree(100); - check_operations(tree, 4, &ops)?; - } - - #[test] - fn check_randomized_str_ops( - ops in proptest::collection::vec( - arb_operation((97u8..123).prop_map(|c| char::from(c).to_string()), 0usize..100), - 1..100 - ) - ) { - let tree = new_combined_tree(100); - check_operations(tree, 4, &ops)?; - } - } -}