Skip to content

test(settlement): cover the settle_all MAX_SETTLE_ALL boundary - #323

Merged
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
thlpkee20-wq:test/settlement-01-boundaries
Jul 28, 2026
Merged

test(settlement): cover the settle_all MAX_SETTLE_ALL boundary#323
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
thlpkee20-wq:test/settlement-01-boundaries

Conversation

@thlpkee20-wq

Copy link
Copy Markdown
Contributor

Closes #299

`record_usage` caps the per-agent service index at
`MAX_AGENT_SERVICE_INDEX` (== `MAX_SETTLE_ALL`), so `settle_all`'s
`SettleAllTooLarge` guard had zero test coverage — it can't be
reached through the public API alone (its own doc comment says as much:
it exists to protect a future migration that could write a larger
index).

Added two tests that write an oversized index directly via
`as_contract`, mirroring the existing `..._via_storage_helper` pattern
used for other invariants in this file:

A real finding along the way

The exactly-at-boundary test needed `env.budget().reset_unlimited()` —
settling 256 services in one call (2 storage reads + 2 writes + 1 event
each) exceeded the default test budget around service #178. That's a
test-harness-only accommodation for this PR, but it's a genuine signal:
a `settle_all` call anywhere near the configured `MAX_SETTLE_ALL` would
likely also exceed real network resource limits on-chain. Flagging this
as worth a follow-up look at whether `MAX_SETTLE_ALL` should be
tightened — that's a behavior change I did not make here, out of scope
for a test-coverage PR.

Test plan

record_usage caps the per-agent service index at MAX_AGENT_SERVICE_INDEX
(== MAX_SETTLE_ALL), so settle_all's SettleAllTooLarge guard had zero
test coverage: it can't be reached through the public API alone (it
exists to protect a future migration that could write a larger index).
Added two tests that write an oversized index directly via
`as_contract`, mirroring the existing `..._via_storage_helper` pattern:

- exactly-at-boundary (256 services): succeeds, settles all of them.
- one-over-boundary (257 services): panics with SettleAllTooLarge (Agentpay-Org#19).

Note: the exactly-at-boundary test needs env.budget().reset_unlimited()
— settling 256 services in one call (2 storage reads + 2 writes + 1
event each) exceeds the default test budget around service Agentpay-Org#178. This
is a test-harness-only accommodation, but it's a real signal: a
settle_all call anywhere near the configured MAX_SETTLE_ALL would likely
also exceed real network resource limits on-chain. Worth a follow-up
look at whether MAX_SETTLE_ALL should be tightened, separate from this
test-coverage change.
@mikewheeleer

Copy link
Copy Markdown
Contributor

neat work @thlpkee20-wq — thanks for the care. merging 🌱

@mikewheeleer
mikewheeleer merged commit c81e6b3 into Agentpay-Org:main Jul 28, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add boundary tests for the settlement logic

2 participants