Skip to content

feat(test): add deterministic test harness and swap_invariant example…#112

Merged
ameeribro4-sudo merged 1 commit into
OpenPeerX:mainfrom
OTimileyin:feat/test-determinism
Jul 20, 2026
Merged

feat(test): add deterministic test harness and swap_invariant example…#112
ameeribro4-sudo merged 1 commit into
OpenPeerX:mainfrom
OTimileyin:feat/test-determinism

Conversation

@OTimileyin

Copy link
Copy Markdown
Contributor

Summary

Closes #8

Adds a test-determinism feature gate and a reusable TestHarness that provides deterministic ledger timestamps, event tracing, and Jest-style timing artifacts in CI.

Changes

peerx-contracts/counter/Cargo.toml

Added test-determinism = [] feature flag.

peerx-contracts/counter/src/test_harness.rs (new)

TestHarness struct with:

  • Deterministic env – pins ledger timestamp to 1_700_000_000 and sequence to 1 for bit-for-bit reproducibility
  • set_timestamp(ts) – advance the ledger mid-test (same with_mut pattern from rate_limit.rs)
  • with_event_trace(f) – captures all Soroban events emitted during f, so failing assertions can be tied to a specific event sequence
  • generate_address() – convenience wrapper for Address::generate
  • Timing artifacts – on Drop, writes $CARGO_TARGET_TMPDIR/timing/<name>.json (Jest-style)

peerx-contracts/counter/src/lib.rs

Registered mod test_harness behind #[cfg(all(test, feature = "test-determinism"))].

peerx-contracts/counter/src/invariants.rs

Added swap_invariant test demonstrating the harness: happy path, timestamp determinism, event tracing (no-op + mint), and invariant verification.

Acceptance Criteria

  • Jest-style test artifacts (CARGO_TARGET_TMPDIR/timing) are published
  • swap_invariant example test demonstrates the harness

Verification

  • Cargo.toml passes TOML validation
  • Only the four named files were touched

@ameeribro4-sudo ameeribro4-sudo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@ameeribro4-sudo
ameeribro4-sudo merged commit 195bd6d into OpenPeerX:main Jul 20, 2026
3 checks passed
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.

[PeerX Backlog # 8] Add a tracing-based test-logging harness in CI

2 participants