Upgradeable programs called same as non-upgradeable (#14239)
* Upgradeable programs called same as non-upgradeable * nudge
This commit is contained in:
@@ -21,9 +21,7 @@ use solana_runtime::{
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account_utils::StateMut,
|
||||
bpf_loader, bpf_loader_deprecated,
|
||||
bpf_loader_upgradeable::UpgradeableLoaderState,
|
||||
client::SyncClient,
|
||||
clock::{DEFAULT_SLOTS_PER_EPOCH, MAX_PROCESSING_AGE},
|
||||
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
|
||||
@@ -1479,11 +1477,11 @@ fn test_program_bpf_upgrade() {
|
||||
bank.add_builtin(&name, id, entrypoint);
|
||||
let bank_client = BankClient::new(bank);
|
||||
|
||||
// deploy upgrade program
|
||||
// Deploy upgrade program
|
||||
let (program_id, authority_keypair) =
|
||||
load_upgradeable_bpf_program(&bank_client, &mint_keypair, "solana_bpf_rust_upgradeable");
|
||||
|
||||
// call upgrade program
|
||||
// Call upgrade program
|
||||
nonce += 1;
|
||||
let instruction = Instruction::new(
|
||||
program_id,
|
||||
@@ -1499,7 +1497,7 @@ fn test_program_bpf_upgrade() {
|
||||
TransactionError::InstructionError(0, InstructionError::Custom(42))
|
||||
);
|
||||
|
||||
// upgrade program
|
||||
// Upgrade program
|
||||
upgrade_bpf_program(
|
||||
&bank_client,
|
||||
&mint_keypair,
|
||||
@@ -1508,7 +1506,7 @@ fn test_program_bpf_upgrade() {
|
||||
"solana_bpf_rust_upgraded",
|
||||
);
|
||||
|
||||
// call upgraded program
|
||||
// Call upgraded program
|
||||
nonce += 1;
|
||||
let instruction = Instruction::new(
|
||||
program_id,
|
||||
@@ -1524,7 +1522,7 @@ fn test_program_bpf_upgrade() {
|
||||
TransactionError::InstructionError(0, InstructionError::Custom(43))
|
||||
);
|
||||
|
||||
// upgrade back to the original program
|
||||
// Set a new authority
|
||||
let new_authority_keypair = Keypair::new();
|
||||
set_upgrade_authority(
|
||||
&bank_client,
|
||||
@@ -1534,7 +1532,7 @@ fn test_program_bpf_upgrade() {
|
||||
Some(&new_authority_keypair.pubkey()),
|
||||
);
|
||||
|
||||
// upgrade back to the original program
|
||||
// Upgrade back to the original program
|
||||
upgrade_bpf_program(
|
||||
&bank_client,
|
||||
&mint_keypair,
|
||||
@@ -1543,7 +1541,7 @@ fn test_program_bpf_upgrade() {
|
||||
"solana_bpf_rust_upgradeable",
|
||||
);
|
||||
|
||||
// call original program
|
||||
// Call original program
|
||||
nonce += 1;
|
||||
let instruction = Instruction::new(
|
||||
program_id,
|
||||
@@ -1562,9 +1560,10 @@ fn test_program_bpf_upgrade() {
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
fn test_program_bpf_invoke_upgradeable() {
|
||||
fn test_program_bpf_invoke_upgradeable_via_cpi() {
|
||||
solana_logger::setup();
|
||||
|
||||
let mut nonce = 0;
|
||||
let GenesisConfigInfo {
|
||||
genesis_config,
|
||||
mint_keypair,
|
||||
@@ -1583,29 +1582,81 @@ fn test_program_bpf_invoke_upgradeable() {
|
||||
"solana_bpf_rust_invoke_and_return",
|
||||
);
|
||||
|
||||
// deploy upgrade program
|
||||
let (program_id, _) =
|
||||
// Deploy upgrade program
|
||||
let (program_id, authority_keypair) =
|
||||
load_upgradeable_bpf_program(&bank_client, &mint_keypair, "solana_bpf_rust_upgradeable");
|
||||
|
||||
let data = bank_client.get_account(&program_id).unwrap().unwrap();
|
||||
let programdata_address = if let UpgradeableLoaderState::Program {
|
||||
programdata_address,
|
||||
} = data.state().unwrap()
|
||||
{
|
||||
programdata_address
|
||||
} else {
|
||||
panic!("Not a program");
|
||||
};
|
||||
|
||||
// call invoker program to invoke the upgradeable program
|
||||
// Call invoker program to invoke the upgradeable program
|
||||
nonce += 1;
|
||||
let instruction = Instruction::new(
|
||||
invoke_and_return,
|
||||
&[0],
|
||||
&[nonce],
|
||||
vec![
|
||||
AccountMeta::new(program_id, false),
|
||||
AccountMeta::new(clock::id(), false),
|
||||
AccountMeta::new(fees::id(), false),
|
||||
],
|
||||
);
|
||||
let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction);
|
||||
assert_eq!(
|
||||
result.unwrap_err().unwrap(),
|
||||
TransactionError::InstructionError(0, InstructionError::Custom(42))
|
||||
);
|
||||
|
||||
// Upgrade program
|
||||
upgrade_bpf_program(
|
||||
&bank_client,
|
||||
&mint_keypair,
|
||||
&program_id,
|
||||
&authority_keypair,
|
||||
"solana_bpf_rust_upgraded",
|
||||
);
|
||||
|
||||
// Call the upgraded program
|
||||
nonce += 1;
|
||||
let instruction = Instruction::new(
|
||||
invoke_and_return,
|
||||
&[nonce],
|
||||
vec![
|
||||
AccountMeta::new(program_id, false),
|
||||
AccountMeta::new(clock::id(), false),
|
||||
AccountMeta::new(fees::id(), false),
|
||||
],
|
||||
);
|
||||
let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction);
|
||||
assert_eq!(
|
||||
result.unwrap_err().unwrap(),
|
||||
TransactionError::InstructionError(0, InstructionError::Custom(43))
|
||||
);
|
||||
|
||||
// Set a new authority
|
||||
let new_authority_keypair = Keypair::new();
|
||||
set_upgrade_authority(
|
||||
&bank_client,
|
||||
&mint_keypair,
|
||||
&program_id,
|
||||
&authority_keypair,
|
||||
Some(&new_authority_keypair.pubkey()),
|
||||
);
|
||||
|
||||
// Upgrade back to the original program
|
||||
upgrade_bpf_program(
|
||||
&bank_client,
|
||||
&mint_keypair,
|
||||
&program_id,
|
||||
&new_authority_keypair,
|
||||
"solana_bpf_rust_upgradeable",
|
||||
);
|
||||
|
||||
// Call original program
|
||||
nonce += 1;
|
||||
let instruction = Instruction::new(
|
||||
invoke_and_return,
|
||||
&[nonce],
|
||||
vec![
|
||||
AccountMeta::new(program_id, false),
|
||||
AccountMeta::new(clock::id(), false),
|
||||
AccountMeta::new(fees::id(), false),
|
||||
AccountMeta::new(programdata_address, false),
|
||||
],
|
||||
);
|
||||
let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction);
|
||||
|
Reference in New Issue
Block a user