Skip to content

Commit

Permalink
Replaces assert_eq! in native programs by explicit if and panic!.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Mar 2, 2021
1 parent 4f27d01 commit 47625d8
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 17 deletions.
7 changes: 5 additions & 2 deletions programs/budget/src/budget_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,15 @@ fn apply_account_data(

pub fn process_instruction(
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
_keyed_accounts: &[KeyedAccount],
data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
let keyed_accounts = invoke_context.get_keyed_accounts();
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
if invoke_context.get_keyed_accounts() != keyed_accounts {
panic!();
}

let instruction = limited_deserialize(data)?;

Expand Down
7 changes: 5 additions & 2 deletions programs/config/src/config_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ use solana_sdk::{

pub fn process_instruction(
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
_keyed_accounts: &[KeyedAccount],
data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
let keyed_accounts = invoke_context.get_keyed_accounts();
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
if invoke_context.get_keyed_accounts() != keyed_accounts {
panic!();
}

let key_list: ConfigKeys = limited_deserialize(data)?;
let config_keyed_account = &mut keyed_account_at_index(keyed_accounts, 0)?;
Expand Down
7 changes: 5 additions & 2 deletions programs/exchange/src/exchange_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,17 @@ impl ExchangeProcessor {

pub fn process_instruction(
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
_keyed_accounts: &[KeyedAccount],
data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
solana_logger::setup();

let keyed_accounts = invoke_context.get_keyed_accounts();
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
if invoke_context.get_keyed_accounts() != keyed_accounts {
panic!();
}

match limited_deserialize::<ExchangeInstruction>(data)? {
ExchangeInstruction::AccountRequest => {
Expand Down
4 changes: 1 addition & 3 deletions programs/noop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ pub fn process_instruction(
program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
data: &[u8],
invoke_context: &mut dyn InvokeContext,
_invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
solana_logger::setup();
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
trace!("noop: program_id: {:?}", program_id);
trace!("noop: keyed_accounts: {:#?}", keyed_accounts);
trace!("noop: data: {:?}", data);
Expand Down
7 changes: 5 additions & 2 deletions programs/ownable/src/ownable_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ fn set_owner(

pub fn process_instruction(
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
_keyed_accounts: &[KeyedAccount],
data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
let keyed_accounts = invoke_context.get_keyed_accounts();
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
if invoke_context.get_keyed_accounts() != keyed_accounts {
panic!();
}
let new_owner_pubkey: Pubkey = limited_deserialize(data)?;
let account_keyed_account = &mut keyed_account_at_index(keyed_accounts, 0)?;
let mut account_owner_pubkey: Pubkey =
Expand Down
7 changes: 5 additions & 2 deletions programs/stake/src/stake_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,15 @@ pub fn set_lockup(

pub fn process_instruction(
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
_keyed_accounts: &[KeyedAccount],
data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
let keyed_accounts = invoke_context.get_keyed_accounts();
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
if invoke_context.get_keyed_accounts() != keyed_accounts {
panic!();
}
trace!("process_instruction: {:?}", data);
trace!("keyed_accounts: {:?}", keyed_accounts);

Expand Down
7 changes: 5 additions & 2 deletions programs/vest/src/vest_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ fn verify_signed_account<'a>(

pub fn process_instruction(
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
_keyed_accounts: &[KeyedAccount],
data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
let keyed_accounts = invoke_context.get_keyed_accounts();
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
if invoke_context.get_keyed_accounts() != keyed_accounts {
panic!();
}

let contract_account = &mut keyed_account_at_index(keyed_accounts, 0)?.try_account_ref_mut()?;
if invoke_context.is_feature_active(&feature_set::check_program_owner::id())
Expand Down
7 changes: 5 additions & 2 deletions programs/vote/src/vote_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,15 @@ fn verify_rent_exemption(

pub fn process_instruction(
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
_keyed_accounts: &[KeyedAccount],
data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
let keyed_accounts = invoke_context.get_keyed_accounts();
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
if invoke_context.get_keyed_accounts() != keyed_accounts {
panic!();
}

trace!("process_instruction: {:?}", data);
trace!("keyed_accounts: {:?}", keyed_accounts);
Expand Down

0 comments on commit 47625d8

Please sign in to comment.