Skip to content

test(example): pin the buyer gate on register_with - #15

Merged
0dillon merged 1 commit into
ledgerkeep:mainfrom
ogundeleoluwaferanmi35:test/register-with-buyer-auth-gate
Aug 7, 2026
Merged

test(example): pin the buyer gate on register_with#15
0dillon merged 1 commit into
ledgerkeep:mainfrom
ogundeleoluwaferanmi35:test/register-with-buyer-auth-gate

Conversation

@ogundeleoluwaferanmi35

Copy link
Copy Markdown
Contributor

Closes #12

Summary

The existing register_with_needs_the_buyers_authorization test removes all
authorizations (env.set_auths(&[])) and asserts the call fails. That only proves some
authorization is required, not that it is the buyer's — it would pass unchanged if the gate
were config.seller.require_auth() or any other address in EscrowConfig. Since the buyer gate is
what stops an arbitrary caller from publishing a manifest under the escrow's address, this PR pins
it with tests that exercise specific addresses.

What changed

Two new tests in examples/long_escrow/src/test.rs, using the SDK's mock_auths (which replaces
the fixture's blanket mock_all_auths with a specific list of authorized addresses):

  • register_with_rejects_non_buyer_authorizations — authorizes the seller and a wholly
    unrelated generated address, but not the buyer, and asserts register_with still fails and
    never reaches the registry.
  • register_with_succeeds_with_only_the_buyers_authorization — authorizes only the buyer and
    asserts register_with succeeds and the registry records the escrow.

The existing set_auths(&[]) test is untouched and still covers the no-auth case.

Key design decisions

  • Used mock_auths rather than hand-built set_auths XDR entries: it registers the no-op
    MockAuthContract at each address, which is how Void-signature credentials are accepted in
    enforcing mode. It also disables the mock_all_auths from the fixture, so a success result is
    genuinely attributable to the authorized address alone.
  • A small register_with_invocation helper builds the mocked MockAuthInvoke. buyer.require_auth()
    (no args) authorizes the current frame, so the entry must name the escrow, the function, and
    exactly the arguments the call passes — using the same .into_val() conversions the generated
    client uses, so the frames compare equal.
  • The registry cross-call succeeds in the buyer-only test because the fake registry's
    contract.require_auth() is satisfied by the invoker check (the escrow is the caller), not by a
    second auth entry.

Acceptance criteria

  • A test authorizes the seller + a wholly unrelated address and asserts register_with still fails — register_with_rejects_non_buyer_authorizations
  • A test authorizes the buyer specifically (not all auths) and asserts success — register_with_succeeds_with_only_the_buyers_authorization
  • Changing the gate to any other EscrowConfig address makes at least one test fail — verified locally by temporarily setting config.seller.require_auth(): both new tests failed; reverted before submitting
  • The existing set_auths(&[]) test stays

Checks

All four CI checks pass locally:

cargo fmt --all -- --check          # clean
cargo clippy --all-targets -- -D warnings   # clean
cargo test --all                    # 26 passed (7 in long_escrow, incl. 2 new)
stellar contract build              # build complete

Follow-ups

None. The change is limited to test-only code in examples/long_escrow.

Security note

Test-only change; no production logic touched. No secrets or environment variables involved.

@0dillon
0dillon merged commit 840950a into ledgerkeep:main Aug 7, 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.

test(example): assert register_with rejects a caller who is not the buyer

2 participants