Skip to content

test: prove double-invocation of collect_fees never double-collects - #178

Open
mordabdul1 wants to merge 1 commit into
AnchorNet-Org:mainfrom
mordabdul1:test/collect-fees-double-invocation-80
Open

mordabdul1 wants to merge 1 commit into
AnchorNet-Org:mainfrom
mordabdul1:test/collect-fees-double-invocation-80

Conversation

@mordabdul1

Copy link
Copy Markdown

Summary

Closes #80.

Adds test_collect_fees_double_invocation_never_double_collects to src/test.rs: collect_fees(asset) is invoked twice in immediate succession (same ledger — the env's sequence number is never advanced), asserting the first call pays the full accrual and zeroes fees_accrued, and the second fails with Error::NoFeesToCollect — never re-collecting the same amount. The test further proves post-collection accruals form a fresh balance (exactly the new amount is collectable, no residue) and that the guarantee holds again after re-accrual.

Checks-effects-interactions review (no gap found)

collect_fees in src/lib.rs already follows CEI ordering, so no reorder was needed:

  1. Checks — admin auth, then a non-zero accrual (else NoFeesToCollect).
  2. Effects — fees_accrued is zeroed; this is the function's only state mutation.
  3. Interactions — there are none. No SEP-41 token transfer or any other cross-contract call exists on this path: accrued fees are internal accounting, and the function just emits an event and returns the amount.

With no external call frame anywhere in the function, there is nothing for a malicious token to reenter through — and the Soroban host additionally forbids contract reentrancy outright, so the guarantee is defense in depth. Should a real token payout ever be added to this path, the accrual is already zeroed before the point where such a transfer would go, and this regression test would pin the observable behavior.

Testing

Full suite: 154 passed, 0 failed. cargo fmt --check clean.

Incidental

Bumps ethnum 1.5.2 → 1.5.3 in Cargo.lock (1.5.2 fails to compile on recent rustc, E0512). Same patch bump as #173/#174/#175/#177; merges cleanly in any order.

@mordabdul1
mordabdul1 force-pushed the test/collect-fees-double-invocation-80 branch from ac7944e to c9e4070 Compare October 23, 2026 12:57
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.

Add reentrancy-style regression test for double-invocation of collect_fees in one ledger

1 participant