Skip to content

test(fuzz): add lifecycle and conservation property testing harness - #350

Merged
josephchimebuka merged 7 commits into
TevaLabs:mainfrom
Oyinkans0la12:test/lifecycle-conservation-fuzz
Aug 5, 2026
Merged

test(fuzz): add lifecycle and conservation property testing harness#350
josephchimebuka merged 7 commits into
TevaLabs:mainfrom
Oyinkans0la12:test/lifecycle-conservation-fuzz

Conversation

@Oyinkans0la12

Copy link
Copy Markdown
Contributor

Closes #285

Summary

Introduce a property-based fuzz testing harness that exercises randomized protocol lifecycle operations while continuously validating conservation and protocol invariants. The harness supports deterministic replay through reproducible random seeds and provides both CI-friendly and extended execution modes.

Problem

Handwritten tests cover expected execution paths but often miss rare action orderings and edge-case state transitions. As new protocol features are added, subtle lifecycle bugs and invariant violations can escape traditional test coverage.

Solution

This PR adds a reusable property-based fuzz testing framework that generates randomized lifecycle sequences, validates protocol invariants after every operation, and records sufficient diagnostics to reproduce failures deterministically.

Implementation Details

Lifecycle Action Generator

Implemented a configurable randomized action generator capable of exercising the protocol through realistic lifecycle operations, including creation, updates, disputes, cancellations, settlements, withdrawals, and other supported transitions.

Generated sequences respect protocol preconditions while maximizing state-space exploration.

Property-Based Harness

Added a reusable fuzz/property testing harness that:

  • executes randomized action sequences,
  • validates invariants after every operation,
  • stops immediately on failure,
  • records execution history for replay.

Protocol Invariants

The harness continuously validates multiple protocol correctness properties, including:

  • asset/value conservation,
  • balance consistency,
  • settlement correctness,
  • fee accounting,
  • lifecycle state validity,

along with additional protocol-specific invariants where applicable.

Failure Diagnostics

Invariant failures now report:

  • random seed,
  • generated action sequence,
  • failing operation index,
  • invariant name,
  • relevant protocol state.

The reported seed enables deterministic reproduction of the exact failing execution.

Execution Modes

Two execution modes are provided:

Fast Mode

  • optimized for pull request CI,
  • reduced iteration count,
  • predictable runtime.

Extended Mode

  • larger randomized workloads,
  • broader state exploration,
  • suitable for nightly or local stress testing.

Documentation

Added documentation covering:

  • execution modes,
  • replaying failures with reported seeds,
  • extending the action generator,
  • adding new invariants.

Testing

Validated:

  • randomized lifecycle execution,
  • continuous invariant enforcement,
  • deterministic replay using reported seeds,
  • acceptable CI runtime for fast mode,
  • successful execution of extended mode.

Behavioral Changes

None.

This PR improves testing infrastructure only and does not modify production protocol behavior.

Benefits

  • Detects rare lifecycle ordering bugs.
  • Strengthens conservation guarantees.
  • Makes failures deterministic and reproducible.
  • Provides a scalable foundation for future protocol testing.

Checklist

  • Added randomized lifecycle action generator.
  • Added property-based fuzz testing harness.
  • Implemented at least five protocol invariants.
  • Added fast and extended execution modes.
  • Added deterministic seed replay and diagnostics.
  • Integrated fast mode into CI.
  • Documented execution and replay workflow.
  • No production behavior changes.
  • Ready for review.

@josephchimebuka

Copy link
Copy Markdown
Contributor

@Oyinkans0la12 Pls can you fix Conflicts and send a message in the group saying you've fixed them so I can merge

@josephchimebuka
josephchimebuka merged commit dc9b0df into TevaLabs:main Aug 5, 2026
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.

Testing: fuzz harness for lifecycle + conservation

3 participants