Test the liquidity-consumption branch and the i128::MAX sentinel skip
Description
compute_route_fee in src/lib.rs debits amount from PairLiquidity via saturating_sub and emits a liq_used event only when the stored liquidity is not the unbounded i128::MAX sentinel — when no oracle has set liquidity, the decrement and event are skipped entirely. This dual behaviour (debit-and-emit vs skip) is core to the routing model but is not directly asserted in the existing test modules. This issue adds focused coverage for both branches and the saturating-sub edge at exact-balance and over-balance.
Requirements and context
- Repository scope: StableRoute-Org/Stableroute-contracts only.
- Test that, with liquidity set, a route debits exactly
amount and get_pair_liquidity reflects the remainder.
- Test that a
liq_used event is emitted carrying (source, destination, remaining) only in the bounded case, and not emitted when liquidity is the unset sentinel.
- Test the exact-balance route (remaining becomes 0) and confirm a subsequent route fails with
InsufficientLiquidity.
- This is distinct from the issues-1 "decrement reported pair liquidity" feature issue — that adds the behaviour; this issue verifies it with tests.
Suggested execution
- Fork the repo and create a branch
git checkout -b test/contracts-liquidity-consumption-coverage
- Implement changes
- Write code in:
src/lib.rs — no production change expected; if a gap is found, note it for a follow-up.
- Write comprehensive tests in:
src/lib.rs (inline #[cfg(test)] mod test, near mod test_i15_bounds_liquidity) — cover the bounded debit, the sentinel skip, the exact-balance drain, and event presence/absence via env.events().all().
- Add documentation: none required beyond test doc comments.
- Include NatSpec-style doc comments (
///) on each new test explaining the branch it pins, matching the existing style in lib.rs.
- Validate security assumptions: liquidity can never go negative; the sentinel is never decremented.
- Test and commit
Test and commit
- Run
cargo fmt --all -- --check, cargo build, and cargo test.
- Cover edge cases: bounded debit, sentinel skip, exact drain to zero, and over-balance rejection.
- Include the full
cargo test output in the PR description.
Example commit message
test: cover compute_route_fee liquidity debit, sentinel skip, and liq_used event
Guidelines
- Minimum 95 percent test coverage for impacted modules.
- Clear, reviewer-focused documentation.
- Timeframe: 96 hours.
Community & contribution rewards
- 💬 Join the StableRoute community on Discord for questions, reviews, and faster merges: https://discord.gg/37aCpusvx
- ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.
Test the liquidity-consumption branch and the i128::MAX sentinel skip
Description
compute_route_feeinsrc/lib.rsdebitsamountfromPairLiquidityviasaturating_suband emits aliq_usedevent only when the stored liquidity is not the unboundedi128::MAXsentinel — when no oracle has set liquidity, the decrement and event are skipped entirely. This dual behaviour (debit-and-emit vs skip) is core to the routing model but is not directly asserted in the existing test modules. This issue adds focused coverage for both branches and the saturating-sub edge at exact-balance and over-balance.Requirements and context
amountandget_pair_liquidityreflects the remainder.liq_usedevent is emitted carrying(source, destination, remaining)only in the bounded case, and not emitted when liquidity is the unset sentinel.InsufficientLiquidity.Suggested execution
git checkout -b test/contracts-liquidity-consumption-coveragesrc/lib.rs— no production change expected; if a gap is found, note it for a follow-up.src/lib.rs(inline#[cfg(test)] mod test, nearmod test_i15_bounds_liquidity) — cover the bounded debit, the sentinel skip, the exact-balance drain, and event presence/absence viaenv.events().all().///) on each new test explaining the branch it pins, matching the existing style inlib.rs.Test and commit
cargo fmt --all -- --check,cargo build, andcargo test.cargo testoutput in the PR description.Example commit message
test: cover compute_route_fee liquidity debit, sentinel skip, and liq_used eventGuidelines
Community & contribution rewards