Skip to content

Add tests for lifetime usage counters and last-settlement timestamps #19

@mikewheeleer

Description

@mikewheeleer

Test lifetime counters and settlement-time tracking

Description

TotalUsageByAgent, TotalRequestsAllTime, and LastSettlement in contracts/escrow/src/lib.rs (read via get_total_usage_by_agent, get_total_requests_all_time, get_last_settlement) are completely untested in contracts/escrow/src/test.rs. The contract's documented invariant — that settle drains per-pair usage but does not reset lifetime counters — is unverified. This issue locks that invariant down with tests.

Requirements and context

  • Repository scope: Agentpay-Org/Agentpay-contracts only.
  • Cover: cross-service accumulation into TotalUsageByAgent; protocol-wide TotalRequestsAllTime summing across agents; both survive settle.
  • Cover: get_last_settlement returns None before any settle and Some(timestamp) after, using env.ledger().with_mut to control the clock.
  • Assert the documented distinction between None and Some(0).
  • Test-only change unless a genuine bug surfaces.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b test/contracts-19-lifetime-counter-tests
  • Implement changes
    • Write code in: contracts/escrow/src/lib.rs — no changes expected.
    • Write comprehensive tests in: contracts/escrow/src/test.rs — the counter/timestamp scenarios above.
    • Add documentation: note covered invariants in the test module header.
    • Include NatSpec-style doc comments (///) on any test helpers.
    • Validate security: settlement never silently loses lifetime analytics.
  • Test and commit

Test and commit

  • Run cargo fmt --all -- --check, cargo build, and cargo test.
  • Cover edge cases: multiple agents, settle then re-record, never-settled pair.
  • Include the full cargo test output and a short security notes section in the PR description.

Example commit message

test: cover lifetime usage counters and last-settlement timestamps

Guidelines

  • Minimum 95 percent test coverage for impacted modules.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the AgentPay community on Discord for questions, reviews, and faster merges: https://discord.gg/eXvRKkgcv
  • ⭐ 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
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions