diff --git a/program/src/lib.rs b/program/src/lib.rs index f4b96885e..20a741264 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -5,7 +5,7 @@ use solana_program::{ solana_program::declare_id!("BpfProgram1111111111111111111111111111111111"); entrypoint!(process_instruction); -fn process_instruction( +pub fn process_instruction( program_id: &Pubkey, accounts: &[AccountInfo], instruction_data: &[u8], @@ -18,39 +18,3 @@ fn process_instruction( ); Ok(()) } - -#[cfg(test)] -mod test { - use { - super::*, - assert_matches::*, - solana_program::instruction::{AccountMeta, Instruction}, - solana_program_test::*, - solana_sdk::{signature::Signer, transaction::Transaction}, - }; - - #[tokio::test] - async fn test_transaction() { - let program_id = Pubkey::new_unique(); - - let (mut banks_client, payer, recent_blockhash) = ProgramTest::new( - "bpf_program_template", - program_id, - processor!(process_instruction), - ) - .start() - .await; - - let mut transaction = Transaction::new_with_payer( - &[Instruction { - program_id, - accounts: vec![AccountMeta::new(payer.pubkey(), false)], - data: vec![1, 2, 3], - }], - Some(&payer.pubkey()), - ); - transaction.sign(&[&payer], recent_blockhash); - - assert_matches!(banks_client.process_transaction(transaction).await, Ok(())); - } -} diff --git a/program/tests/integration.rs b/program/tests/integration.rs index f66892033..d7cb42248 100644 --- a/program/tests/integration.rs +++ b/program/tests/integration.rs @@ -1,23 +1,24 @@ -#![cfg(feature = "test-bpf")] - use { - assert_matches::*, + bpf_program_template::process_instruction, + assert_matches::assert_matches, solana_program::{ instruction::{AccountMeta, Instruction}, pubkey::Pubkey, }, solana_sdk::{signature::Signer, transaction::Transaction}, - solana_validator::test_validator::*, + solana_program_test::{processor, tokio, ProgramTest} }; -#[test] -fn test_validator_transaction() { +#[tokio::test] +async fn test_transaction() { let program_id = Pubkey::new_unique(); + let pt = ProgramTest::new( + "bpf_program_template", + program_id, + processor!(process_instruction), + ); - let (test_validator, payer) = TestValidatorGenesis::default() - .add_program("bpf_program_template", program_id) - .start(); - let (rpc_client, recent_blockhash, _fee_calculator) = test_validator.rpc_client(); + let (mut banks_client, payer, recent_blockhash) = pt.start().await; let mut transaction = Transaction::new_with_payer( &[Instruction { @@ -29,5 +30,5 @@ fn test_validator_transaction() { ); transaction.sign(&[&payer], recent_blockhash); - assert_matches!(rpc_client.send_and_confirm_transaction(&transaction), Ok(_)); + assert_matches!(banks_client.process_transaction(transaction).await, Ok(())); }