Test compute_billing's multiplication and zero/saturation behaviour
Description
compute_billing in contracts/escrow/src/lib.rs returns accumulated_requests * price_per_request with saturating_mul, returns 0 when either side is zero, and is the read-only mirror of the math inside settle. contracts/escrow/src/test.rs does not directly test compute_billing across its cases — zero usage, zero price (free service), a normal product, and the saturation edge. This issue adds focused coverage and verifies compute_billing agrees with the billed value settle would return for the same state.
Requirements and context
- Repository scope:
Agentpay-Org/Agentpay-contracts only.
- Cover: zero usage →
0; zero price (free service) → 0; a normal requests * price product computed correctly; an unpriced and unused pair → 0.
- Cover the saturation edge: a large
requests × large price saturates at i128::MAX rather than overflowing.
- Cover that
compute_billing(agent, svc) equals the value settle returns for the same pre-settle state (drive the state, read compute_billing, then settle and compare).
- Test-only change unless a genuine bug surfaces.
Suggested execution
- Fork the repo and create a branch
git checkout -b test/contracts-compute-billing-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 zero, free, product, saturation, and settle-agreement scenarios above.
- Add documentation: note the covered billing math in the test module header comment.
- Include NatSpec-style doc comments (
///) on any test helpers.
- Validate security: billing math never overflows and the read mirrors settlement.
- Test and commit
Test and commit
- Run
cargo fmt --all -- --check, cargo build, and cargo test.
- Cover edge cases: zero usage, zero price, large product, saturated product, compute-vs-settle equality.
- Include the full
cargo test output and a short security notes section in the PR description.
Example commit message
test: cover compute_billing free, priced, and saturated cases
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 compute_billing's multiplication and zero/saturation behaviour
Description
compute_billingincontracts/escrow/src/lib.rsreturnsaccumulated_requests * price_per_requestwithsaturating_mul, returns0when either side is zero, and is the read-only mirror of the math insidesettle.contracts/escrow/src/test.rsdoes not directly testcompute_billingacross its cases — zero usage, zero price (free service), a normal product, and the saturation edge. This issue adds focused coverage and verifiescompute_billingagrees with thebilledvaluesettlewould return for the same state.Requirements and context
Agentpay-Org/Agentpay-contractsonly.0; zero price (free service) →0; a normalrequests * priceproduct computed correctly; an unpriced and unused pair →0.requests× largepricesaturates ati128::MAXrather than overflowing.compute_billing(agent, svc)equals the valuesettlereturns for the same pre-settle state (drive the state, readcompute_billing, thensettleand compare).Suggested execution
git checkout -b test/contracts-compute-billing-testscontracts/escrow/src/lib.rs— no changes expected; only touch if a bug is found.contracts/escrow/src/test.rs— the zero, free, product, saturation, and settle-agreement 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 compute_billing free, priced, and saturated casesGuidelines
Community & contribution rewards