Skip to content

Add test coverage that is_pair_active returns false for unregistered, zero-liquidity, and unset-liquidity pairs #134

Description

@mikewheeleer

Test the three falsey branches and the true branch of is_pair_active

Description

is_pair_active in src/lib.rs returns true only when a pair is both registered and has strictly positive reported liquidity. It short-circuits to false on an unregistered pair, and otherwise returns liquidity > 0, defaulting absent liquidity to 0. There is a subtlety here: a pair whose liquidity was never set by an oracle reads as 0 from this helper (not the i128::MAX sentinel that compute_route_fee uses), so is_pair_active is false for a freshly registered, never-funded pair even though compute_route_fee would treat it as unbounded. That divergence is worth pinning with tests so it is intentional and documented.

Requirements and context

  • Repository scope: StableRoute-Org/Stableroute-contracts only.
  • Test is_pair_active returns false for an unregistered pair.
  • Test it returns false for a registered pair with liquidity explicitly set to 0 and for a registered pair with liquidity never set.
  • Test it returns true for a registered pair with positive liquidity.
  • Document (in the test doc comments and optionally a lib.rs note) the deliberate divergence between is_pair_active's 0-default and compute_route_fee's i128::MAX sentinel.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b test/contracts-is-pair-active-coverage
  • Implement changes
    • Write code in: src/lib.rs — optional one-line doc clarification of the sentinel divergence; otherwise no production change.
    • Write comprehensive tests in: src/lib.rs (inline #[cfg(test)] mod test, near mod test_i18_read_surface) — cover all four branches.
    • Add documentation: note the divergence in docs/abi.md under is_pair_active.
    • Include NatSpec-style doc comments (///) on each new test, matching the existing style in lib.rs.
    • Validate security assumptions: read-only, no state change.
  • Test and commit

Test and commit

  • Run cargo fmt --all -- --check, cargo build, and cargo test.
  • Cover edge cases: unregistered, zero liquidity, unset liquidity, and positive liquidity.
  • Include the full cargo test output in the PR description.

Example commit message

test: cover is_pair_active across unregistered, zero, unset, and positive liquidity

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.

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions