2

Based on the code here I am trying to run an integration test using the solana_program_test crate.

The integration test code I am executing is as follows:

#![feature(backtrace)]
#![cfg(feature = "test-bpf")]
#[cfg(test)]
use {
    solana_program::{pubkey::Pubkey, system_program},
    solana_program_test::ProgramTest,
    solana_sdk::signature::{Keypair, Signer},
};

#[test]
fn test_echo() {
    let program_id = Pubkey::new_unique();
    let mut program_test = ProgramTest::default();
    program_test.add_program("echo", program_id, None);

    let auth = Keypair::new();
    program_test.add_account(
        auth.pubkey(),
        solana_sdk::account::Account {
            lamports: 100_000_000_000,
            data: vec![],
            owner: system_program::id(),
            ..solana_sdk::account::Account::default()
        },
    );
    // INSERT TESTS HERE
}

When I execute the test by running:

cargo test --package bpf-program-template --test integration_test test_echo --features "test-bpf" -- --exact

I get the following error:

-- snipped --

---- test_echo stdout ----
thread 'test_echo' panicked at 'Program processor not available for echo (4uQeVj5tqViQh7yWWGStvkEG1Zmhx6uasJtWCJziofM)', /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/solana-program-test-1.11.1/src/lib.rs:671:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

-- snipped --

Any idea on how to fix it? Could not get much info on the solana_program_test crate as it seems not to be documented that much.

3 Answers 3

1

You should add the entry in the third argument of the program_test.add_program method as following:

let mut program = ProgramTest::default();
program.add_program("<program_name>", <program_name>::id(), processor!(<program_name>::entry));

Replace <program_name> with the name of your program, the one defined in Cargo.toml > [package] > name. In this case I think you can use "echo".

After the changes, execute using cargo test-bpf.

0

For me, I needed to define the env variable BPF_OUT_DIR to the location of my .so file, and as my test program was adding multiple programs I made sure to include each one. I found this by reading here: https://docs.rs/solana-program-test/latest/src/solana_program_test/lib.rs.html#415

example commands:

$ export BPF_OUT_DIR=/home/lando/projects/mpl/mpl/test-programs

$ pwd

/home/lando/projects/mpl/mpl/auction-house/program

$ cargo test --features='test-bpf' --test buy

success.

0

Not all solana programs expose an entrypoint that works with ProcessInstructionWithContext. However, instead of

cargo test

you can use

cargo test-sbf

With test-sbf everything should work out of the box and you don't even need to call add_program on your ProgramTest instance.

I believe cargo test-sbf is the canonical way of running rust tests for solana programs at the moment, perhaps somebody wiser than me can comment on what it actually does under the hood.

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.