Skip to content

test: Implement deterministic fuzz target for lifecycle sequences and invariants - #198

Merged
arisu6804 merged 1 commit into
RemitFlow:mainfrom
Opulencechuks:fix-fuzz-testing
Aug 27, 2026
Merged

test: Implement deterministic fuzz target for lifecycle sequences and invariants#198
arisu6804 merged 1 commit into
RemitFlow:mainfrom
Opulencechuks:fix-fuzz-testing

Conversation

@Opulencechuks

Copy link
Copy Markdown

Closes #192

Description

Problem:
The example tests previously did not adequately cover permutations involving expiry, refunds, partial settlements, and large amounts. Furthermore, we needed a robust suite to assert contract invariants correctly under arbitrary command sequences.

Objective:
Deliver a production-quality improvement to the property and lifecycle test suite by integrating fuzzing capabilities that generate diverse sequences of operations. This aims to create measurable value for correctness, security, reliability, and maintainability.

Implementation Scope:

  • Configured the remitflow-contract-fuzz package to utilize the arbitrary crate and soroban-sdk testutils.
  • Implemented fuzz_target_1.rs to generate arbitrary sequence actions: AdvanceTime, CreateTransfer, ClaimTransfer, CancelTransfer, and SweepExpired.
  • Verified key invariants across randomized sequences, including:
    • Monotonic status changes (e.g. enforcing transitions only occur from Pending).
    • Escrow conservation, ensuring that tokens within the contract match the sum of active liabilities (tested before and after every sequence action).
    • Checked arithmetic and robustness against large random inputs.

Acceptance Criteria Met:

  • Fuzz failures are deterministic and reproducible due to using libfuzzer-sys with a strict FuzzData struct serialization.
  • All primary lifecycle paths now participate fully in the test suites.
  • State invariants remain rigorously enabled and verified during fuzz testing.
  • No existing tests were weakened, deleted, or skipped.

Design Tradeoffs:
We chose libfuzzer-sys along with arbitrary::Arbitrary for state generation, which provides excellent interoperability with cargo-fuzz and simplifies finding complex regressions for smart contract state transitions. Mock setups limit user scopes deterministically, allowing us to accurately simulate token movements without triggering extraneous Soroban test framework limitations on auth.

@arisu6804
arisu6804 merged commit 17673b7 into RemitFlow:main Aug 27, 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.

test(contract): add fuzz invariants for escrow, expiry, and balance accounting

2 participants