Skip to content

test: cover agent allowlist enforcement in record_usage#74

Merged
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
greatest0fallt1me:test/contracts-16-allowlist-tests
Jun 24, 2026
Merged

test: cover agent allowlist enforcement in record_usage#74
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
greatest0fallt1me:test/contracts-16-allowlist-tests

Conversation

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

Closes #16.

Summary

The allowlist logic in record_usage (and set_allowlist_enabled / set_agent_allowed / is_agent_allowed) had no enforcement coverage — nothing asserted that an off-allowlist agent is rejected with AgentNotAllowed (#10) or that disabling the gate restores access. This closes that gap.

Tests added (test-only; no contract logic changed)

  • test_allowlist_disabled_allows_any_agent — default (off) allows any agent.
  • test_allowlist_enabled_rejects_unlisted_agent — on + unlisted → #10.
  • test_allowlist_enabled_allows_listed_agent — on + listed → succeeds.
  • test_allowlist_revocation_reblocks_agent — allowed then revoked → #10.
  • test_allowlist_disable_restores_access — toggling the gate off restores access (uses try_record_usage).
  • test_allowlist_status_round_tripsis_allowlist_enabled / is_agent_allowed round-trips.
  • test_allowlist_mixed_agents — multiple agents, mixed status, handled independently.

#[should_panic(expected = "Error(Contract, #10)")] matches the existing test conventions. A module section comment documents the covered behaviour.

Verification

cargo fmt --all -- --check, cargo build, cargo test all green — 58 passed; 0 failed.

Security notes

The tests prove the gate cannot be bypassed: an unlisted agent is rejected, revocation re-blocks, and the gate is off only by explicit default.

Closes Agentpay-Org#16. The allowlist gate in record_usage (and set_allowlist_enabled
/ set_agent_allowed / is_agent_allowed) had no enforcement coverage. Add
focused tests: disabled gate allows any agent; enabled + unlisted →
AgentNotAllowed (Agentpay-Org#10); enabled + allowed → succeeds; allowed-then-revoked
re-blocks; is_allowlist_enabled / is_agent_allowed round-trips; disabling
the gate restores access; and multiple agents with mixed status. Test-only
change — no contract logic modified.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mikewheeleer mikewheeleer merged commit e632bf0 into Agentpay-Org:main Jun 24, 2026
1 check passed
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 agent allowlist enforcement path in record_usage

2 participants