1

When I try to run my tests with cargo test-bpf, I get this error:

thread 'processor::tests::it_works' panicked at 'Program file data not available for program_name (...)'

This is my test code:

#[cfg(test)]
mod tests {
    use {
        super::*,
        assert_matches::*,
        solana_program::{
            instruction::{AccountMeta, Instruction},
            system_program::ID as SYSTEM_PROGRAM_ID,
        },
        solana_program_test::*,
        solana_sdk::{
            signature::Signer, sysvar::rent::ID as SYSVAR_RENT_ID, transaction::Transaction, signer::keypair::Keypair
        },
        spl_associated_token_account::{
            get_associated_token_address, instruction::create_associated_token_account,
        },
        spl_token::ID as TOKEN_PROGRAM_ID,
    };

    #[tokio::test]
    async fn it_works() {
        let program_id = Pubkey::new_unique();

        let (mut banks_client, payer, recent_blockhash) = ProgramTest::new(
            "program_name",
            program_id,
            processor!(process_instruction),
        )
        .start()
        .await;

        let test_acct = Keypair::new();

        let mut transaction = Transaction::new_with_payer(
            &[Instruction {
                program_id,
                accounts: vec![
                    AccountMeta::new(payer.pubkey(), true),
                    AccountMeta::new(test_acct.pubkey(), true)
                ],
                data: vec![1, 2, 3],
            }],
            Some(&payer.pubkey()),
        );
        transaction.sign(&[&payer, &test_acct], recent_blockhash);

        assert_matches!(banks_client.process_transaction(transaction).await, Ok(_));

    }
}
1
  • What's ProgramTest
    – vicyyn
    Commented Dec 25, 2022 at 17:09

1 Answer 1

2

You must put the right Program Name in this line:

   let (mut banks_client, payer, recent_blockhash) = ProgramTest::new(
     "program_name",
     program_id,
     processor!(process_instruction),
   )

Probably the correct program name is the name of the file in the target/deploy/ folder of your project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.