Skip to content

Add property test that total_fees_accrued() equals the sum of recorded fees on every Executed settlement per asset #146

Description

@Jagadeeshftw

📌 Description

total_fees_accrued sums fees_accrued(asset) across list_assets, and fees_accrued(asset) is meant to track the fee portion of every execute_settlement call for that asset since the last collect_fees. There is no property-style test asserting this invariant holds under a randomized mix of open_settlement/execute_settlement/cancel_settlement/collect_fees calls across multiple assets and anchors, only more targeted example-based tests elsewhere in the suite.

🧩 Requirements and context

  • Add a proptest-based test (the crate already depends on proptest per Cargo.toml) generating a randomized sequence of open_settlement, execute_settlement, cancel_settlement, and collect_fees calls across a small fixed set of assets and anchors.
  • Independently track, in the test itself, the expected accrued-fee total per asset from every execute_settlement call minus every collect_fees call, and assert it matches total_fees_accrued/fees_accrued(asset) after each step.
  • Ensure the generated sequence respects preconditions (sufficient liquidity, valid settlement ids, registered anchors) so the property test explores valid executions rather than mostly hitting early validation errors.

🛠️ Suggested execution

  • Add the proptest to src/test.rs, reusing the crate's existing proptest dev-dependency and any strategy helpers already present for other property tests in this suite.
  • Keep the state-machine model simple: track a HashMap<Symbol, i128> of expected accrued fees, mutated alongside each simulated call, and assert equality with the contract's on-chain state after each step.
  • Document the invariant being tested in a comment above the proptest for future maintainers.

✅ Acceptance criteria

  • The property test passes across many randomized valid call sequences.
  • The test would fail if a future change caused fees_accrued/total_fees_accrued to drift from the sum of actually-executed settlement fees.
  • The test respects Cargo.toml's existing proptest dependency without requiring a new one.

🔒 Security notes

Fee accrual drift compounding silently across many settlements is exactly the class of bug example-based tests are least likely to catch; a property test covering the full accrual/collection lifecycle is the strongest guard against a subtle fund-accounting regression here.

📋 Guidelines

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

Metadata

Metadata

Assignees

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