0
fn setup(program_id: &Pubkey, other_program_id: &Pubkey) -> ProgramTest {
    let mut program_test = ProgramTest::new(
        "program",
        *program_id,
        processor!(program::processor::process),
    );

    program_test.prefer_bpf(false); // simplicity in the build

    program_test.add_program(
        "other_program",
        other_program_id,
        processor!(other_program::processor::Processor::process),
    );

    program_test
}

When adding multiple program to ProgramTest context the test fails "multiple definition of entrypoint? If I use program::processor::process for the other_program, the test builds how do I resolve this conflict to be able to import both the entrypoints?

2 Answers 2

0

The error "multiple definition of entrypoint" means that the symbol entrypoint exists multiple times in your package. This happens when one of the crates that your program depends on also has the entrypoint function defined.

To fix this, be sure to import all programs with the no-entrypoint macro, as described in https://docs.rs/solana-program/latest/solana_program/macro.entrypoint.html#cargo-features

So for example, if you're importing spl-token, in your Cargo.toml, you need to declare it as:

spl-token = { version = "4.0",  path = "../program", features = ["no-entrypoint"] }
-1

To resolve this issue, you can use different entrypoint names for each program. In Rust, the entrypoint is a function with a specific signature, and it's identified by its name. Here's an example of how you can modify your code to use distinct entrypoint names for each program:

// Assuming your entrypoints are defined like this:

// program/src/processor.rs
pub fn process(program_id: &Pubkey, accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult {
    // Your program logic here
    Ok(())
}

// other_program/src/processor.rs
pub fn process(program_id: &Pubkey, accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult {
    // Your other program logic here
    Ok(())
}

// In your setup function:

fn setup(program_id: &Pubkey, other_program_id: &Pubkey) -> ProgramTest {
    let mut program_test = ProgramTest::new(
        "program",
        *program_id,
        processor!(program::processor::process), // Use the entrypoint name for the first program
    );

    program_test.prefer_bpf(false);

    program_test.add_program(
        "other_program",
        other_program_id,
        processor!(other_program::processor::process), // Use a different entrypoint name for the other program
    );

    program_test
}

By using distinct entrypoint names (process for the first program and, let's say, other_process for the other program), you should avoid conflicts in the ProgramTest context. Ensure that you update the function names in your actual Rust code accordingly.

Also, make sure to update the Cargo.toml files of both programs to reflect the correct entrypoint names under [entrypoint] if you are using the solana_sdk crate.

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.