refactor(crypto): move inline merkle-backend tests to tests/#615
refactor(crypto): move inline merkle-backend tests to tests/#615diegokingston wants to merge 1 commit into
Conversation
Relocate #[cfg(test)] mod tests blocks out of crypto/crypto source files into crypto/crypto/src/tests/. - backends/field_element.rs tests -> tests/field_element_tests.rs - backends/field_element_vector.rs tests -> tests/field_element_vector_tests.rs - merkle.rs disk_spill_serde_tests -> appended to tests/merkle_tests.rs - MerkleTree::mmap_backing bumped to pub(crate) so the relocated disk-spill serde test can reach it
| #[cfg(feature = "disk-spill")] | ||
| #[cfg_attr(feature = "serde", serde(skip))] | ||
| mmap_backing: Option<MmapNodeBacking>, | ||
| pub(crate) mmap_backing: Option<MmapNodeBacking>, |
There was a problem hiding this comment.
Medium — unnecessary visibility widening
mmap_backing is promoted to pub(crate) solely so the relocated test can write restored.mmap_backing.is_none(). This leaks a disk-spill implementation detail to every crate-internal caller, not just test code.
Preferred alternatives (in order of preference):
- Add a
#[cfg(test)]accessor onMerkleTreeso the visibility stays private outside tests:
| pub(crate) mmap_backing: Option<MmapNodeBacking>, | |
| mmap_backing: Option<MmapNodeBacking>, |
#[cfg(test)]
impl<B: IsMerkleTreeBackend> MerkleTree<B> {
pub(crate) fn has_mmap_backing(&self) -> bool {
self.mmap_backing.is_some()
}
}- Test a weaker but equivalent invariant that doesn't require field access, e.g. check that
restored.nodesis non-empty instead.
| assert_eq!(batch_proof.path.len(), 2); | ||
| } | ||
|
|
||
| #[cfg(all(test, feature = "serde", feature = "disk-spill"))] |
There was a problem hiding this comment.
Low — redundant test in cfg predicate
This file is only compiled because lib.rs declares #[cfg(test)] pub mod tests;, so the test condition here is already implied. The inner module will only ever exist during a test build.
| #[cfg(all(test, feature = "serde", feature = "disk-spill"))] | |
| #[cfg(all(feature = "serde", feature = "disk-spill"))] |
Codex Code ReviewNo issues found in the PR diff. I could not complete test verification in this sandbox: |
Codex Code ReviewFindings
No Critical/High/Medium issues found in the PR diff. I attempted to run tests, but |
| #[cfg(all(test, feature = "serde", feature = "disk-spill"))] | ||
| mod disk_spill_serde_tests { | ||
| use crate::merkle_tree::backends::field_element::FieldElementBackend; | ||
| use crate::merkle_tree::merkle::*; |
There was a problem hiding this comment.
Low — wildcard import pulls in more than needed
Only MerkleTree is used from this module; the glob makes the dependency surface opaque.
| use crate::merkle_tree::merkle::*; | |
| use crate::merkle_tree::merkle::MerkleTree; |
Review: refactor(crypto): move inline merkle-backend tests to tests/Clean refactor — the test logic is identical to what was removed from the source files, and the module structure is correct (the Three minor issues flagged inline:
The |
| @@ -0,0 +1,118 @@ | |||
| //! Tests for the field-element Merkle tree backend. | |||
|
|
|||
| use alloc::vec::Vec; | |||
There was a problem hiding this comment.
Low — unnecessary alloc::vec::Vec import
This was needed in the original field_element.rs where it was compiled in no_std configurations. This tests/ module is #[cfg(test)]-gated and always compiled with std, so Vec is already in the prelude. The sibling field_element_vector_tests.rs doesn't import it.
| use alloc::vec::Vec; |
| assert_eq!(batch_proof.path.len(), 2); | ||
| } | ||
|
|
||
| #[cfg(all(test, feature = "serde", feature = "disk-spill"))] |
There was a problem hiding this comment.
Low — dead test predicate in cfg guard
This file lives inside a module that is already declared #[cfg(test)] in lib.rs, so the test predicate here is always true and does nothing. It was correct in merkle.rs (where it was copy-pasted from) because that file is compiled unconditionally, but here it's misleading.
| #[cfg(all(test, feature = "serde", feature = "disk-spill"))] | |
| #[cfg(all(feature = "serde", feature = "disk-spill"))] |
Relocate #[cfg(test)] mod tests blocks out of crypto/crypto source files into crypto/crypto/src/tests/.