Skip to content

test(basics/checking-accounts): assert the owner constraint rejects a foreign account - #729

Open
moviendome wants to merge 1 commit into
solana-foundation:mainfrom
moviendome:test/basics-checking-accounts-assertions
Open

test(basics/checking-accounts): assert the owner constraint rejects a foreign account#729
moviendome wants to merge 1 commit into
solana-foundation:mainfrom
moviendome:test/basics-checking-accounts-assertions

Conversation

@moviendome

Copy link
Copy Markdown
Contributor

Summary

basics/checking-accounts exists to teach the owner = id() constraint on account_to_change, but neither suite ever hands the program an account it does not own. Both specs pass a correctly-owned account, and since the handler body is Ok(()), the suite would stay green against a program that checks nothing.

This adds one negative spec to each suite (validator and LiteSVM): call check_accounts with a System-Program-owned account as account_to_change and assert the transaction is rejected with ConstraintOwner. The account used is accountToCreate, which the suite already declares and never creates, so no extra setup is needed.

The error assertion reuses the inline expectAnchorError helper already used by tokens/pda-mint-authority and tokens/token-fundraiser. No new dependencies; lockfile unchanged.

Test plan

  • anchor test at this commit: all specs pass in both suites (6 passing).
  • Red proof: with owner = id() removed from CheckingAccounts and the program rebuilt, the new spec fails in both suites with expected the transaction to fail with ConstraintOwner; every other spec still passes (2 failing, 4 passing). Constraint restored, back to green.
  • pnpm check (prettier) clean.

AI use

I identified the missing check while reading this example, decided the shape of the test, and reviewed the diff and both test runs; Claude drafted the code and this description.

🤖 Generated with Claude Code

… foreign account

Both suites only ever pass a correctly-owned account_to_change, so the
owner = id() constraint the example teaches was never exercised and the
suite stayed green against a handler that checks nothing. Add a negative
spec to the validator and LiteSVM suites that passes a System-Program-
owned account and asserts the ConstraintOwner rejection, using the same
inline expectAnchorError helper as pda-mint-authority and token-fundraiser.
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the new tests accurately exercise the intended owner constraint in both suites.

Summary

  • Passes a never-created, System Program-owned account as accountToChange.
  • Verifies that validator and LiteSVM transactions fail with ConstraintOwner.
  • Reuses the repository’s established Anchor error assertion pattern.

Reviews (1) · Last reviewed commit: "test(basics/checking-accounts): assert t..."

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.

1 participant