Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lang: associated_token constraints don't work when setting token_program #2603

Merged
merged 8 commits into from
Aug 23, 2023
2 changes: 1 addition & 1 deletion lang/syn/src/codegen/accounts/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ fn generate_constraint_init_group(
return Err(anchor_lang::error::Error::from(anchor_lang::error::ErrorCode::ConstraintAssociatedTokenTokenProgram).with_account_name(#name_str).with_pubkeys((*owner_program, #token_program.key())));
}

if pa.key() != ::anchor_spl::associated_token::get_associated_token_address(&#owner.key(), &#mint.key()) {
if pa.key() != ::anchor_spl::associated_token::get_associated_token_address_with_program_id(&#owner.key(), &#mint.key(), &#token_program.key()) {
return Err(anchor_lang::error::Error::from(anchor_lang::error::ErrorCode::AccountNotAssociatedTokenAccount).with_account_name(#name_str));
}
}
Expand Down
15 changes: 8 additions & 7 deletions tests/misc/programs/misc-optional/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::account::*;
use anchor_lang::prelude::*;
use anchor_spl::associated_token::AssociatedToken;
use anchor_spl::token::{Mint, Token, TokenAccount};
use anchor_spl::token_interface::{Mint as MintInterface, TokenAccount as TokenAccountInterface};

#[derive(Accounts)]
pub struct TestTokenSeedsInit<'info> {
Expand Down Expand Up @@ -55,8 +56,8 @@ pub struct TestInitAssociatedTokenWithTokenProgram<'info> {
associated_token::authority = payer,
associated_token::token_program = associated_token_token_program,
)]
pub token: Option<Account<'info, TokenAccount>>,
pub mint: Option<Account<'info, Mint>>,
pub token: Option<InterfaceAccount<'info, TokenAccountInterface>>,
pub mint: Option<InterfaceAccount<'info, MintInterface>>,
#[account(mut)]
pub payer: Option<Signer<'info>>,
pub system_program: Option<Program<'info, System>>,
Expand Down Expand Up @@ -268,7 +269,7 @@ pub struct TestInitMintWithTokenProgram<'info> {
mint::freeze_authority = payer,
mint::token_program = mint_token_program,
)]
pub mint: Option<Account<'info, Mint>>,
pub mint: Option<InterfaceAccount<'info, MintInterface>>,
#[account(mut)]
pub payer: Option<Signer<'info>>,
pub system_program: Option<Program<'info, System>>,
Expand Down Expand Up @@ -465,8 +466,8 @@ pub struct TestInitAssociatedTokenIfNeededWithTokenProgram<'info> {
associated_token::authority = authority,
associated_token::token_program = associated_token_token_program,
)]
pub token: Option<Account<'info, TokenAccount>>,
pub mint: Option<Account<'info, Mint>>,
pub token: Option<InterfaceAccount<'info, TokenAccountInterface>>,
pub mint: Option<InterfaceAccount<'info, MintInterface>>,
#[account(mut)]
pub payer: Option<Signer<'info>>,
pub system_program: Option<Program<'info, System>>,
Expand Down Expand Up @@ -711,8 +712,8 @@ pub struct TestAssociatedTokenWithTokenProgramConstraint<'info> {
associated_token::authority = authority,
associated_token::token_program = associated_token_token_program,
)]
pub token: Option<Account<'info, TokenAccount>>,
pub mint: Account<'info, Mint>,
pub token: Option<InterfaceAccount<'info, TokenAccountInterface>>,
pub mint: InterfaceAccount<'info, MintInterface>,
/// CHECK: ignore
pub authority: AccountInfo<'info>,
/// CHECK: ignore
Expand Down
15 changes: 8 additions & 7 deletions tests/misc/programs/misc/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::account::*;
use anchor_lang::prelude::*;
use anchor_spl::associated_token::AssociatedToken;
use anchor_spl::token::{Mint, Token, TokenAccount};
use anchor_spl::token_interface::{Mint as MintInterface, TokenAccount as TokenAccountInterface};

#[derive(Accounts)]
pub struct TestTokenSeedsInit<'info> {
Expand Down Expand Up @@ -56,8 +57,8 @@ pub struct TestInitAssociatedTokenWithTokenProgram<'info> {
associated_token::authority = payer,
associated_token::token_program = associated_token_token_program,
)]
pub token: Account<'info, TokenAccount>,
pub mint: Account<'info, Mint>,
pub token: InterfaceAccount<'info, TokenAccountInterface>,
pub mint: InterfaceAccount<'info, MintInterface>,
#[account(mut)]
pub payer: Signer<'info>,
pub system_program: Program<'info, System>,
Expand Down Expand Up @@ -267,7 +268,7 @@ pub struct TestInitMintWithTokenProgram<'info> {
mint::freeze_authority = payer,
mint::token_program = mint_token_program,
)]
pub mint: Account<'info, Mint>,
pub mint: InterfaceAccount<'info, MintInterface>,
#[account(mut)]
pub payer: Signer<'info>,
pub system_program: Program<'info, System>,
Expand Down Expand Up @@ -472,8 +473,8 @@ pub struct TestInitAssociatedTokenIfNeededWithTokenProgram<'info> {
associated_token::authority = authority,
associated_token::token_program = associated_token_token_program,
)]
pub token: Account<'info, TokenAccount>,
pub mint: Account<'info, Mint>,
pub token: InterfaceAccount<'info, TokenAccountInterface>,
pub mint: InterfaceAccount<'info, MintInterface>,
#[account(mut)]
pub payer: Signer<'info>,
pub system_program: Program<'info, System>,
Expand Down Expand Up @@ -727,8 +728,8 @@ pub struct TestAssociatedTokenWithTokenProgramConstraint<'info> {
associated_token::authority = authority,
associated_token::token_program = associated_token_token_program,
)]
pub token: Account<'info, TokenAccount>,
pub mint: Account<'info, Mint>,
pub token: InterfaceAccount<'info, TokenAccountInterface>,
pub mint: InterfaceAccount<'info, MintInterface>,
/// CHECK: ignore
pub authority: AccountInfo<'info>,
/// CHECK: ignore
Expand Down
Loading
Loading