Skip to content

Conversation

@Himess
Copy link
Contributor

@Himess Himess commented Jan 6, 2026

Adds integration tests for the History mechanism with SMT:

  • smt_history_integration: Tests creating history overlay from SMT mutations and querying historical state
  • smt_history_multiple_updates: Tests history with multiple sequential SMT updates

Closes #699

@Himess Himess marked this pull request as draft January 6, 2026 15:42
@Himess Himess force-pushed the feat/smt-history-tests branch 5 times, most recently from fbc7985 to 6f43466 Compare January 6, 2026 18:25
@Himess Himess marked this pull request as ready for review January 6, 2026 18:58
Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither test actually updates an SMT. They create an empty SMT, get its root, but then manually construct CompactLeaf and LeafChanges / NodeChanges instead of using the SMT's mutation machinery.

@Himess
Copy link
Contributor Author

Himess commented Jan 7, 2026

Updated.
Tests now use real SMT mutations via compute_mutations() and apply_mutations() instead of manually constructing the data.

@Himess Himess marked this pull request as draft January 7, 2026 15:06
@Himess Himess marked this pull request as ready for review January 7, 2026 15:29
@Himess Himess requested a review from huitseeker January 7, 2026 15:29
assert_eq!(view_v1.value(&key_2), Some(Some(&value_2)));

// Verify node changes were captured (mutations produce inner node updates)
assert!(!node_changes_v0.is_empty(), "SMT insertion should produce node changes");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test verifies node changes were captured, but doesn't compare the stored hashes against the actual SMT. Could we add something like:

for (index, hash) in node_changes_v0.iter() {
    assert_eq!(*hash, smt.get_node_hash(*index));
}

This would confirm the History node values match what the SMT actually computed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added hash verification assertions after each mutation is applied.

use crate::merkle::smt::{MutationSet, NodeMutation, SMT_DEPTH, Smt, SparseMerkleTree};

/// Converts a MutationSet into the format expected by History.
fn mutation_set_to_history_changes(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this helper is duplicated in both tests. Could be extracted to a shared function at the top of the SMT integration tests section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Extracted the helper to module level right after the SMT integration tests header.

@Himess Himess force-pushed the feat/smt-history-tests branch from 99fc7d1 to 4e3c8b3 Compare January 11, 2026 10:41
Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!


// Verify version 0 has original value
let view_v0 = history.get_view_at(0)?;
assert_eq!(view_v0.value(&key), Some(Some(&value_v0)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: since we have the SMT available, could also verify view_v0.value(&key) == Some(smt.get_value(key).as_ref()) to complete the round-trip the issue described. Not blocking, the current assertion is equivalent for this test.

Add tests verifying History overlay works correctly with SMT data structures:
- smt_leaf_history_tracking: Tests leaf data tracking across versions
- smt_node_history_tracking: Tests inner node hash tracking at SMT-valid depths
Replace manually constructed test data with actual SMT mutations
obtained via compute_mutations() and apply_mutations(). The new tests:

- smt_history_with_real_mutations: Tests History tracking of node and
  leaf changes from real SMT insertions across multiple versions
- smt_history_value_updates: Tests History tracking when updating
  existing values in the SMT

This ensures the tests reflect real-world usage patterns where History
receives data derived from actual SMT mutation operations.
- Moved mutation_set_to_history_changes to module level to eliminate duplication
- Added assertions to verify stored node hashes match SMT computed values
@huitseeker huitseeker force-pushed the feat/smt-history-tests branch from 6c91d56 to 7c51eb2 Compare January 14, 2026 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add additional tests to the History mechanism

2 participants