Test the record_usage event and UsageRecord return semantics
Description
record_usage in contracts/escrow/src/lib.rs emits a usage(agent, service_id, requests, total) event and returns a UsageRecord carrying the new total (not the delta), per its doc comment. contracts/escrow/src/test.rs does not assert the emitted event payload nor that the returned requests field equals the accumulated total rather than the per-call delta. This issue verifies both the event and the documented return contract.
Requirements and context
- Repository scope:
Agentpay-Org/Agentpay-contracts only.
- Cover: after
record_usage(agent, svc, n), the returned UsageRecord.requests equals the accumulated total (e.g. two calls of 3 then 5 return 8, not 5); the event payload's requests field is the per-call delta while the total field is the running total.
- Cover: the
usage event topic and tuple are emitted exactly once per call via env.events().all().
- Cover: lifetime counters (
get_total_usage_by_agent, get_total_requests_all_time) advance by the delta on each call.
- Test-only change unless a genuine bug surfaces.
Suggested execution
- Fork the repo and create a branch
git checkout -b test/contracts-record-usage-event-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 return-value, event-payload, and lifetime-counter scenarios above.
- Add documentation: note the covered contract in the test module header comment.
- Include NatSpec-style doc comments (
///) on any test helpers.
- Validate security: the recorded total and emitted event agree, so off-chain loops cannot be misled.
- Test and commit
Test and commit
- Run
cargo fmt --all -- --check, cargo build, and cargo test.
- Cover edge cases: first call, repeated calls accumulating, multi-service isolation, single large delta.
- Include the full
cargo test output and a short security notes section in the PR description.
Example commit message
test: cover record_usage event payload and new-total return contract
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.
Test the record_usage event and UsageRecord return semantics
Description
record_usageincontracts/escrow/src/lib.rsemits ausage(agent, service_id, requests, total)event and returns aUsageRecordcarrying the new total (not the delta), per its doc comment.contracts/escrow/src/test.rsdoes not assert the emitted event payload nor that the returnedrequestsfield equals the accumulated total rather than the per-call delta. This issue verifies both the event and the documented return contract.Requirements and context
Agentpay-Org/Agentpay-contractsonly.record_usage(agent, svc, n), the returnedUsageRecord.requestsequals the accumulated total (e.g. two calls of 3 then 5 return 8, not 5); the event payload'srequestsfield is the per-call delta while thetotalfield is the running total.usageevent topic and tuple are emitted exactly once per call viaenv.events().all().get_total_usage_by_agent,get_total_requests_all_time) advance by the delta on each call.Suggested execution
git checkout -b test/contracts-record-usage-event-testscontracts/escrow/src/lib.rs— no changes expected; only touch if a bug is found.contracts/escrow/src/test.rs— the return-value, event-payload, and lifetime-counter scenarios above.///) on any test helpers.Test and commit
cargo fmt --all -- --check,cargo build, andcargo test.cargo testoutput and a short security notes section in the PR description.Example commit message
test: cover record_usage event payload and new-total return contractGuidelines
Community & contribution rewards