Skip to content

Add tests for get_usage_batch ordering, defaults, and the BatchTooLarge bound #96

Description

@mikewheeleer

Test the batched usage read and its MAX_BATCH_READ guard

Description

get_usage_batch in contracts/escrow/src/lib.rs returns one count per input (agent, service_id) pair, defaults unknown pairs to 0, preserves input order, and panics with BatchTooLarge (#16) above MAX_BATCH_READ (100). None of this is covered by contracts/escrow/src/test.rs — there is no test that the order is preserved, that duplicate pairs yield the same value at each position, or that the bound actually fires. This issue adds the missing coverage for this read.

Requirements and context

  • Repository scope: Agentpay-Org/Agentpay-contracts only.
  • Cover: results are returned in the exact order of the input pairs; unknown pairs return 0; a mix of known and unknown pairs maps positionally; duplicate pairs return the same value at each occurrence.
  • Cover: a batch of exactly MAX_BATCH_READ succeeds; MAX_BATCH_READ + 1 panics #16; an empty batch returns an empty Vec.
  • Assert that get_usage_batch and get_usage agree for every shared pair (no drift between the single and batched read paths).
  • Use #[should_panic(expected = "Error(Contract, #16)")]; test-only change unless a genuine bug surfaces.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b test/contracts-get-usage-batch-tests
  • Implement changes
    • Write code in: contracts/escrow/src/lib.rs — no changes expected; only touch if a bug is found.
    • Write comprehensive tests in: contracts/escrow/src/test.rs — the ordering, default, agreement, and bound scenarios above.
    • Add documentation: note the covered behaviour in the test module header comment.
    • Include NatSpec-style doc comments (///) on any test helpers.
    • Validate security: the read loop is bounded and cannot be forced past the cap.
  • Test and commit

Test and commit

  • Run cargo fmt --all -- --check, cargo build, and cargo test.
  • Cover edge cases: empty batch, single pair, exactly-at-bound, just-over-bound, all-unknown pairs.
  • Include the full cargo test output and a short security notes section in the PR description.

Example commit message

test: cover get_usage_batch ordering, defaults, and BatchTooLarge bound

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