Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add solana-program-test compatibility test in CI #2738

Open
acheroncrypto opened this issue Dec 18, 2023 · 4 comments · May be fixed by #2841
Open

Add solana-program-test compatibility test in CI #2738

acheroncrypto opened this issue Dec 18, 2023 · 4 comments · May be fixed by #2841
Labels

Comments

@acheroncrypto
Copy link
Collaborator

Problem

The expected entrypoint lifetimes in solana-program-test is not compatible with the 0.29.0 release due to the changes in #2656 but we have no tests for this case in CI.

Solution

Add a simple test to check the compatibility between anchor-lang and solana-program-test.

Related: #2711

@dfy313
Copy link

dfy313 commented Mar 14, 2024

Hey! I'm interested in working on this issue and have explored an approach for compatibility testing in this draft PR: #2841. Does this align with the solution you had in mind?

@denisglotov
Copy link

Hey! Is there any solution? I bumped into this one type is more general than the other problem too.

@ifiokjr
Copy link

ifiokjr commented Jul 15, 2024

@denisglotov this is a wrapper I'm using which seems to suppress the warnings. The program I'm testing is called kickjump_launchpad.

use kickjump_launchpad::ID_CONST;
use solana_program::account_info::AccountInfo;
use solana_program::entrypoint::ProgramResult;
use solana_program::pubkey::Pubkey;
use solana_program_test::processor;
use solana_program_test::ProgramTest;

pub fn add_program() -> ProgramTest {
	ProgramTest::new("kickjump_launchpad", ID_CONST, processor!(entry))
}

/// This is a wrapper to get the processor macro to work.
fn entry(program_id: &Pubkey, accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult {
	let accounts = Box::leak(Box::new(accounts.to_vec()));

	kickjump_launchpad::entry(program_id, accounts, instruction_data)
}

@ifiokjr
Copy link

ifiokjr commented Jul 16, 2024

I've added the following workaround to my own codebase for testing. Would it be useful to others?

If so, I can create a pull request.

/// The current processor for [`solana_program_test`] doesn't support anchor
/// programs due to lifetime conflicts. This is a wrapper that supports the
/// anchor lifetimes by using [`Box::leak`] on the accounts array.
#[macro_export]
macro_rules! anchor_processor {
	($program:ident) => {{
		fn entry(
			program_id: &::solana_program::pubkey::Pubkey,
			accounts: &[::solana_program::account_info::AccountInfo],
			instruction_data: &[u8],
		) -> ::solana_program::entrypoint::ProgramResult {
			let accounts = Box::leak(Box::new(accounts.to_vec()));

			$program::entry(program_id, accounts, instruction_data)
		}

		::solana_program_test::processor!(entry)
	}};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants