Skip to content

test: cover settle event payload and drain-to-zero invariant - #51

Merged
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
Jagadeeshftw:test/contracts-settle-event-invariants
Jun 24, 2026
Merged

test: cover settle event payload and drain-to-zero invariant#51
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
Jagadeeshftw:test/contracts-settle-event-invariants

Conversation

@Jagadeeshftw

Copy link
Copy Markdown
Contributor

Summary

Adds test-only coverage (in contracts/escrow/src/test.rs) for the settlement path invariants:

  • After settle, the per-(agent, service) usage counter drains to 0 and get_last_settlement returns Some(ts) matching a clock set via env.ledger().with_mut.
  • The billed value returned by settle equals compute_billing for the same pre-settle state.
  • settle emits a settled event with payload (agent, service_id, requests, billed).
  • record_usage emits a usage event with payload (agent, service_id, requests, total).
  • Settling a zero-usage pair returns 0, still stamps LastSettlement, and still emits a settled event.

A module header comment documents the covered invariants. No changes to lib.rs.

Closes #40

Test output

test result: ok. 28 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.22s

Security notes: Test-only change; no contract logic, storage layout, or auth surface is modified.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Jagadeeshftw
Jagadeeshftw force-pushed the test/contracts-settle-event-invariants branch from 278abf4 to 8756b40 Compare June 24, 2026 02:30
@mikewheeleer

Copy link
Copy Markdown
Contributor

nice, the settle drain-to-zero invariant deserves a test. lgtm

@mikewheeleer
mikewheeleer merged commit a7ca362 into Agentpay-Org:main Jun 24, 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 tests for the settled event payload and the post-settle drain-to-zero invariant

2 participants