Skip to content

Commit

Permalink
Slightly fancier program_seed test.
Browse files Browse the repository at this point in the history
  • Loading branch information
cqfd committed Dec 27, 2021
1 parent cb02fbe commit ee911d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/misc/programs/misc/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,7 @@ pub struct TestConstArraySize<'info> {
pub struct TestProgramIdConstraint<'info> {
#[account(seeds = [b"seed"], bump, program_seed = anchor_spl::associated_token::ID)]
associated_token_account: AccountInfo<'info>,

#[account(seeds = [b"seed"], bump, program_seed = crate::ID)]
other_account: AccountInfo<'info>,
}
7 changes: 7 additions & 0 deletions tests/misc/tests/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1301,11 +1301,16 @@ describe("misc", () => {
});

it("Can validate PDAs derived from other program ids", async () => {
const [ourPda, ourPdaBump] = await anchor.web3.PublicKey.findProgramAddress(
[Buffer.from("seed")],
program.programId
);
const wrongAddress = anchor.web3.Keypair.generate().publicKey;
try {
await program.rpc.testProgramIdConstraint(123, {
accounts: {
associatedTokenAccount: wrongAddress,
otherAccount: ourPda,
},
});
assert.ok(false);
Expand All @@ -1322,6 +1327,7 @@ describe("misc", () => {
await program.rpc.testProgramIdConstraint(wrongBump, {
accounts: {
associatedTokenAccount: wrongProgramIdPDA,
otherAccount: ourPda,
},
});
assert.ok(false);
Expand All @@ -1337,6 +1343,7 @@ describe("misc", () => {
await program.rpc.testProgramIdConstraint(rightBump, {
accounts: {
associatedTokenAccount: rightProgramIdPDA,
otherAccount: ourPda,
},
});
});
Expand Down

0 comments on commit ee911d0

Please sign in to comment.