I'm having some issues with running tests locally against a program I created. Its based off mint_nft.rs from this repo but I've updated it to use the token_2022 program.
use anchor_lang::prelude::*;
use anchor_spl::metadata::mpl_token_metadata::{
instructions::{
CreateMasterEditionV3Cpi, CreateMasterEditionV3CpiAccounts,
CreateMasterEditionV3InstructionArgs, CreateMetadataAccountV3Cpi,
CreateMetadataAccountV3CpiAccounts, CreateMetadataAccountV3InstructionArgs,
},
types::{CollectionDetails, Creator, DataV2},
};
use anchor_spl::{
associated_token::AssociatedToken,
metadata::Metadata,
token_2022,
token_interface::{Mint, Token2022, TokenAccount},
};
#[derive(Accounts)]
pub struct CreateCollection<'info> {
#[account(mut)]
user: Signer<'info>,
#[account(
init,
payer = user,
mint::decimals = 0,
mint::authority = mint_authority,
mint::freeze_authority = mint_authority,
)]
mint: InterfaceAccount<'info, Mint>,
#[account(
seeds = [b"authority"],
bump,
)]
/// CHECK: This account is not initialized and is being used for signing purposes only
pub mint_authority: UncheckedAccount<'info>,
#[account(mut)]
/// CHECK: This account will be initialized by the metaplex program
metadata: UncheckedAccount<'info>,
#[account(mut)]
/// CHECK: This account will be initialized by the metaplex program
master_edition: UncheckedAccount<'info>,
#[account(
init,
payer = user,
associated_token::mint = mint,
associated_token::authority = user
)]
destination: InterfaceAccount<'info, TokenAccount>,
system_program: Program<'info, System>,
token_program: Program<'info, Token2022>,
associated_token_program: Program<'info, AssociatedToken>,
token_metadata_program: Program<'info, Metadata>,
}
impl<'info> CreateCollection<'info> {
pub fn create_collection(&mut self, bumps: &CreateCollectionBumps) -> Result<()> {
let metadata = &self.metadata.to_account_info();
let master_edition = &self.master_edition.to_account_info();
let mint = &self.mint.to_account_info();
let authority = &self.mint_authority.to_account_info();
let payer = &self.user.to_account_info();
let system_program = &self.system_program.to_account_info();
let spl_token_program = &self.token_program.to_account_info();
let spl_metadata_program = &self.token_metadata_program.to_account_info();
let seeds = &[&b"authority"[..], &[bumps.mint_authority]];
let signer_seeds = &[&seeds[..]];
let cpi_program = self.token_program.to_account_info();
let cpi_accounts = token_2022::MintTo {
mint: self.mint.to_account_info(),
to: self.destination.to_account_info(),
authority: self.mint_authority.to_account_info(),
};
let cpi_ctx = CpiContext::new_with_signer(cpi_program, cpi_accounts, signer_seeds);
token_2022::mint_to(cpi_ctx, 1)?;
msg!("Collection NFT minted!");
let creator = vec![Creator {
address: self.mint_authority.key().clone(),
verified: true,
share: 100,
}];
let metadata_account = CreateMetadataAccountV3Cpi::new(
spl_metadata_program,
CreateMetadataAccountV3CpiAccounts {
metadata,
mint,
mint_authority: authority,
payer,
update_authority: (authority, true),
system_program,
rent: None,
},
CreateMetadataAccountV3InstructionArgs {
data: DataV2 {
name: "DummyCollection".to_owned(),
symbol: "DC".to_owned(),
uri: "".to_owned(),
seller_fee_basis_points: 0,
creators: Some(creator),
collection: None,
uses: None,
},
is_mutable: true,
collection_details: Some(CollectionDetails::V1 { size: 0 }),
},
);
metadata_account.invoke_signed(signer_seeds)?;
msg!("Metadata Account created!");
let master_edition_account: CreateMasterEditionV3Cpi = CreateMasterEditionV3Cpi::new(
spl_metadata_program,
CreateMasterEditionV3CpiAccounts {
edition: master_edition,
update_authority: authority,
mint_authority: authority,
mint,
payer,
metadata,
token_program: spl_token_program,
system_program,
rent: None,
},
CreateMasterEditionV3InstructionArgs {
max_supply: Some(0),
},
);
master_edition_account.invoke_signed(signer_seeds)?;
msg!("Master Edition Account created");
Ok(())
}
}
My test file is practically the same as the repo but this is with TOKEN_2022_PROGRAM_ID
being passed into token program here
I can deploy the program so I feel like maybe it's some config issue with my Anchor.toml
maybe.
error logs:
1) mint-nft
Create Collection NFT:
Error:
at Function.parse (node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@coral-xyz/anchor/src/error.ts:250:14)
at translateError (node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@coral-xyz/anchor/src/error.ts:282:37)
at MethodsBuilder.rpc [as _rpcFn] (node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@coral-xyz/anchor/src/program/namespace/rpc.ts:35:29)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
2) mint-nft
Mint NFT:
Error:
at Function.parse (node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@coral-xyz/anchor/src/error.ts:250:14)
at translateError (node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@coral-xyz/anchor/src/error.ts:282:37)
at MethodsBuilder.rpc [as _rpcFn] (node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@coral-xyz/anchor/src/program/namespace/rpc.ts:35:29)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
3) mint-nft
Verify Collection:
Error:
at Function.parse (node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@coral-xyz/anchor/src/error.ts:250:14)
at translateError (node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@coral-xyz/anchor/src/error.ts:282:37)
at MethodsBuilder.rpc [as _rpcFn] (node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@coral-xyz/anchor/src/program/namespace/rpc.ts:35:29)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
error Command failed with exit code 3.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Here is the repo if you would like to try it out locally, https://github.com/rtwhite10/token_2022_nft
Appreciate any advice, thanks!!