Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 7961

Token_2022 and mpl_token_metadata test issues

$
0
0

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.

Appreciate any advice, thanks!!


Viewing all articles
Browse latest Browse all 7961

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>