Skip to content

Commit

Permalink
Adjust tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Feb 6, 2023
1 parent 474b723 commit 90850fb
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions programs/sbf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1822,26 +1822,30 @@ fn test_program_sbf_invoke_in_same_tx_as_deployment() {
)
.unwrap();

// Deployment is invisible to top-level-instructions but visible to CPI instructions
for (invoke_instruction, expected) in [
(
invoke_instruction,
Err(TransactionError::ProgramAccountNotFound),
),
(indirect_invoke_instruction, Ok(())),
] {
// Deployment is invisible to both top-level-instructions and CPI instructions
for (index, invoke_instruction) in [invoke_instruction, indirect_invoke_instruction]
.into_iter()
.enumerate()
{
let mut instructions = deployment_instructions.clone();
instructions.push(invoke_instruction);
let tx = Transaction::new(
&[&mint_keypair, &program_keypair, &authority_keypair],
Message::new(&instructions, Some(&mint_keypair.pubkey())),
bank.last_blockhash(),
);
let results = execute_transactions(&bank, vec![tx]);
if let Err(err) = expected {
assert_eq!(results[0].as_ref().unwrap_err(), &err);
if index == 0 {
let results = execute_transactions(&bank, vec![tx]);
assert_eq!(
results[0].as_ref().unwrap_err(),
&TransactionError::ProgramAccountNotFound,
);
} else {
assert!(results[0].is_ok());
let (result, _, _) = process_transaction_and_record_inner(&bank, tx);
assert_eq!(
result.unwrap_err(),
TransactionError::InstructionError(2, InstructionError::InvalidAccountData),
);
}
}
}
Expand Down Expand Up @@ -1887,6 +1891,17 @@ fn test_program_sbf_invoke_in_same_tx_as_redeployment() {
"solana_sbf_rust_invoke_and_return",
);

// Deploy panic program
let panic_program_keypair = Keypair::new();
load_upgradeable_program(
&bank_client,
&mint_keypair,
&buffer_keypair,
&panic_program_keypair,
&authority_keypair,
"solana_sbf_rust_panic",
);

let invoke_instruction =
Instruction::new_with_bytes(program_id, &[0], vec![AccountMeta::new(clock::id(), false)]);
let indirect_invoke_instruction = Instruction::new_with_bytes(
Expand All @@ -1899,6 +1914,7 @@ fn test_program_sbf_invoke_in_same_tx_as_redeployment() {
);

// Prepare redeployment
let buffer_keypair = Keypair::new();
load_upgradeable_buffer(
&bank_client,
&mint_keypair,
Expand All @@ -1912,8 +1928,10 @@ fn test_program_sbf_invoke_in_same_tx_as_redeployment() {
&authority_keypair.pubkey(),
&mint_keypair.pubkey(),
);
let panic_instruction =
Instruction::new_with_bytes(panic_program_keypair.pubkey(), &[], vec![]);

// Redeployment is visible to both top-level-instructions and CPI instructions
// Redeployment is invisible to both top-level-instructions and CPI instructions
for invoke_instruction in [invoke_instruction, indirect_invoke_instruction] {
// Call upgradeable program
let result =
Expand All @@ -1922,7 +1940,11 @@ fn test_program_sbf_invoke_in_same_tx_as_redeployment() {

// Upgrade the program and invoke in same tx
let message = Message::new(
&[redeployment_instruction.clone(), invoke_instruction],
&[
redeployment_instruction.clone(),
invoke_instruction,
panic_instruction.clone(), // Make sure the TX fails, so we don't have to deploy another program
],
Some(&mint_keypair.pubkey()),
);
let tx = Transaction::new(
Expand All @@ -1933,7 +1955,7 @@ fn test_program_sbf_invoke_in_same_tx_as_redeployment() {
let (result, _, _) = process_transaction_and_record_inner(&bank, tx);
assert_eq!(
result.unwrap_err(),
TransactionError::InstructionError(1, InstructionError::ProgramFailedToComplete),
TransactionError::InstructionError(2, InstructionError::ProgramFailedToComplete),
);
}
}
Expand Down

0 comments on commit 90850fb

Please sign in to comment.