diff --git a/core/rust/utils/src/assertions.rs b/core/rust/utils/src/assertions.rs index cf5995eb67..0054726f1b 100644 --- a/core/rust/utils/src/assertions.rs +++ b/core/rust/utils/src/assertions.rs @@ -1,6 +1,7 @@ use solana_program::{ account_info::AccountInfo, entrypoint::ProgramResult, + msg, program_error::ProgramError, program_pack::{IsInitialized, Pack}, pubkey::Pubkey, @@ -9,6 +10,7 @@ use solana_program::{ pub fn assert_signer(account_info: &AccountInfo) -> ProgramResult { if !account_info.is_signer { + msg!("{key} is not a signer", key = account_info.key,); Err(ProgramError::MissingRequiredSignature) } else { Ok(()) @@ -21,6 +23,7 @@ pub fn assert_initialized( ) -> Result { let account: T = T::unpack_unchecked(&account_info.data.borrow())?; if !account.is_initialized() { + msg!("{key} is not initialized", key = account_info.key,); Err(error.into()) } else { Ok(account) @@ -33,6 +36,12 @@ pub fn assert_owned_by( error: impl Into, ) -> ProgramResult { if account.owner != owner { + msg!( + "invalid owner for {key}: expected {expected}, got {actual}", + key = account.key, + expected = owner, + actual = account.owner + ); Err(error.into()) } else { Ok(()) @@ -47,6 +56,14 @@ pub fn assert_derivation( ) -> Result { let (key, bump) = Pubkey::find_program_address(path, program_id); if key != *account.key { + msg!( + "derivation assertion failed for {actual_key}: + \x20 expected {key} with program {program_id}, path {path:?}", + actual_key = account.key, + key = key, + program_id = program_id, + path = path, + ); return Err(error.into()); } Ok(bump) @@ -58,6 +75,12 @@ pub fn assert_rent_exempt( error: impl Into, ) -> ProgramResult { if !rent.is_exempt(account_info.lamports(), account_info.data_len()) { + msg!( + "{key} is not rent-exempt: has {balance} lamports, requires {min} lamports", + key = account_info.key, + balance = account_info.lamports(), + min = rent.minimum_balance(account_info.data_len()), + ); Err(error.into()) } else { Ok(())