Skip to content

Add fuzz/property test that settlement ids stay strictly monotonic and gapless under mixed lifecycle churn #155

Description

@Jagadeeshftw

📌 Description

open_settlement assigns ids via storage::get_settlement_count(&env) + 1, then immediately persists the incremented counter, which should guarantee ids are assigned strictly monotonically with no gaps or reuse regardless of how many settlements are subsequently executed, cancelled, or expired. There is no property-style test explicitly fuzzing a long, randomized sequence of open_settlement calls interleaved with execute_settlement/cancel_settlement/cancel_expired_settlement calls and asserting the id sequence itself (independent of status) remains strictly monotonic and gapless.

🧩 Requirements and context

  • Add a proptest-based test generating a randomized sequence of settlement lifecycle operations across multiple assets and anchors.
  • Track every id returned by open_settlement in the test and assert the sequence is exactly 1, 2, 3, ... with no gaps or repeats, regardless of how many of those settlements are later executed/cancelled/expired.
  • Assert settlement_count() always equals the number of open_settlement calls made so far, never more or less.

🛠️ Suggested execution

  • Add the proptest to src/test.rs, reusing the crate's existing proptest dev-dependency.
  • Keep the operation-generation strategy simple: a bounded list of (asset, anchor) pairs and a small set of lifecycle actions to interleave.
  • Document the monotonic-id invariant being tested in a comment above the proptest.

✅ Acceptance criteria

  • The property test passes across many randomized valid sequences of settlement lifecycle operations.
  • Settlement ids are proven to be strictly monotonic and gapless independent of lifecycle status changes.
  • settlement_count() always matches the number of open_settlement calls made.

🔒 Security notes

A gap or repeat in settlement ids would break every id-keyed off-chain index and could, in the worst case, let two distinct settlements collide on the same id — this property test is cheap insurance against that class of bug given the counter's simple but easy-to-regress increment-then-persist pattern.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issuesmart-contractSoroban/Rust smart contract worktestingTests and coverage

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions