Skip to content

Add test coverage asserting idempotent register/unregister and event payloads for pair lifecycle #39

Description

@1nonlypiece

Test pair lifecycle events and idempotency edges

Description

The existing suite in src/lib.rs covers basic register/unregister round-trips, but it never asserts the emitted events for the pair lifecycle (pair_reg, unreg, fee_set, liq_set, init) and never verifies edge behaviors like unregistering a never-registered pair, re-registering after unregister, or that unregister_pair leaves the configured fee untouched (the behavior its own doc comment claims). This issue adds event-assertion and lifecycle-edge coverage.

Requirements and context

  • Repository scope: StableRoute-Org/Stableroute-contracts only.
  • Use env.events().all() to assert the topic and data tuple emitted by init, register_pair, unregister_pair, set_pair_fee_bps, and set_pair_liquidity.
  • Cover: unregister of a never-registered pair is a clean no-op, re-register after unregister works, and unregister_pair does NOT clear PairFeeBps (documenting the current behavior precisely).
  • Use the existing setup_initialized helper; no production change expected unless a discrepancy is found.
  • Assert exact event counts so a future extra/missing publish is caught.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b test/contracts-38-pair-lifecycle-event-tests
  • Implement changes
    • Write code in: src/lib.rs — no production change expected (open a follow-up if a gap is found).
    • Write comprehensive tests in: src/lib.rs #[cfg(test)] mod test — the event-assertion and lifecycle-edge suite described above.
    • Add documentation: note the pair-lifecycle test matrix in README.md or docs/testing.md.
    • Include NatSpec-style doc comments (///) on any new test helper.
    • Validate security assumptions: events are emitted exactly once per state change with the documented payload.
  • Test and commit

Test and commit

  • Run cargo fmt --all -- --check, cargo build, and cargo test.
  • Cover edge cases and failure paths: event topic/data per entrypoint, no-op unregister, re-register, fee survives unregister.
  • Include the full cargo test output and a short security notes section in the PR description (threat model + mitigations).

Example commit message

test: cover pair lifecycle events and idempotency edges

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

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions