diff --git a/.github/workflows/proofs.yml b/.github/workflows/proofs.yml new file mode 100644 index 0000000..7940871 --- /dev/null +++ b/.github/workflows/proofs.yml @@ -0,0 +1,27 @@ +name: Proofs + +on: + push: + branches: [proofs] + pull_request: + branches: [proofs] + +jobs: + format_and_lint_ptoken: + name: Format & Lint p-token + runs-on: ubuntu-latest + steps: + - name: Git Checkout + uses: actions/checkout@v4 + + - name: Setup Environment + uses: ./.github/actions/setup + with: + clippy: true + rustfmt: true + + - name: Format + run: pnpm p-token:format + + - name: Lint + run: pnpm p-token:lint \ No newline at end of file diff --git a/p-token/src/entrypoint-runtime-verification.rs b/p-token/src/entrypoint-runtime-verification.rs index b4a6bb5..50a7d85 100644 --- a/p-token/src/entrypoint-runtime-verification.rs +++ b/p-token/src/entrypoint-runtime-verification.rs @@ -12,9 +12,17 @@ use { crate::processor::*, pinocchio::{ - account_info::AccountInfo, no_allocator, nostd_panic_handler, program_entrypoint, program_error::{ProgramError, ToStr}, pubkey::Pubkey, sysvars::Sysvar, ProgramResult + account_info::AccountInfo, + no_allocator, nostd_panic_handler, program_entrypoint, + program_error::{ProgramError, ToStr}, + pubkey::Pubkey, + sysvars::Sysvar, + ProgramResult, + }, + pinocchio_token_interface::{ + error::TokenError, + state::{Initializable, Transmutable}, }, - pinocchio_token_interface::{error::TokenError, state::{Initializable, Transmutable}}, }; program_entrypoint!(process_instruction); @@ -95,8 +103,14 @@ pub(crate) fn inner_process_instruction( pinocchio::msg!("Testing Instruction: InitializeMint"); match instruction_data.len() { - x if 66 <= x => test_process_initialize_mint_freeze(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()), - x if 34 <= x => test_process_initialize_mint_no_freeze(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()), + x if 66 <= x => test_process_initialize_mint_freeze( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ), + x if 34 <= x => test_process_initialize_mint_no_freeze( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ), _ => panic!("Invalid instruction data length"), } } @@ -112,21 +126,30 @@ pub(crate) fn inner_process_instruction( #[cfg(feature = "logging")] pinocchio::msg!("Testing Instruction: Transfer"); - test_process_transfer(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()) + test_process_transfer( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ) } // 7 - MintTo 7 => { #[cfg(feature = "logging")] pinocchio::msg!("Instruction: MintTo"); - test_process_mint_to(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()) + test_process_mint_to( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ) } // 8 - Test Burn 8 => { #[cfg(feature = "logging")] pinocchio::msg!("Testing Instruction: Burn"); - test_process_burn(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()) + test_process_burn( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ) } // 9 - Test CloseAccount 9 => { @@ -140,28 +163,40 @@ pub(crate) fn inner_process_instruction( #[cfg(feature = "logging")] pinocchio::msg!("Testing Instruction: TransferChecked"); - test_process_transfer_checked(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()) + test_process_transfer_checked( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ) } // 15 - Test BurnChecked 15 => { #[cfg(feature = "logging")] pinocchio::msg!("Testing Instruction: BurnChecked"); - test_process_burn_checked(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()) + test_process_burn_checked( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ) } // 16 - Test InitializeAccount2 16 => { #[cfg(feature = "logging")] pinocchio::msg!("Testing Instruction: InitializeAccount2"); - test_process_initialize_account2(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()) + test_process_initialize_account2( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ) } // 18 - Test InitializeAccount3 18 => { #[cfg(feature = "logging")] pinocchio::msg!("Testing Instruction: InitializeAccount3"); - test_process_initialize_account3(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()) + test_process_initialize_account3( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ) } // 20 - Test InitializeMint2 20 => { @@ -169,8 +204,14 @@ pub(crate) fn inner_process_instruction( pinocchio::msg!("Testing Instruction: InitializeMint2"); match instruction_data.len() { - x if 66 <= x => test_process_initialize_mint2_freeze(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()), - x if 34 <= x => test_process_initialize_mint2_no_freeze(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()), + x if 66 <= x => test_process_initialize_mint2_freeze( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ), + x if 34 <= x => test_process_initialize_mint2_no_freeze( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ), _ => panic!("Invalid instruction data length"), } } @@ -195,14 +236,20 @@ fn inner_process_remaining_instruction( #[cfg(feature = "logging")] pinocchio::msg!("Instruction: InitializeMultisig"); - test_process_initialize_multisig(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()) + test_process_initialize_multisig( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ) } // 4 - Approve 4 => { #[cfg(feature = "logging")] pinocchio::msg!("Instruction: Approve"); - test_process_approve(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()) + test_process_approve( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ) } // 5 - Revoke 5 => { @@ -219,8 +266,14 @@ fn inner_process_remaining_instruction( // Determine if this is an Account or Mint based on data length if let Some(first_account) = accounts.first() { match first_account.data_len() { - Account::LEN => test_process_set_authority_account(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()), - Mint::LEN => test_process_set_authority_mint(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()), + Account::LEN => test_process_set_authority_account( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ), + Mint::LEN => test_process_set_authority_mint( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ), // FIXME: Create proof harness for this _ => panic!("SetAuthority: Unexpected account data length"), } @@ -248,14 +301,20 @@ fn inner_process_remaining_instruction( #[cfg(feature = "logging")] pinocchio::msg!("Instruction: ApproveChecked"); - test_process_approve_checked(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()) + test_process_approve_checked( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ) } // 14 - MintToChecked 14 => { #[cfg(feature = "logging")] pinocchio::msg!("Instruction: MintToChecked"); - test_process_mint_to_checked(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()) + test_process_mint_to_checked( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ) } // 17 - SyncNative 17 => { @@ -269,7 +328,10 @@ fn inner_process_remaining_instruction( #[cfg(feature = "logging")] pinocchio::msg!("Instruction: InitializeMultisig2"); - test_process_initialize_multisig2(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()) + test_process_initialize_multisig2( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ) } // 21 - GetAccountDataSize 21 => { @@ -290,7 +352,10 @@ fn inner_process_remaining_instruction( #[cfg(feature = "logging")] pinocchio::msg!("Instruction: AmountToUiAmount"); - test_process_amount_to_ui_amount(accounts.first_chunk().unwrap(), instruction_data.first_chunk().unwrap()) + test_process_amount_to_ui_amount( + accounts.first_chunk().unwrap(), + instruction_data.first_chunk().unwrap(), + ) } // 24 - UiAmountToAmount 24 => { @@ -310,14 +375,21 @@ fn inner_process_remaining_instruction( if let Some(acc) = accounts.first() { match acc.data_len() { - Account::LEN => test_process_withdraw_excess_lamports_account(accounts.first_chunk().unwrap()), - Mint::LEN => test_process_withdraw_excess_lamports_mint(accounts.first_chunk().unwrap()), - Multisig::LEN => test_process_withdraw_excess_lamports_multisig(accounts.first_chunk().unwrap()), + Account::LEN => test_process_withdraw_excess_lamports_account( + accounts.first_chunk().unwrap(), + ), + Mint::LEN => { + test_process_withdraw_excess_lamports_mint(accounts.first_chunk().unwrap()) + } + Multisig::LEN => test_process_withdraw_excess_lamports_multisig( + accounts.first_chunk().unwrap(), + ), // FIXME: Need harness for this _other => panic!("withdraw_excess_lamports: Unexpected account data_len"), } } else { - // FIXME: need to add harness isntead since instruction still accepts this case and has an error code + // FIXME: need to add harness isntead since instruction still accepts this case + // and has an error code panic!("withdraw_excess_lamports: no accounts provided") } } @@ -335,11 +407,12 @@ fn cheatcode_is_multisig(_: &AccountInfo) {} // TODO: implement multisig cheatco #[inline(never)] fn cheatcode_is_rent(_: &AccountInfo) {} -use pinocchio_token_interface::state::mint::Mint; -use pinocchio_token_interface::state::account::Account; -use pinocchio_token_interface::state::multisig::Multisig; -use pinocchio_token_interface::state::{load_mut_unchecked, load_unchecked}; -use pinocchio::sysvars::rent::Rent; +use { + pinocchio::sysvars::rent::Rent, + pinocchio_token_interface::state::{ + account::Account, load_mut_unchecked, load_unchecked, mint::Mint, multisig::Multisig, + }, +}; fn get_account(account_info: &AccountInfo) -> &Account { unsafe { @@ -366,20 +439,18 @@ fn get_multisig(account_info: &AccountInfo) -> &Multisig { } fn get_rent(account_info: &AccountInfo) -> &Rent { - unsafe { - Rent::from_bytes_unchecked(account_info.borrow_data_unchecked()) - } + unsafe { Rent::from_bytes_unchecked(account_info.borrow_data_unchecked()) } } -/// This function encapsulates the specification of validating the signature requirements -/// In particular, code from mod.rs::validate_owner is checked +/// This function encapsulates the specification of validating the signature +/// requirements In particular, code from mod.rs::validate_owner is checked #[inline(never)] fn inner_test_validate_owner( expected_owner: &Pubkey, owner_account_info: &AccountInfo, tx_signers: &[AccountInfo], - maybe_multisig_is_initialised : Option>, - result : Result<(), ProgramError> + maybe_multisig_is_initialised: Option>, + result: Result<(), ProgramError>, ) -> Result<(), ProgramError> { use pinocchio_token_interface::program::ID; @@ -390,7 +461,8 @@ fn inner_test_validate_owner( result } // Line 106-108 - else if owner_account_info.data_len() == Multisig::LEN && owner_account_info.is_owned_by(&ID) { + else if owner_account_info.data_len() == Multisig::LEN && owner_account_info.is_owned_by(&ID) + { // Guaranteed to succeed by `cheatcode_is_multisig` let multisig_is_initialised = maybe_multisig_is_initialised.unwrap(); @@ -406,12 +478,11 @@ fn inner_test_validate_owner( let multisig = get_multisig(owner_account_info); // Lines 119-129: Did all declared and allowed signers sign? - let unsigned_exists = tx_signers.iter() - .any(|potential_signer| { - multisig.signers - .iter() - .any(|registered_key| registered_key == potential_signer.key() && !potential_signer.is_signer()) - }); + let unsigned_exists = tx_signers.iter().any(|potential_signer| { + multisig.signers.iter().any(|registered_key| { + registered_key == potential_signer.key() && !potential_signer.is_signer() + }) + }); if unsigned_exists { assert_eq!(result, Err(ProgramError::MissingRequiredSignature)); @@ -419,20 +490,23 @@ fn inner_test_validate_owner( } // Lines 130-132: Were enough signatures received? - let signers_count = multisig.signers.iter() + let signers_count = multisig + .signers + .iter() .filter_map(|registered_key| { - tx_signers.iter() - .find(|potential_signer| potential_signer.key() == registered_key && potential_signer.is_signer()) + tx_signers.iter().find(|potential_signer| { + potential_signer.key() == registered_key && potential_signer.is_signer() + }) }) .count(); // Line 130-132: Check if we have enough signers (singers_count < multisig.m) - if signers_count < multisig.m as usize { - assert_eq!(result, Err(ProgramError::MissingRequiredSignature)); - return result; - } else { - return result; - } + if signers_count < multisig.m as usize { + assert_eq!(result, Err(ProgramError::MissingRequiredSignature)); + return result; + } else { + return result; + } } } // Line 133-135: Non-multisig case - check if owner_account_info.is_signer() @@ -466,10 +540,9 @@ fn test_ptoken_domain_data(acc: &AccountInfo, mint: &AccountInfo, rent: &Account cheatcode_is_account(acc); unsafe { let test = acc.borrow_mut_data_unchecked(); - let iacc:Result<&mut Account, _> = load_mut_unchecked(test); + let iacc: Result<&mut Account, _> = load_mut_unchecked(test); let iacc = iacc.unwrap(); iacc.set_native(true); - } let iacc = get_account(acc); assert!(iacc.is_native()); @@ -502,9 +575,13 @@ fn test_ptoken_domain_data(acc: &AccountInfo, mint: &AccountInfo, rent: &Account /// instruction_data[0] // Decimals /// instruction_data[1..33] // Mint Authority Pubkey /// instruction_data[33] // Freeze Authority Exists? 1 for freeze -/// instruction_data[34..66] // instruction_data[33] == 1 ==> Freeze Authority Pubkey +/// instruction_data[34..66] // instruction_data[33] == 1 ==> Freeze Authority +/// Pubkey #[inline(never)] -pub fn test_process_initialize_mint_freeze(accounts: &[AccountInfo; 2], instruction_data: &[u8; 66]) -> ProgramResult { +pub fn test_process_initialize_mint_freeze( + accounts: &[AccountInfo; 2], + instruction_data: &[u8; 66], +) -> ProgramResult { cheatcode_is_mint(&accounts[0]); cheatcode_is_rent(&accounts[1]); @@ -528,17 +605,23 @@ pub fn test_process_initialize_mint_freeze(accounts: &[AccountInfo; 2], instruct assert_eq!(result, Err(ProgramError::InvalidAccountData)) } else if mint_is_initialised_prior.is_err() { assert_eq!(result, Err(ProgramError::InvalidAccountData)) - } else if mint_is_initialised_prior.unwrap() { + } else if mint_is_initialised_prior.unwrap() { assert_eq!(result, Err(ProgramError::Custom(6))) } else if accounts[0].lamports() < minimum_balance { assert_eq!(result, Err(ProgramError::Custom(0))) } else { assert!(get_mint(&accounts[0]).is_initialized().unwrap()); - assert_eq!(get_mint(&accounts[0]).mint_authority().unwrap(), &instruction_data[1..33]); + assert_eq!( + get_mint(&accounts[0]).mint_authority().unwrap(), + &instruction_data[1..33] + ); assert_eq!(get_mint(&accounts[0]).decimals, instruction_data[0]); if instruction_data[33] == 1 { - assert_eq!(get_mint(&accounts[0]).freeze_authority().unwrap(), &instruction_data[34..66]); + assert_eq!( + get_mint(&accounts[0]).freeze_authority().unwrap(), + &instruction_data[34..66] + ); } } @@ -551,7 +634,10 @@ pub fn test_process_initialize_mint_freeze(accounts: &[AccountInfo; 2], instruct /// instruction_data[1..33] // Mint Authority Pubkey /// instruction_data[33] // Freeze Authority Exists? 0 for no freeze #[inline(never)] -pub fn test_process_initialize_mint_no_freeze(accounts: &[AccountInfo; 2], instruction_data: &[u8; 34]) -> ProgramResult { +pub fn test_process_initialize_mint_no_freeze( + accounts: &[AccountInfo; 2], + instruction_data: &[u8; 34], +) -> ProgramResult { cheatcode_is_mint(&accounts[0]); cheatcode_is_rent(&accounts[1]); @@ -575,18 +661,25 @@ pub fn test_process_initialize_mint_no_freeze(accounts: &[AccountInfo; 2], instr assert_eq!(result, Err(ProgramError::InvalidAccountData)) } else if mint_is_initialised_prior.is_err() { assert_eq!(result, Err(ProgramError::InvalidAccountData)) - } else if mint_is_initialised_prior.unwrap() { + } else if mint_is_initialised_prior.unwrap() { assert_eq!(result, Err(ProgramError::Custom(6))) } else if accounts[0].lamports() < minimum_balance { assert_eq!(result, Err(ProgramError::Custom(0))) } else { assert!(get_mint(&accounts[0]).is_initialized().unwrap()); - assert_eq!(get_mint(&accounts[0]).mint_authority().unwrap(), &instruction_data[1..33]); + assert_eq!( + get_mint(&accounts[0]).mint_authority().unwrap(), + &instruction_data[1..33] + ); assert_eq!(get_mint(&accounts[0]).decimals, instruction_data[0]); - #[allow(clippy::out_of_bounds_indexing)] // Guard above prevents this branch TODO: Perhaps remove? + #[allow(clippy::out_of_bounds_indexing)] + // Guard above prevents this branch TODO: Perhaps remove? if instruction_data[33] == 1 { - assert_eq!(get_mint(&accounts[0]).freeze_authority().unwrap(), &instruction_data[34..66]); + assert_eq!( + get_mint(&accounts[0]).freeze_authority().unwrap(), + &instruction_data[34..66] + ); } } @@ -607,8 +700,7 @@ pub fn test_process_initialize_account(accounts: &[AccountInfo; 4]) -> ProgramRe cheatcode_is_rent(&accounts[3]); //-Initial State----------------------------------------------------------- - let initial_state_new_account = get_account(&accounts[0]) - .account_state(); + let initial_state_new_account = get_account(&accounts[0]).account_state(); let minimum_balance = get_rent(&accounts[3]).minimum_balance(accounts[0].data_len()); // TODO float problem let is_native_mint = accounts[1].key() == &pinocchio_token_interface::native_mint::ID; @@ -633,23 +725,34 @@ pub fn test_process_initialize_account(accounts: &[AccountInfo; 4]) -> ProgramRe } else if !is_native_mint && accounts[1].owner() != &pinocchio_token_interface::program::ID { assert_eq!(result, Err(ProgramError::IncorrectProgramId)) } else if !is_native_mint - && accounts[1].owner() == &pinocchio_token_interface::program::ID - && mint_is_initialised.is_err() { + && accounts[1].owner() == &pinocchio_token_interface::program::ID + && mint_is_initialised.is_err() + { assert_eq!(result, Err(ProgramError::InvalidAccountData)) } else if !is_native_mint - && accounts[1].owner() == &pinocchio_token_interface::program::ID - && !mint_is_initialised.unwrap() { + && accounts[1].owner() == &pinocchio_token_interface::program::ID + && !mint_is_initialised.unwrap() + { assert_eq!(result, Err(ProgramError::Custom(2))) } else { assert!(result.is_ok()); - assert_eq!(get_account(&accounts[0]).account_state().unwrap(), account_state::AccountState::Initialized); + assert_eq!( + get_account(&accounts[0]).account_state().unwrap(), + account_state::AccountState::Initialized + ); assert_eq!(get_account(&accounts[0]).mint, *accounts[1].key()); assert_eq!(get_account(&accounts[0]).owner, *accounts[2].key()); if is_native_mint { assert!(get_account(&accounts[0]).is_native()); - assert_eq!(get_account(&accounts[0]).native_amount().unwrap(), minimum_balance); - assert_eq!(get_account(&accounts[0]).amount(), accounts[0].lamports() - minimum_balance); + assert_eq!( + get_account(&accounts[0]).native_amount().unwrap(), + minimum_balance + ); + assert_eq!( + get_account(&accounts[0]).amount(), + accounts[0].lamports() - minimum_balance + ); } } @@ -662,14 +765,17 @@ pub fn test_process_initialize_account(accounts: &[AccountInfo; 4]) -> ProgramRe /// accounts[3..14] // Signers /// instruction_data[0..8] // Little Endian Bytes of u64 amount #[inline(never)] -pub fn test_process_transfer(accounts: &[AccountInfo; 3], instruction_data: &[u8; 8]) -> ProgramResult { +pub fn test_process_transfer( + accounts: &[AccountInfo; 3], + instruction_data: &[u8; 8], +) -> ProgramResult { use pinocchio_token_interface::state::account_state; cheatcode_is_account(&accounts[0]); cheatcode_is_account(&accounts[1]); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[2]); - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[2]); //-Initial State----------------------------------------------------------- @@ -683,9 +789,9 @@ pub fn test_process_transfer(accounts: &[AccountInfo; 3], instruction_data: &[u8 let src_owner = get_account(&accounts[0]).owner; let old_src_delgate = get_account(&accounts[0]).delegate().cloned(); let old_src_delgated_amount = get_account(&accounts[0]).delegated_amount(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[2]).is_initialized()); //-Process Instruction----------------------------------------------------- @@ -710,28 +816,33 @@ pub fn test_process_transfer(accounts: &[AccountInfo; 3], instruction_data: &[u8 } else if accounts[0] != accounts[1] && !dst_initialised.unwrap() { assert_eq!(result, Err(ProgramError::UninitializedAccount)); return result; - } else if get_account(&accounts[0]).account_state().unwrap() == account_state::AccountState::Frozen { + } else if get_account(&accounts[0]).account_state().unwrap() + == account_state::AccountState::Frozen + { assert_eq!(result, Err(ProgramError::Custom(17))); return result; - } else if accounts[0] != accounts[1] && get_account(&accounts[1]).account_state().unwrap() == account_state::AccountState::Frozen { + } else if accounts[0] != accounts[1] + && get_account(&accounts[1]).account_state().unwrap() == account_state::AccountState::Frozen + { assert_eq!(result, Err(ProgramError::Custom(17))); return result; } else if src_initial_amount < amount { assert_eq!(result, Err(ProgramError::Custom(1))); return result; - } else if accounts[0] != accounts[1] && get_account(&accounts[0]).mint != get_account(&accounts[1]).mint { + } else if accounts[0] != accounts[1] + && get_account(&accounts[0]).mint != get_account(&accounts[1]).mint + { assert_eq!(result, Err(ProgramError::Custom(3))); return result; } else { if old_src_delgate == Some(*accounts[2].key()) { - // Validate Owner inner_test_validate_owner( &old_src_delgate.unwrap(), // expected_owner &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; if old_src_delgated_amount < amount { @@ -739,35 +850,51 @@ pub fn test_process_transfer(accounts: &[AccountInfo; 3], instruction_data: &[u8 return result; } } else { - // Validate Owner inner_test_validate_owner( &src_owner, // expected_owner &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - } - if (accounts[0] == accounts[1] || amount == 0) && accounts[0].owner() != &pinocchio_token_interface::program::ID { + if (accounts[0] == accounts[1] || amount == 0) + && accounts[0].owner() != &pinocchio_token_interface::program::ID + { assert_eq!(result, Err(ProgramError::IncorrectProgramId)); return result; - } else if (accounts[0] == accounts[1] || amount == 0) && accounts[1].owner() != &pinocchio_token_interface::program::ID { + } else if (accounts[0] == accounts[1] || amount == 0) + && accounts[1].owner() != &pinocchio_token_interface::program::ID + { assert_eq!(result, Err(ProgramError::IncorrectProgramId)); return result; - } else if accounts[0] != accounts[1] && amount != 0 && get_account(&accounts[0]).is_native() && src_initial_lamports < amount { + } else if accounts[0] != accounts[1] + && amount != 0 + && get_account(&accounts[0]).is_native() + && src_initial_lamports < amount + { // Not sure how to fund native mint assert_eq!(result, Err(ProgramError::Custom(14))); return result; - } else if accounts[0] != accounts[1] && amount != 0 && get_account(&accounts[0]).is_native() && u64::MAX - amount < dst_initial_lamports { + } else if accounts[0] != accounts[1] + && amount != 0 + && get_account(&accounts[0]).is_native() + && u64::MAX - amount < dst_initial_lamports + { // Not sure how to fund native mint assert_eq!(result, Err(ProgramError::Custom(14))); return result; - } else if accounts[0] != accounts[1] && amount != 0 { - assert_eq!(get_account(&accounts[0]).amount(), src_initial_amount - amount); - assert_eq!(get_account(&accounts[1]).amount(), dst_initial_amount + amount); + } else if accounts[0] != accounts[1] && amount != 0 { + assert_eq!( + get_account(&accounts[0]).amount(), + src_initial_amount - amount + ); + assert_eq!( + get_account(&accounts[1]).amount(), + dst_initial_amount + amount + ); if get_account(&accounts[0]).is_native() { assert_eq!(accounts[0].lamports(), src_initial_lamports - amount); @@ -779,7 +906,10 @@ pub fn test_process_transfer(accounts: &[AccountInfo; 3], instruction_data: &[u8 // Delegate updates if old_src_delgate == Some(*accounts[2].key()) && accounts[0] != accounts[1] { - assert_eq!(get_account(&accounts[0]).delegated_amount(), old_src_delgated_amount - amount); + assert_eq!( + get_account(&accounts[0]).delegated_amount(), + old_src_delgated_amount - amount + ); if old_src_delgated_amount - amount == 0 { assert_eq!(get_account(&accounts[0]).delegate(), None); } @@ -795,14 +925,17 @@ pub fn test_process_transfer(accounts: &[AccountInfo; 3], instruction_data: &[u8 /// accounts[3..14] // Signers /// instruction_data[0..8] // Little Endian Bytes of u64 amount #[inline(never)] -pub fn test_process_mint_to(accounts: &[AccountInfo; 3], instruction_data: &[u8; 8]) -> ProgramResult { +pub fn test_process_mint_to( + accounts: &[AccountInfo; 3], + instruction_data: &[u8; 8], +) -> ProgramResult { use pinocchio_token_interface::state::account_state; cheatcode_is_mint(&accounts[0]); cheatcode_is_account(&accounts[1]); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[2]); - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[2]); //-Initial State----------------------------------------------------------- @@ -811,9 +944,9 @@ pub fn test_process_mint_to(accounts: &[AccountInfo; 3], instruction_data: &[u8; let mint_initialised = get_mint(&accounts[0]).is_initialized(); let dst_initialised = get_account(&accounts[1]).is_initialized(); let dst_init_state = get_account(&accounts[1]).account_state(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[2]).is_initialized()); //-Process Instruction----------------------------------------------------- @@ -835,7 +968,8 @@ pub fn test_process_mint_to(accounts: &[AccountInfo; 3], instruction_data: &[u8; } else if !dst_initialised.unwrap() { assert_eq!(result, Err(ProgramError::UninitializedAccount)); return result; - } else if dst_init_state.unwrap() == account_state::AccountState::Frozen { // unwrap must succeed due to dst_initialised not being err + } else if dst_init_state.unwrap() == account_state::AccountState::Frozen { + // unwrap must succeed due to dst_initialised not being err assert_eq!(result, Err(ProgramError::Custom(17))); return result; } else if get_account(&accounts[1]).is_native() { @@ -856,22 +990,20 @@ pub fn test_process_mint_to(accounts: &[AccountInfo; 3], instruction_data: &[u8; return result; } else { if get_mint(&accounts[0]).mint_authority().is_some() { - // Validate Owner inner_test_validate_owner( get_mint(&accounts[0]).mint_authority().unwrap(), // expected_owner &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - } else { assert_eq!(result, Err(ProgramError::Custom(5))); return result; } - let amount = unsafe { u64::from_le_bytes(*(instruction_data.as_ptr() as *const [u8; 8])) }; + let amount = unsafe { u64::from_le_bytes(*(instruction_data.as_ptr() as *const [u8; 8])) }; if amount == 0 && accounts[0].owner() != &pinocchio_token_interface::program::ID { assert_eq!(result, Err(ProgramError::IncorrectProgramId)); @@ -887,7 +1019,6 @@ pub fn test_process_mint_to(accounts: &[AccountInfo; 3], instruction_data: &[u8; assert_eq!(get_mint(&accounts[0]).supply(), initial_supply + amount); assert_eq!(get_account(&accounts[1]).amount(), initial_amount + amount); assert!(result.is_ok()); - } result @@ -904,9 +1035,9 @@ pub fn test_process_burn(accounts: &[AccountInfo; 3], instruction_data: &[u8; 8] cheatcode_is_account(&accounts[0]); cheatcode_is_mint(&accounts[1]); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[2]); - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[2]); //-Initial State----------------------------------------------------------- @@ -923,9 +1054,9 @@ pub fn test_process_burn(accounts: &[AccountInfo; 3], instruction_data: &[u8; 8] let mint_initialised = get_mint(&accounts[1]).is_initialized(); let mint_init_supply = get_mint(&accounts[1]).supply(); let mint_owner = *accounts[1].owner(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[2]).is_initialized()); //-Process Instruction----------------------------------------------------- @@ -959,14 +1090,13 @@ pub fn test_process_burn(accounts: &[AccountInfo; 3], instruction_data: &[u8; 8] } else { if !src_owned_sys_inc { if old_src_delgate.is_some() && *accounts[2].key() == old_src_delgate.unwrap() { - // Validate Owner inner_test_validate_owner( &old_src_delgate.unwrap(), // expected_owner &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; if old_src_delgated_amount < amount { @@ -974,16 +1104,14 @@ pub fn test_process_burn(accounts: &[AccountInfo; 3], instruction_data: &[u8; 8] return result; } } else { - // Validate Owner inner_test_validate_owner( &src_owner, // expected_owner &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - } } @@ -998,7 +1126,10 @@ pub fn test_process_burn(accounts: &[AccountInfo; 3], instruction_data: &[u8; 8] // Delegate updates if old_src_delgate.is_some() && *accounts[2].key() == old_src_delgate.unwrap() { - assert_eq!(get_account(&accounts[0]).delegated_amount(), old_src_delgated_amount - amount); + assert_eq!( + get_account(&accounts[0]).delegated_amount(), + old_src_delgated_amount - amount + ); if old_src_delgated_amount - amount == 0 { assert_eq!(get_account(&accounts[0]).delegate(), None); } @@ -1019,9 +1150,9 @@ pub fn test_process_close_account(accounts: &[AccountInfo; 3]) -> ProgramResult cheatcode_is_account(&accounts[0]); cheatcode_is_account(&accounts[1]); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[2]); - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[2]); //-Initial State----------------------------------------------------------- @@ -1032,10 +1163,13 @@ pub fn test_process_close_account(accounts: &[AccountInfo; 3]) -> ProgramResult let src_init_lamports = accounts[1].lamports(); let src_is_native = get_account(&accounts[0]).is_native(); let src_owned_sys_inc = get_account(&accounts[0]).is_owned_by_system_program_or_incinerator(); - let authority = get_account(&accounts[0]).close_authority().cloned().unwrap_or(get_account(&accounts[0]).owner); - #[cfg(not(feature="multisig"))] + let authority = get_account(&accounts[0]) + .close_authority() + .cloned() + .unwrap_or(get_account(&accounts[0]).owner); + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[2]).is_initialized()); //-Process Instruction----------------------------------------------------- @@ -1062,16 +1196,14 @@ pub fn test_process_close_account(accounts: &[AccountInfo; 3]) -> ProgramResult return result; } else { if !src_owned_sys_inc { - // Validate Owner inner_test_validate_owner( &authority, // expected_owner &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - } else if accounts[1].key() != &INCINERATOR_ID { assert_eq!(result, Err(ProgramError::InvalidAccountData)); return result; @@ -1081,7 +1213,10 @@ pub fn test_process_close_account(accounts: &[AccountInfo; 3]) -> ProgramResult } // Validate owner falls through to here if no error - assert_eq!(accounts[1].lamports(), dst_init_lamports + src_init_lamports); + assert_eq!( + accounts[1].lamports(), + dst_init_lamports + src_init_lamports + ); assert_eq!(accounts[0].data_len(), 0); // TODO: More sol_memset stuff? assert!(result.is_ok()); } @@ -1095,15 +1230,18 @@ pub fn test_process_close_account(accounts: &[AccountInfo; 3]) -> ProgramResult /// accounts[4..15] // Signers /// instruction_data[0..9] // Little Endian Bytes of u64 amount, and decimals #[inline(never)] -pub fn test_process_transfer_checked(accounts: &[AccountInfo; 4], instruction_data: &[u8; 9]) -> ProgramResult { +pub fn test_process_transfer_checked( + accounts: &[AccountInfo; 4], + instruction_data: &[u8; 9], +) -> ProgramResult { use pinocchio_token_interface::state::account_state; cheatcode_is_account(&accounts[0]); cheatcode_is_mint(&accounts[1]); cheatcode_is_account(&accounts[2]); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[3]); - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[3]); //-Initial State----------------------------------------------------------- @@ -1118,9 +1256,9 @@ pub fn test_process_transfer_checked(accounts: &[AccountInfo; 4], instruction_da let old_src_delgate = get_account(&accounts[0]).delegate().cloned(); let old_src_delgated_amount = get_account(&accounts[0]).delegated_amount(); let mint_initialised = get_mint(&accounts[1]).is_initialized(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[3]).is_initialized()); //-Process Instruction----------------------------------------------------- @@ -1145,16 +1283,22 @@ pub fn test_process_transfer_checked(accounts: &[AccountInfo; 4], instruction_da } else if accounts[0] != accounts[2] && !dst_initialised.unwrap() { assert_eq!(result, Err(ProgramError::UninitializedAccount)); return result; - } else if get_account(&accounts[0]).account_state().unwrap() == account_state::AccountState::Frozen { + } else if get_account(&accounts[0]).account_state().unwrap() + == account_state::AccountState::Frozen + { assert_eq!(result, Err(ProgramError::Custom(17))); return result; - } else if accounts[0] != accounts[2] && get_account(&accounts[2]).account_state().unwrap() == account_state::AccountState::Frozen { + } else if accounts[0] != accounts[2] + && get_account(&accounts[2]).account_state().unwrap() == account_state::AccountState::Frozen + { assert_eq!(result, Err(ProgramError::Custom(17))); return result; - } else if src_initial_amount < amount { + } else if src_initial_amount < amount { assert_eq!(result, Err(ProgramError::Custom(1))); return result; - } else if accounts[0] != accounts[2] && get_account(&accounts[0]).mint != get_account(&accounts[2]).mint { + } else if accounts[0] != accounts[2] + && get_account(&accounts[0]).mint != get_account(&accounts[2]).mint + { assert_eq!(result, Err(ProgramError::Custom(3))); return result; } else if accounts[1].key() != &get_account(&accounts[0]).mint { @@ -1174,15 +1318,14 @@ pub fn test_process_transfer_checked(accounts: &[AccountInfo; 4], instruction_da return result; } else { if old_src_delgate == Some(*accounts[3].key()) { - - // Because of the above if, there is a duplicated check in the following function - // Validate Owner + // Because of the above if, there is a duplicated check in the following + // function Validate Owner inner_test_validate_owner( &old_src_delgate.unwrap(), // expected_owner &accounts[3], // owner_account_info &accounts[4..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; if old_src_delgated_amount < amount { @@ -1190,22 +1333,24 @@ pub fn test_process_transfer_checked(accounts: &[AccountInfo; 4], instruction_da return result; } } else { - // Validate Owner inner_test_validate_owner( &src_owner, // expected_owner &accounts[3], // owner_account_info &accounts[4..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - } - if (accounts[0] == accounts[2] || amount == 0) && accounts[0].owner() != &pinocchio_token_interface::program::ID { + if (accounts[0] == accounts[2] || amount == 0) + && accounts[0].owner() != &pinocchio_token_interface::program::ID + { assert_eq!(result, Err(ProgramError::IncorrectProgramId)); return result; - } else if (accounts[0] == accounts[2] || amount == 0) && accounts[2].owner() != &pinocchio_token_interface::program::ID { + } else if (accounts[0] == accounts[2] || amount == 0) + && accounts[2].owner() != &pinocchio_token_interface::program::ID + { assert_eq!(result, Err(ProgramError::IncorrectProgramId)); return result; } else if accounts[0] != accounts[2] && amount != 0 { @@ -1213,14 +1358,22 @@ pub fn test_process_transfer_checked(accounts: &[AccountInfo; 4], instruction_da // Not sure how to fund native mint assert_eq!(result, Err(ProgramError::Custom(14))); return result; - } else if get_account(&accounts[0]).is_native() && u64::MAX - amount < dst_initial_lamports { + } else if get_account(&accounts[0]).is_native() + && u64::MAX - amount < dst_initial_lamports + { // Not sure how to fund native mint assert_eq!(result, Err(ProgramError::Custom(14))); return result; } - assert_eq!(get_account(&accounts[0]).amount(), src_initial_amount - amount); - assert_eq!(get_account(&accounts[2]).amount(), dst_initial_amount + amount); + assert_eq!( + get_account(&accounts[0]).amount(), + src_initial_amount - amount + ); + assert_eq!( + get_account(&accounts[2]).amount(), + dst_initial_amount + amount + ); if get_account(&accounts[0]).is_native() { assert_eq!(accounts[0].lamports(), src_initial_lamports - amount); @@ -1231,7 +1384,10 @@ pub fn test_process_transfer_checked(accounts: &[AccountInfo; 4], instruction_da assert!(result.is_ok()); // Delegate updates if old_src_delgate == Some(*accounts[3].key()) && accounts[0] != accounts[2] { - assert_eq!(get_account(&accounts[0]).delegated_amount(), old_src_delgated_amount - amount); + assert_eq!( + get_account(&accounts[0]).delegated_amount(), + old_src_delgated_amount - amount + ); if old_src_delgated_amount - amount == 0 { assert_eq!(get_account(&accounts[0]).delegate(), None); } @@ -1247,14 +1403,17 @@ pub fn test_process_transfer_checked(accounts: &[AccountInfo; 4], instruction_da /// accounts[3..14] // Signers /// instruction_data[0..9] // Little Endian Bytes of u64 amount, and decimals #[inline(never)] -pub fn test_process_burn_checked(accounts: &[AccountInfo; 3], instruction_data: &[u8; 9]) -> ProgramResult { +pub fn test_process_burn_checked( + accounts: &[AccountInfo; 3], + instruction_data: &[u8; 9], +) -> ProgramResult { use pinocchio_token_interface::state::account_state; cheatcode_is_account(&accounts[0]); cheatcode_is_mint(&accounts[1]); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[2]); - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[2]); //-Initial State----------------------------------------------------------- @@ -1272,9 +1431,9 @@ pub fn test_process_burn_checked(accounts: &[AccountInfo; 3], instruction_data: let mint_init_supply = get_mint(&accounts[1]).supply(); let mint_decimals = get_mint(&accounts[1]).decimals; let mint_owner = *accounts[1].owner(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[2]).is_initialized()); //-Process Instruction----------------------------------------------------- @@ -1310,14 +1469,13 @@ pub fn test_process_burn_checked(accounts: &[AccountInfo; 3], instruction_data: } else { if !src_owned_sys_inc { if old_src_delgate.is_some() && *accounts[2].key() == old_src_delgate.unwrap() { - // Validate Owner inner_test_validate_owner( &old_src_delgate.unwrap(), // expected_owner &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; if old_src_delgated_amount < amount { @@ -1325,16 +1483,14 @@ pub fn test_process_burn_checked(accounts: &[AccountInfo; 3], instruction_data: return result; } } else { - // Validate Owner inner_test_validate_owner( &src_owner, // expected_owner &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - } } @@ -1349,7 +1505,10 @@ pub fn test_process_burn_checked(accounts: &[AccountInfo; 3], instruction_data: // Delegate updates if old_src_delgate.is_some() && *accounts[2].key() == old_src_delgate.unwrap() { - assert_eq!(get_account(&accounts[0]).delegated_amount(), old_src_delgated_amount - amount); + assert_eq!( + get_account(&accounts[0]).delegated_amount(), + old_src_delgated_amount - amount + ); if old_src_delgated_amount - amount == 0 { assert_eq!(get_account(&accounts[0]).delegate(), None); } @@ -1365,7 +1524,10 @@ pub fn test_process_burn_checked(accounts: &[AccountInfo; 3], instruction_data: /// accounts[2] // Rent Sysvar Info /// instruction_data[..] // Owner #[inline(never)] -pub fn test_process_initialize_account2(accounts: &[AccountInfo; 3], instruction_data: &[u8; 32]) -> ProgramResult { +pub fn test_process_initialize_account2( + accounts: &[AccountInfo; 3], + instruction_data: &[u8; 32], +) -> ProgramResult { use pinocchio_token_interface::state::account_state; cheatcode_is_account(&accounts[0]); @@ -1373,8 +1535,7 @@ pub fn test_process_initialize_account2(accounts: &[AccountInfo; 3], instruction cheatcode_is_rent(&accounts[2]); //-Initial State----------------------------------------------------------- - let initial_state_new_account = get_account(&accounts[0]) - .account_state(); + let initial_state_new_account = get_account(&accounts[0]).account_state(); let minimum_balance = get_rent(&accounts[2]).minimum_balance(accounts[0].data_len()); @@ -1403,23 +1564,34 @@ pub fn test_process_initialize_account2(accounts: &[AccountInfo; 3], instruction } else if !is_native_mint && accounts[1].owner() != &pinocchio_token_interface::program::ID { assert_eq!(result, Err(ProgramError::IncorrectProgramId)) } else if !is_native_mint - && accounts[1].owner() == &pinocchio_token_interface::program::ID - && mint_is_initialised.is_err() { + && accounts[1].owner() == &pinocchio_token_interface::program::ID + && mint_is_initialised.is_err() + { assert_eq!(result, Err(ProgramError::InvalidAccountData)) } else if !is_native_mint - && accounts[1].owner() == &pinocchio_token_interface::program::ID - && !mint_is_initialised.unwrap() { + && accounts[1].owner() == &pinocchio_token_interface::program::ID + && !mint_is_initialised.unwrap() + { assert_eq!(result, Err(ProgramError::Custom(2))) } else { assert!(result.is_ok()); - assert_eq!(get_account(&accounts[0]).account_state().unwrap(), account_state::AccountState::Initialized); + assert_eq!( + get_account(&accounts[0]).account_state().unwrap(), + account_state::AccountState::Initialized + ); assert_eq!(get_account(&accounts[0]).mint, *accounts[1].key()); assert_eq!(get_account(&accounts[0]).owner, *instruction_data); if is_native_mint { assert!(get_account(&accounts[0]).is_native()); - assert_eq!(get_account(&accounts[0]).native_amount().unwrap(), minimum_balance); - assert_eq!(get_account(&accounts[0]).amount(), accounts[0].lamports() - minimum_balance); + assert_eq!( + get_account(&accounts[0]).native_amount().unwrap(), + minimum_balance + ); + assert_eq!( + get_account(&accounts[0]).amount(), + accounts[0].lamports() - minimum_balance + ); } } @@ -1430,17 +1602,20 @@ pub fn test_process_initialize_account2(accounts: &[AccountInfo; 3], instruction /// accounts[1] // Mint Info /// instruction_data[..] // Owner #[inline(never)] -pub fn test_process_initialize_account3(accounts: &[AccountInfo; 2], instruction_data: &[u8; 32]) -> ProgramResult { +pub fn test_process_initialize_account3( + accounts: &[AccountInfo; 2], + instruction_data: &[u8; 32], +) -> ProgramResult { use pinocchio_token_interface::state::account_state; cheatcode_is_account(&accounts[0]); cheatcode_is_mint(&accounts[1]); //-Initial State----------------------------------------------------------- - let initial_state_new_account = get_account(&accounts[0]) - .account_state(); + let initial_state_new_account = get_account(&accounts[0]).account_state(); - // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be impossible + // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be + // impossible let rent = pinocchio::sysvars::rent::Rent::get().unwrap(); let minimum_balance = rent.minimum_balance(accounts[0].data_len()); @@ -1467,23 +1642,34 @@ pub fn test_process_initialize_account3(accounts: &[AccountInfo; 2], instruction } else if !is_native_mint && accounts[1].owner() != &pinocchio_token_interface::program::ID { assert_eq!(result, Err(ProgramError::IncorrectProgramId)) } else if !is_native_mint - && accounts[1].owner() == &pinocchio_token_interface::program::ID - && mint_is_initialised.is_err() { + && accounts[1].owner() == &pinocchio_token_interface::program::ID + && mint_is_initialised.is_err() + { assert_eq!(result, Err(ProgramError::InvalidAccountData)) } else if !is_native_mint - && accounts[1].owner() == &pinocchio_token_interface::program::ID - && !mint_is_initialised.unwrap() { + && accounts[1].owner() == &pinocchio_token_interface::program::ID + && !mint_is_initialised.unwrap() + { assert_eq!(result, Err(ProgramError::Custom(2))) } else { assert!(result.is_ok()); - assert_eq!(get_account(&accounts[0]).account_state().unwrap(), account_state::AccountState::Initialized); + assert_eq!( + get_account(&accounts[0]).account_state().unwrap(), + account_state::AccountState::Initialized + ); assert_eq!(get_account(&accounts[0]).mint, *accounts[1].key()); assert_eq!(get_account(&accounts[0]).owner, *instruction_data); if is_native_mint { assert!(get_account(&accounts[0]).is_native()); - assert_eq!(get_account(&accounts[0]).native_amount().unwrap(), minimum_balance); - assert_eq!(get_account(&accounts[0]).amount(), accounts[0].lamports() - minimum_balance); + assert_eq!( + get_account(&accounts[0]).native_amount().unwrap(), + minimum_balance + ); + assert_eq!( + get_account(&accounts[0]).amount(), + accounts[0].lamports() - minimum_balance + ); } } @@ -1494,13 +1680,18 @@ pub fn test_process_initialize_account3(accounts: &[AccountInfo; 2], instruction /// instruction_data[0] // Decimals /// instruction_data[1..33] // Mint Authority Pubkey /// instruction_data[33] // Freeze Authority Exists? 1 for freeze -/// instruction_data[34..66] // instruction_data[33] == 1 ==> Freeze Authority Pubkey +/// instruction_data[34..66] // instruction_data[33] == 1 ==> Freeze Authority +/// Pubkey #[inline(never)] -pub fn test_process_initialize_mint2_freeze(accounts: &[AccountInfo; 1], instruction_data: &[u8; 66]) -> ProgramResult { +pub fn test_process_initialize_mint2_freeze( + accounts: &[AccountInfo; 1], + instruction_data: &[u8; 66], +) -> ProgramResult { cheatcode_is_mint(&accounts[0]); //-Initial State----------------------------------------------------------- - // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be impossible + // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be + // impossible let rent = pinocchio::sysvars::rent::Rent::get().unwrap(); let minimum_balance = rent.minimum_balance(accounts[0].data_len()); let mint_is_initialised_prior = get_mint(&accounts[0]).is_initialized(); @@ -1521,17 +1712,23 @@ pub fn test_process_initialize_mint2_freeze(accounts: &[AccountInfo; 1], instruc assert_eq!(result, Err(ProgramError::InvalidAccountData)) } else if mint_is_initialised_prior.is_err() { assert_eq!(result, Err(ProgramError::InvalidAccountData)) - } else if mint_is_initialised_prior.unwrap() { + } else if mint_is_initialised_prior.unwrap() { assert_eq!(result, Err(ProgramError::Custom(6))) } else if accounts[0].lamports() < minimum_balance { assert_eq!(result, Err(ProgramError::Custom(0))) } else { assert!(get_mint(&accounts[0]).is_initialized().unwrap()); - assert_eq!(get_mint(&accounts[0]).mint_authority().unwrap(), &instruction_data[1..33]); + assert_eq!( + get_mint(&accounts[0]).mint_authority().unwrap(), + &instruction_data[1..33] + ); assert_eq!(get_mint(&accounts[0]).decimals, instruction_data[0]); if instruction_data[33] == 1 { - assert_eq!(get_mint(&accounts[0]).freeze_authority().unwrap(), &instruction_data[34..66]); + assert_eq!( + get_mint(&accounts[0]).freeze_authority().unwrap(), + &instruction_data[34..66] + ); } } @@ -1543,11 +1740,15 @@ pub fn test_process_initialize_mint2_freeze(accounts: &[AccountInfo; 1], instruc /// instruction_data[1..33] // Mint Authority Pubkey /// instruction_data[33] // Freeze Authority Exists? 0 for no freeze #[inline(never)] -pub fn test_process_initialize_mint2_no_freeze(accounts: &[AccountInfo; 1], instruction_data: &[u8; 34]) -> ProgramResult { +pub fn test_process_initialize_mint2_no_freeze( + accounts: &[AccountInfo; 1], + instruction_data: &[u8; 34], +) -> ProgramResult { cheatcode_is_mint(&accounts[0]); //-Initial State----------------------------------------------------------- - // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be impossible + // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be + // impossible let rent = pinocchio::sysvars::rent::Rent::get().unwrap(); let minimum_balance = rent.minimum_balance(accounts[0].data_len()); let mint_is_initialised_prior = get_mint(&accounts[0]).is_initialized(); @@ -1568,18 +1769,25 @@ pub fn test_process_initialize_mint2_no_freeze(accounts: &[AccountInfo; 1], inst assert_eq!(result, Err(ProgramError::InvalidAccountData)) } else if mint_is_initialised_prior.is_err() { assert_eq!(result, Err(ProgramError::InvalidAccountData)) - } else if mint_is_initialised_prior.unwrap() { + } else if mint_is_initialised_prior.unwrap() { assert_eq!(result, Err(ProgramError::Custom(6))) } else if accounts[0].lamports() < minimum_balance { assert_eq!(result, Err(ProgramError::Custom(0))) } else { assert!(get_mint(&accounts[0]).is_initialized().unwrap()); - assert_eq!(get_mint(&accounts[0]).mint_authority().unwrap(), &instruction_data[1..33]); + assert_eq!( + get_mint(&accounts[0]).mint_authority().unwrap(), + &instruction_data[1..33] + ); assert_eq!(get_mint(&accounts[0]).decimals, instruction_data[0]); - #[allow(clippy::out_of_bounds_indexing)] // Guard above prevents this branch TODO: Perhaps remove? + #[allow(clippy::out_of_bounds_indexing)] + // Guard above prevents this branch TODO: Perhaps remove? if instruction_data[33] == 1 { - assert_eq!(get_mint(&accounts[0]).freeze_authority().unwrap(), &instruction_data[34..66]); + assert_eq!( + get_mint(&accounts[0]).freeze_authority().unwrap(), + &instruction_data[34..66] + ); } } @@ -1592,8 +1800,10 @@ pub fn test_process_initialize_mint2_no_freeze(accounts: &[AccountInfo; 1], inst /// accounts[2..].len() // n /// instruction_data[1] // m #[inline(never)] -fn test_process_initialize_multisig(accounts: &[AccountInfo; 5], instruction_data: &[u8; 1]) -> ProgramResult { - // ^ FIXME: totally arbitrary for the tests +fn test_process_initialize_multisig( + accounts: &[AccountInfo; 5], + instruction_data: &[u8; 1], +) -> ProgramResult { cheatcode_is_multisig(&accounts[0]); cheatcode_is_rent(&accounts[1]); cheatcode_is_account(&accounts[2]); // Signer @@ -1631,14 +1841,11 @@ fn test_process_initialize_multisig(accounts: &[AccountInfo; 5], instruction_dat assert!(accounts[2..] .iter() .map(|signer| *signer.key()) - .eq( - get_multisig(&accounts[0]) + .eq(get_multisig(&accounts[0]) .signers .iter() .take(accounts[2..].len()) - .copied() - ) - ); + .copied())); assert_eq!(get_multisig(&accounts[0]).m, instruction_data[0]); assert_eq!(get_multisig(&accounts[0]).n as usize, accounts.len() - 2); assert!(get_multisig(&accounts[0]).is_initialized().is_ok()); @@ -1656,13 +1863,13 @@ fn test_process_initialize_multisig(accounts: &[AccountInfo; 5], instruction_dat /// instruction_data[0..8] // Little Endian Bytes of u64 amount #[inline(never)] fn test_process_approve(accounts: &[AccountInfo; 3], instruction_data: &[u8; 8]) -> ProgramResult { - use pinocchio_token_interface::state::{account_state}; + use pinocchio_token_interface::state::account_state; cheatcode_is_account(&accounts[0]); // Source Account cheatcode_is_account(&accounts[1]); // Delegate - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[2]); // Owner - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[2]); // Owner //-Initial State----------------------------------------------------------- @@ -1670,9 +1877,9 @@ fn test_process_approve(accounts: &[AccountInfo; 3], instruction_data: &[u8; 8]) let src_owner = get_account(&accounts[0]).owner; let src_initialised = get_account(&accounts[0]).is_initialized(); let src_init_state = get_account(&accounts[0]).account_state(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[2]).is_initialized()); //-Process Instruction----------------------------------------------------- @@ -1689,20 +1896,23 @@ fn test_process_approve(accounts: &[AccountInfo; 3], instruction_data: &[u8; 8]) assert_eq!(result, Err(ProgramError::InvalidAccountData)) } else if !src_initialised.unwrap() { assert_eq!(result, Err(ProgramError::UninitializedAccount)) - } else if src_init_state.unwrap() == account_state::AccountState::Frozen { // This should be safe to unwrap due to above check passing + } else if src_init_state.unwrap() == account_state::AccountState::Frozen { + // This should be safe to unwrap due to above check passing assert_eq!(result, Err(ProgramError::Custom(17))) } else { - // Validate Owner inner_test_validate_owner( &src_owner, // expected_owner &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - assert_eq!(get_account(&accounts[0]).delegate().unwrap(), accounts[1].key()); + assert_eq!( + get_account(&accounts[0]).delegate().unwrap(), + accounts[1].key() + ); assert_eq!(get_account(&accounts[0]).delegated_amount(), amount); assert!(result.is_ok()) } @@ -1715,21 +1925,21 @@ fn test_process_approve(accounts: &[AccountInfo; 3], instruction_data: &[u8; 8]) /// accounts[2..13] // Signers #[inline(never)] fn test_process_revoke(accounts: &[AccountInfo; 2]) -> ProgramResult { - use pinocchio_token_interface::state::{account_state}; + use pinocchio_token_interface::state::account_state; cheatcode_is_account(&accounts[0]); // Source Account - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[1]); // Owner - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[1]); // Owner //-Initial State----------------------------------------------------------- let src_initialised = get_account(&accounts[0]).is_initialized(); let src_init_state = get_account(&accounts[0]).account_state(); let src_owner = get_account(&accounts[0]).owner; - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[1]).is_initialized()); //-Process Instruction----------------------------------------------------- @@ -1749,14 +1959,13 @@ fn test_process_revoke(accounts: &[AccountInfo; 2]) -> ProgramResult { } else if src_init_state.unwrap() == account_state::AccountState::Frozen { assert_eq!(result, Err(ProgramError::Custom(17))) } else { - // Validate Owner inner_test_validate_owner( &src_owner, // expected_owner &accounts[1], // owner_account_info &accounts[2..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; assert!(get_account(&accounts[0]).delegate().is_none()); @@ -1774,24 +1983,30 @@ fn test_process_revoke(accounts: &[AccountInfo; 2]) -> ProgramResult { /// instruction_data[1] // New Authority Follows (0 -> No, 1 -> Yes) /// instruction_data[2..34] // New Authority Pubkey #[inline(never)] -fn test_process_set_authority_account(accounts: &[AccountInfo; 2], instruction_data: &[u8; 34]) -> ProgramResult { +fn test_process_set_authority_account( + accounts: &[AccountInfo; 2], + instruction_data: &[u8; 34], +) -> ProgramResult { use pinocchio_token_interface::state::account_state; cheatcode_is_account(&accounts[0]); // Assume Account - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[1]); // Authority - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[1]); // Authority //-Initial State----------------------------------------------------------- let src_initialised = get_account(&accounts[0]).is_initialized(); let src_init_state = get_account(&accounts[0]).account_state(); let src_owner = get_account(&accounts[0]).owner; - let authority = get_account(&accounts[0]).close_authority().cloned().unwrap_or(get_account(&accounts[0]).owner); + let authority = get_account(&accounts[0]) + .close_authority() + .cloned() + .unwrap_or(get_account(&accounts[0]).owner); let account_data_len = accounts[0].data_len(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[1]).is_initialized()); //-Process Instruction----------------------------------------------------- @@ -1816,7 +2031,8 @@ fn test_process_set_authority_account(accounts: &[AccountInfo; 2], instruction_d } else if account_data_len != Account::LEN && account_data_len != Mint::LEN { assert_eq!(result, Err(ProgramError::InvalidArgument)); return result; - } else if account_data_len == Account::LEN { // established by cheatcode_is_account + } else if account_data_len == Account::LEN { + // established by cheatcode_is_account if src_initialised.is_err() { assert_eq!(result, Err(ProgramError::InvalidAccountData)); return result; @@ -1826,17 +2042,19 @@ fn test_process_set_authority_account(accounts: &[AccountInfo; 2], instruction_d } else if src_init_state.unwrap() == account_state::AccountState::Frozen { assert_eq!(result, Err(ProgramError::Custom(17))); return result; - } else if instruction_data[0] != 2 && instruction_data[0] != 3 { // AuthorityType neither AccountOwner nor CloseAccount + } else if instruction_data[0] != 2 && instruction_data[0] != 3 { + // AuthorityType neither AccountOwner nor CloseAccount assert_eq!(result, Err(ProgramError::Custom(15))); return result; - } else if instruction_data[0] == 2 { // AccountOwner + } else if instruction_data[0] == 2 { + // AccountOwner // Validate Owner inner_test_validate_owner( &src_owner, // expected_owner &accounts[1], // owner_account_info &accounts[2..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; if instruction_data[1] != 1 || instruction_data.len() < 34 { @@ -1851,8 +2069,8 @@ fn test_process_set_authority_account(accounts: &[AccountInfo; 2], instruction_d assert_eq!(get_account(&accounts[0]).close_authority(), None); } assert!(result.is_ok()) - - } else { // CloseAccount + } else { + // CloseAccount assert_eq!(instruction_data[0], 3); // If not AccountOwner (2), must be CloseAccount (3) // Validate Owner @@ -1861,11 +2079,15 @@ fn test_process_set_authority_account(accounts: &[AccountInfo; 2], instruction_d &accounts[1], // owner_account_info &accounts[2..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - if instruction_data[1] == 1 { // 1 ==> 34 <= instruction_data.len() - assert_eq!(get_account(&accounts[0]).close_authority().unwrap(), &instruction_data[2..34]); + if instruction_data[1] == 1 { + // 1 ==> 34 <= instruction_data.len() + assert_eq!( + get_account(&accounts[0]).close_authority().unwrap(), + &instruction_data[2..34] + ); } else { assert_eq!(get_account(&accounts[0]).close_authority(), None); } @@ -1875,8 +2097,6 @@ fn test_process_set_authority_account(accounts: &[AccountInfo; 2], instruction_d unreachable!() // account_data_len == Account::LEN must hold } - - result } @@ -1887,12 +2107,14 @@ fn test_process_set_authority_account(accounts: &[AccountInfo; 2], instruction_d /// instruction_data[1] // New Authority Follows (0 -> No, 1 -> Yes) /// instruction_data[2..34] // New Authority Pubkey #[inline(never)] -fn test_process_set_authority_mint(accounts: &[AccountInfo; 2], instruction_data: &[u8; 34]) -> ProgramResult { - - cheatcode_is_mint(&accounts[0]); // Assume Mint - #[cfg(not(feature="multisig"))] - cheatcode_is_account(&accounts[1]); // Authority - #[cfg(feature="multisig")] +fn test_process_set_authority_mint( + accounts: &[AccountInfo; 2], + instruction_data: &[u8; 34], +) -> ProgramResult { + cheatcode_is_mint(&accounts[0]); // Assume Mint + #[cfg(not(feature = "multisig"))] + cheatcode_is_account(&accounts[1]); // Authority + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[1]); // Authority //-Initial State----------------------------------------------------------- @@ -1901,9 +2123,9 @@ fn test_process_set_authority_mint(accounts: &[AccountInfo; 2], instruction_data let old_freeze_authority_is_none = get_mint(&accounts[0]).freeze_authority().is_none(); let old_mint_authority = get_mint(&accounts[0]).mint_authority().cloned(); let old_freeze_authority = get_mint(&accounts[0]).freeze_authority().cloned(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[1]).is_initialized()); let mint_is_initialised = get_mint(&accounts[0]).is_initialized(); @@ -1929,14 +2151,17 @@ fn test_process_set_authority_mint(accounts: &[AccountInfo; 2], instruction_data } else if mint_data_len != Account::LEN && mint_data_len != Mint::LEN { assert_eq!(result, Err(ProgramError::InvalidArgument)); return result; - } else if mint_data_len == Mint::LEN { // established by cheatcode_is_mint + } else if mint_data_len == Mint::LEN { + // established by cheatcode_is_mint if !mint_is_initialised.unwrap() { assert_eq!(result, Err(ProgramError::UninitializedAccount)); return result; - } else if instruction_data[0] != 0 && instruction_data[0] != 1 { // AuthorityType neither MintTokens nor FreezeAccount + } else if instruction_data[0] != 0 && instruction_data[0] != 1 { + // AuthorityType neither MintTokens nor FreezeAccount assert_eq!(result, Err(ProgramError::Custom(15))); return result; - } else if instruction_data[0] == 0 { // MintTokens + } else if instruction_data[0] == 0 { + // MintTokens if old_mint_authority_is_none { assert_eq!(result, Err(ProgramError::Custom(5))); return result; @@ -1948,17 +2173,21 @@ fn test_process_set_authority_mint(accounts: &[AccountInfo; 2], instruction_data &accounts[1], // owner_account_info &accounts[2..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - if instruction_data[1] == 1 { // 1 ==> 34 <= instruction_data.len() - assert_eq!(get_mint(&accounts[0]).mint_authority().unwrap(), &instruction_data[2..34]); + if instruction_data[1] == 1 { + // 1 ==> 34 <= instruction_data.len() + assert_eq!( + get_mint(&accounts[0]).mint_authority().unwrap(), + &instruction_data[2..34] + ); } else { assert_eq!(get_mint(&accounts[0]).mint_authority(), None); } assert!(result.is_ok()) - - } else { // FreezeAccount + } else { + // FreezeAccount assert_eq!(instruction_data[0], 1); // If not MintTokens (0), must be FreezeAccount (1) if old_freeze_authority_is_none { assert_eq!(result, Err(ProgramError::Custom(16))); @@ -1971,11 +2200,15 @@ fn test_process_set_authority_mint(accounts: &[AccountInfo; 2], instruction_data &accounts[1], // owner_account_info &accounts[2..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - if instruction_data[1] == 1 { // 1 ==> 34 <= instruction_data.len() - assert_eq!(get_mint(&accounts[0]).freeze_authority().unwrap(), &instruction_data[2..34]); + if instruction_data[1] == 1 { + // 1 ==> 34 <= instruction_data.len() + assert_eq!( + get_mint(&accounts[0]).freeze_authority().unwrap(), + &instruction_data[2..34] + ); } else { assert_eq!(get_mint(&accounts[0]).freeze_authority(), None); } @@ -1994,13 +2227,13 @@ fn test_process_set_authority_mint(accounts: &[AccountInfo; 2], instruction_data /// accounts[3..13] // Signers #[inline(never)] fn test_process_freeze_account(accounts: &[AccountInfo; 3]) -> ProgramResult { - use pinocchio_token_interface::state::{account_state}; + use pinocchio_token_interface::state::account_state; cheatcode_is_account(&accounts[0]); cheatcode_is_mint(&accounts[1]); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[2]); - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[2]); //-Initial State----------------------------------------------------------- @@ -2010,9 +2243,9 @@ fn test_process_freeze_account(accounts: &[AccountInfo; 3]) -> ProgramResult { let src_mint = get_account(&accounts[0]).mint; let mint_initialised = get_mint(&accounts[1]).is_initialized(); let mint_freeze_auth = get_mint(&accounts[1]).freeze_authority().cloned(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[2]).is_initialized()); //-Process Instruction----------------------------------------------------- @@ -2044,17 +2277,19 @@ fn test_process_freeze_account(accounts: &[AccountInfo; 3]) -> ProgramResult { } else if mint_freeze_auth.is_none() { assert_eq!(result, Err(ProgramError::Custom(16))) } else { - // Validate Owner inner_test_validate_owner( &mint_freeze_auth.unwrap(), // expected_owner &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - assert_eq!(get_account(&accounts[0]).account_state().unwrap(), account_state::AccountState::Frozen); + assert_eq!( + get_account(&accounts[0]).account_state().unwrap(), + account_state::AccountState::Frozen + ); assert!(result.is_ok()) } result @@ -2066,13 +2301,13 @@ fn test_process_freeze_account(accounts: &[AccountInfo; 3]) -> ProgramResult { /// accounts[3..13] // Signers #[inline(never)] fn test_process_thaw_account(accounts: &[AccountInfo; 3]) -> ProgramResult { - use pinocchio_token_interface::state::{account_state}; + use pinocchio_token_interface::state::account_state; cheatcode_is_account(&accounts[0]); cheatcode_is_mint(&accounts[1]); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[2]); - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[2]); //-Initial State----------------------------------------------------------- @@ -2082,9 +2317,9 @@ fn test_process_thaw_account(accounts: &[AccountInfo; 3]) -> ProgramResult { let src_mint = get_account(&accounts[0]).mint; let mint_initialised = get_mint(&accounts[1]).is_initialized(); let mint_freeze_auth = get_mint(&accounts[1]).freeze_authority().cloned(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[2]).is_initialized()); //-Process Instruction----------------------------------------------------- @@ -2116,17 +2351,19 @@ fn test_process_thaw_account(accounts: &[AccountInfo; 3]) -> ProgramResult { } else if mint_freeze_auth.is_none() { assert_eq!(result, Err(ProgramError::Custom(16))) } else { - // Validate Owner inner_test_validate_owner( &mint_freeze_auth.unwrap(), // expected_owner &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - assert_eq!(get_account(&accounts[0]).account_state().unwrap(), account_state::AccountState::Initialized); + assert_eq!( + get_account(&accounts[0]).account_state().unwrap(), + account_state::AccountState::Initialized + ); assert!(result.is_ok()) } result @@ -2139,15 +2376,18 @@ fn test_process_thaw_account(accounts: &[AccountInfo; 3]) -> ProgramResult { /// accounts[4..15] // Signers /// instruction_data[0..9] // Little Endian Bytes of u64 amount, and decimals #[inline(never)] -fn test_process_approve_checked(accounts: &[AccountInfo; 4], instruction_data: &[u8; 9]) -> ProgramResult { - use pinocchio_token_interface::state::{account_state}; +fn test_process_approve_checked( + accounts: &[AccountInfo; 4], + instruction_data: &[u8; 9], +) -> ProgramResult { + use pinocchio_token_interface::state::account_state; cheatcode_is_account(&accounts[0]); // Source Account - cheatcode_is_mint(&accounts[1]); // Expected Mint + cheatcode_is_mint(&accounts[1]); // Expected Mint cheatcode_is_account(&accounts[2]); // Delegate - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[3]); // Owner - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[3]); // Owner //-Initial State----------------------------------------------------------- @@ -2156,9 +2396,9 @@ fn test_process_approve_checked(accounts: &[AccountInfo; 4], instruction_data: & let src_initialised = get_account(&accounts[0]).is_initialized(); let src_init_state = get_account(&accounts[0]).account_state(); let mint_initialised = get_mint(&accounts[1]).is_initialized(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[3]).is_initialized()); //-Process Instruction----------------------------------------------------- @@ -2175,7 +2415,8 @@ fn test_process_approve_checked(accounts: &[AccountInfo; 4], instruction_data: & assert_eq!(result, Err(ProgramError::InvalidAccountData)) } else if !src_initialised.unwrap() { assert_eq!(result, Err(ProgramError::UninitializedAccount)) - } else if src_init_state.unwrap() == account_state::AccountState::Frozen { // This should be safe to unwrap due to above check passing + } else if src_init_state.unwrap() == account_state::AccountState::Frozen { + // This should be safe to unwrap due to above check passing assert_eq!(result, Err(ProgramError::Custom(17))) } else if accounts[1].key() != &get_account(&accounts[0]).mint { assert_eq!(result, Err(ProgramError::Custom(3))) @@ -2189,17 +2430,19 @@ fn test_process_approve_checked(accounts: &[AccountInfo; 4], instruction_data: & } else if instruction_data[8] != get_mint(&accounts[1]).decimals { assert_eq!(result, Err(ProgramError::Custom(18))) } else { - // Validate Owner inner_test_validate_owner( &src_owner, // expected_owner &accounts[3], // owner_account_info &accounts[4..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - assert_eq!(get_account(&accounts[0]).delegate().unwrap(), accounts[2].key()); + assert_eq!( + get_account(&accounts[0]).delegate().unwrap(), + accounts[2].key() + ); assert_eq!(get_account(&accounts[0]).delegated_amount(), amount); assert!(result.is_ok()) } @@ -2213,14 +2456,17 @@ fn test_process_approve_checked(accounts: &[AccountInfo; 4], instruction_data: & /// accounts[3..14] // Signers /// instruction_data[0..9] // Little Endian Bytes of u64 amount, and decimals #[inline(never)] -fn test_process_mint_to_checked(accounts: &[AccountInfo; 3], instruction_data: &[u8; 9]) -> ProgramResult { - use pinocchio_token_interface::state::{account_state}; +fn test_process_mint_to_checked( + accounts: &[AccountInfo; 3], + instruction_data: &[u8; 9], +) -> ProgramResult { + use pinocchio_token_interface::state::account_state; cheatcode_is_mint(&accounts[0]); cheatcode_is_account(&accounts[1]); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[2]); - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[2]); //-Initial State----------------------------------------------------------- @@ -2229,9 +2475,9 @@ fn test_process_mint_to_checked(accounts: &[AccountInfo; 3], instruction_data: & let mint_initialised = get_mint(&accounts[0]).is_initialized(); let dst_initialised = get_account(&accounts[1]).is_initialized(); let dst_init_state = get_account(&accounts[1]).account_state(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[2]).is_initialized()); //-Process Instruction----------------------------------------------------- @@ -2244,7 +2490,9 @@ fn test_process_mint_to_checked(accounts: &[AccountInfo; 3], instruction_data: & } else if accounts.len() < 3 { assert_eq!(result, Err(ProgramError::NotEnoughAccountKeys)); return result; - } else if accounts[1].data_len() != Account::LEN { // TODO Daniel: is it possible for something to be provided that has the same len but is not an account? + } else if accounts[1].data_len() != Account::LEN { + // TODO Daniel: is it possible for something to be provided that has the same + // len but is not an account? assert_eq!(result, Err(ProgramError::InvalidAccountData)); return result; } else if dst_initialised.is_err() { @@ -2253,7 +2501,8 @@ fn test_process_mint_to_checked(accounts: &[AccountInfo; 3], instruction_data: & } else if !dst_initialised.unwrap() { assert_eq!(result, Err(ProgramError::UninitializedAccount)); return result; - } else if dst_init_state.unwrap() == account_state::AccountState::Frozen { // unwrap must succeed due to dst_initialised not being err + } else if dst_init_state.unwrap() == account_state::AccountState::Frozen { + // unwrap must succeed due to dst_initialised not being err assert_eq!(result, Err(ProgramError::Custom(17))); return result; } else if get_account(&accounts[1]).is_native() { @@ -2277,22 +2526,20 @@ fn test_process_mint_to_checked(accounts: &[AccountInfo; 3], instruction_data: & return result; } else { if get_mint(&accounts[0]).mint_authority().is_some() { - // Validate Owner inner_test_validate_owner( get_mint(&accounts[0]).mint_authority().unwrap(), // expected_owner &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - } else { assert_eq!(result, Err(ProgramError::Custom(5))); return result; } - let amount = unsafe { u64::from_le_bytes(*(instruction_data.as_ptr() as *const [u8; 8])) }; + let amount = unsafe { u64::from_le_bytes(*(instruction_data.as_ptr() as *const [u8; 8])) }; if amount == 0 && accounts[0].owner() != &pinocchio_token_interface::program::ID { assert_eq!(result, Err(ProgramError::IncorrectProgramId)); @@ -2347,7 +2594,10 @@ fn test_process_sync_native(accounts: &[AccountInfo; 1]) -> ProgramResult { } else if src_init_lamports - src_native_amount.unwrap() < src_init_amount { assert_eq!(result, Err(ProgramError::Custom(13))) } else { - assert_eq!(get_account(&accounts[0]).amount(), src_init_lamports - src_native_amount.unwrap()); + assert_eq!( + get_account(&accounts[0]).amount(), + src_init_lamports - src_native_amount.unwrap() + ); assert!(result.is_ok()) } result @@ -2358,8 +2608,10 @@ fn test_process_sync_native(accounts: &[AccountInfo; 1]) -> ProgramResult { /// accounts[1..].len() // n /// instruction_data[1] // m #[inline(never)] -fn test_process_initialize_multisig2(accounts: &[AccountInfo; 4], instruction_data: &[u8; 1]) -> ProgramResult { - // ^ FIXME: totally arbitrary for the tests +fn test_process_initialize_multisig2( + accounts: &[AccountInfo; 4], + instruction_data: &[u8; 1], +) -> ProgramResult { cheatcode_is_multisig(&accounts[0]); cheatcode_is_account(&accounts[1]); // Signer cheatcode_is_account(&accounts[2]); // Signer @@ -2368,7 +2620,8 @@ fn test_process_initialize_multisig2(accounts: &[AccountInfo; 4], instruction_da //-Initial State----------------------------------------------------------- let multisig_already_initialised = get_multisig(&accounts[0]).is_initialized(); let multisig_init_lamports = accounts[0].lamports(); - // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be impossible + // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be + // impossible let rent = pinocchio::sysvars::rent::Rent::get().unwrap(); let minimum_balance = rent.minimum_balance(accounts[0].data_len()); @@ -2396,14 +2649,11 @@ fn test_process_initialize_multisig2(accounts: &[AccountInfo; 4], instruction_da assert!(accounts[1..] .iter() .map(|signer| *signer.key()) - .eq( - get_multisig(&accounts[0]) + .eq(get_multisig(&accounts[0]) .signers .iter() .take(accounts[1..].len()) - .copied() - ) - ); + .copied())); assert_eq!(get_multisig(&accounts[0]).m, instruction_data[0]); assert_eq!(get_multisig(&accounts[0]).n as usize, accounts.len() - 1); assert!(get_multisig(&accounts[0]).is_initialized().is_ok()); @@ -2469,7 +2719,10 @@ fn test_process_initialize_immutable_owner(accounts: &[AccountInfo; 1]) -> Progr } #[inline(never)] -fn test_process_amount_to_ui_amount(accounts: &[AccountInfo; 1], instruction_data: &[u8; 8]) -> ProgramResult { +fn test_process_amount_to_ui_amount( + accounts: &[AccountInfo; 1], + instruction_data: &[u8; 8], +) -> ProgramResult { cheatcode_is_mint(&accounts[0]); //-Initial State----------------------------------------------------------- @@ -2498,7 +2751,10 @@ fn test_process_amount_to_ui_amount(accounts: &[AccountInfo; 1], instruction_dat } #[inline(never)] -fn test_process_ui_amount_to_amount(accounts: &[AccountInfo; 1], instruction_data: &[u8]) -> ProgramResult { +fn test_process_ui_amount_to_amount( + accounts: &[AccountInfo; 1], + instruction_data: &[u8], +) -> ProgramResult { cheatcode_is_mint(&accounts[0]); //-Initial State----------------------------------------------------------- @@ -2528,23 +2784,33 @@ fn test_process_ui_amount_to_amount(accounts: &[AccountInfo; 1], instruction_dat assert_eq!(result, Err(ProgramError::InvalidArgument)) } else if 1 < ui_amount.unwrap().chars().filter(|&c| c == '.').count() { assert_eq!(result, Err(ProgramError::InvalidArgument)) - } else if ui_amount.unwrap().starts_with('.') && ui_amount.unwrap().chars().skip(1).all(|c| c == '0') { + } else if ui_amount.unwrap().starts_with('.') + && ui_amount.unwrap().chars().skip(1).all(|c| c == '0') + { assert_eq!(result, Err(ProgramError::InvalidArgument)) - } else if ui_amount.unwrap().split_once('.').is_some_and(|(_, frac)| { (get_mint(&accounts[0]).decimals as usize) < frac.trim_end_matches('0').len()}) { + } else if ui_amount.unwrap().split_once('.').is_some_and(|(_, frac)| { + (get_mint(&accounts[0]).decimals as usize) < frac.trim_end_matches('0').len() + }) { assert_eq!(result, Err(ProgramError::InvalidArgument)) } else if ui_amount.unwrap().split_once('.').map_or( 257_usize < ui_amount.unwrap().len() + (get_mint(&accounts[0]).decimals as usize), - |(ints, _)| { 257_usize < ints.len() + (get_mint(&accounts[0]).decimals as usize) }) { - assert_eq!(result, Err(ProgramError::InvalidArgument)) - } /*else if ui_amount.unwrap() == "+." { + |(ints, _)| 257_usize < ints.len() + (get_mint(&accounts[0]).decimals as usize), + ) { + assert_eq!(result, Err(ProgramError::InvalidArgument)) + } + /*else if ui_amount.unwrap() == "+." { // TODO: Why is this valid? assert_eq!(result, Err(ProgramError::InvalidArgument)) } else if ui_amount.unwrap() == "+" { // TODO: Why is this valid? assert_eq!(result, Err(ProgramError::InvalidArgument)) - }*/ else if ui_amount.unwrap().starts_with('-') { + }*/ + else if ui_amount.unwrap().starts_with('-') { assert_eq!(result, Err(ProgramError::InvalidArgument)) - } else if ui_amount.unwrap().contains(|c: char| !c.is_ascii_digit() && c != '+' && c != '.') { + } else if ui_amount + .unwrap() + .contains(|c: char| !c.is_ascii_digit() && c != '+' && c != '.') + { assert_eq!(result, Err(ProgramError::InvalidArgument)) } else if ui_amount.unwrap().split_once('.').map_or( { @@ -2562,13 +2828,17 @@ fn test_process_ui_amount_to_amount(accounts: &[AccountInfo; 1], instruction_dat const MAX_VAL: &str = "1844674407370955"; // TODO: What should this be? let ints = ints.strip_prefix('+').unwrap_or(ints); let hi = ints.trim_start_matches('0'); - let lo = if hi.is_empty() { fracs.trim_start_matches('0') } else { fracs }; + let lo = if hi.is_empty() { + fracs.trim_start_matches('0') + } else { + fracs + }; let total_len = hi.len() + lo.len(); match total_len.cmp(&MAX_VAL.len()) { core::cmp::Ordering::Less => false, - core::cmp::Ordering::Greater => { true }, + core::cmp::Ordering::Greater => true, core::cmp::Ordering::Equal => { if hi.len() > MAX_VAL.len() { return true; @@ -2577,7 +2847,7 @@ fn test_process_ui_amount_to_amount(accounts: &[AccountInfo; 1], instruction_dat hi > max_hi || (hi == max_hi && lo > max_lo) } } - } + }, ) { // TODO: What is going on ??? Need to fix // assert_eq!(result, Err(ProgramError::InvalidArgument)) @@ -2593,12 +2863,11 @@ fn test_process_ui_amount_to_amount(accounts: &[AccountInfo; 1], instruction_dat /// accounts[3..14] // Signers #[inline(never)] fn test_process_withdraw_excess_lamports_account(accounts: &[AccountInfo; 3]) -> ProgramResult { - cheatcode_is_account(&accounts[0]); // Source Account cheatcode_is_account(&accounts[1]); // Destination - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[2]); // Authority - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[2]); // Authority //-Initial State----------------------------------------------------------- @@ -2608,12 +2877,13 @@ fn test_process_withdraw_excess_lamports_account(accounts: &[AccountInfo; 3]) -> let src_account_is_native = get_account(&accounts[0]).is_native(); let src_init_lamports = accounts[0].lamports(); let dst_init_lamports = accounts[1].lamports(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[2]).is_initialized()); - // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be impossible + // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be + // impossible let rent = pinocchio::sysvars::rent::Rent::get().unwrap(); let minimum_balance = rent.minimum_balance(accounts[0].data_len()); @@ -2644,7 +2914,7 @@ fn test_process_withdraw_excess_lamports_account(accounts: &[AccountInfo; 3]) -> &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; if src_init_lamports < minimum_balance { @@ -2656,7 +2926,10 @@ fn test_process_withdraw_excess_lamports_account(accounts: &[AccountInfo; 3]) -> } assert_eq!(accounts[0].lamports(), minimum_balance); - assert_eq!(accounts[1].lamports(), dst_init_lamports + src_init_lamports - minimum_balance); + assert_eq!( + accounts[1].lamports(), + dst_init_lamports + src_init_lamports - minimum_balance + ); assert!(result.is_ok()) } } @@ -2670,12 +2943,11 @@ fn test_process_withdraw_excess_lamports_account(accounts: &[AccountInfo; 3]) -> /// accounts[3..14] // Signers #[inline(never)] fn test_process_withdraw_excess_lamports_mint(accounts: &[AccountInfo; 3]) -> ProgramResult { - cheatcode_is_mint(&accounts[0]); // Source Account (Mint) cheatcode_is_account(&accounts[1]); // Destination - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[2]); // Authority - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[2]); // Authority //-Initial State----------------------------------------------------------- @@ -2684,12 +2956,13 @@ fn test_process_withdraw_excess_lamports_mint(accounts: &[AccountInfo; 3]) -> Pr let src_mint_mint_authority = get_mint(&accounts[0]).mint_authority().cloned(); let src_init_lamports = accounts[0].lamports(); let dst_init_lamports = accounts[1].lamports(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[2]).is_initialized()); - // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be impossible + // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be + // impossible let rent = pinocchio::sysvars::rent::Rent::get().unwrap(); let minimum_balance = rent.minimum_balance(accounts[0].data_len()); @@ -2710,25 +2983,21 @@ fn test_process_withdraw_excess_lamports_mint(accounts: &[AccountInfo; 3]) -> Pr assert_eq!(result, Err(ProgramError::UninitializedAccount)); return result; } else if src_mint_mint_authority.is_some() { - // Validate Owner inner_test_validate_owner( &src_mint_mint_authority.unwrap(), // expected_owner &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; - } else if accounts[0] != accounts[2] { assert_eq!(result, Err(ProgramError::Custom(15))); return result; } else if !accounts[2].is_signer() { assert_eq!(result, Err(ProgramError::MissingRequiredSignature)); return result; - } - - else if src_init_lamports < minimum_balance { + } else if src_init_lamports < minimum_balance { assert_eq!(result, Err(ProgramError::Custom(0))); return result; } else if u64::MAX - src_init_lamports + minimum_balance < dst_init_lamports { @@ -2737,7 +3006,10 @@ fn test_process_withdraw_excess_lamports_mint(accounts: &[AccountInfo; 3]) -> Pr } assert_eq!(accounts[0].lamports(), minimum_balance); - assert_eq!(accounts[1].lamports(), dst_init_lamports + src_init_lamports - minimum_balance); + assert_eq!( + accounts[1].lamports(), + dst_init_lamports + src_init_lamports - minimum_balance + ); assert!(result.is_ok()) } } @@ -2751,24 +3023,24 @@ fn test_process_withdraw_excess_lamports_mint(accounts: &[AccountInfo; 3]) -> Pr /// accounts[3..14] // Signers #[inline(never)] fn test_process_withdraw_excess_lamports_multisig(accounts: &[AccountInfo; 3]) -> ProgramResult { - cheatcode_is_multisig(&accounts[0]); // Source Account (Multisig) cheatcode_is_account(&accounts[1]); // Destination - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] cheatcode_is_account(&accounts[2]); // Authority - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] cheatcode_is_multisig(&accounts[2]); // Authority //-Initial State----------------------------------------------------------- let src_data_len = accounts[0].data_len(); let src_init_lamports = accounts[0].lamports(); let dst_init_lamports = accounts[1].lamports(); - #[cfg(not(feature="multisig"))] + #[cfg(not(feature = "multisig"))] let maybe_multisig_is_initialised = None; - #[cfg(feature="multisig")] + #[cfg(feature = "multisig")] let maybe_multisig_is_initialised = Some(get_multisig(&accounts[2]).is_initialized()); - // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be impossible + // Note: Rent is a supported sysvar so ProgramError::UnsupportedSysvar should be + // impossible let rent = pinocchio::sysvars::rent::Rent::get().unwrap(); let minimum_balance = rent.minimum_balance(accounts[0].data_len()); @@ -2779,7 +3051,10 @@ fn test_process_withdraw_excess_lamports_multisig(accounts: &[AccountInfo; 3]) - if accounts.len() < 3 { assert_eq!(result, Err(ProgramError::NotEnoughAccountKeys)); return result; - } else if src_data_len != Account::LEN && src_data_len != Mint::LEN && src_data_len != Multisig::LEN { + } else if src_data_len != Account::LEN + && src_data_len != Mint::LEN + && src_data_len != Multisig::LEN + { assert_eq!(result, Err(ProgramError::Custom(13))); return result; } else { @@ -2791,7 +3066,7 @@ fn test_process_withdraw_excess_lamports_multisig(accounts: &[AccountInfo; 3]) - &accounts[2], // owner_account_info &accounts[3..], // tx_signers maybe_multisig_is_initialised, - result.clone() + result.clone(), )?; if src_init_lamports < minimum_balance { @@ -2803,7 +3078,10 @@ fn test_process_withdraw_excess_lamports_multisig(accounts: &[AccountInfo; 3]) - } assert_eq!(accounts[0].lamports(), minimum_balance); - assert_eq!(accounts[1].lamports(), dst_init_lamports + src_init_lamports - minimum_balance); + assert_eq!( + accounts[1].lamports(), + dst_init_lamports + src_init_lamports - minimum_balance + ); assert!(result.is_ok()) } diff --git a/p-token/src/entrypoint.rs b/p-token/src/entrypoint.rs index c33e9f1..2a48382 100644 --- a/p-token/src/entrypoint.rs +++ b/p-token/src/entrypoint.rs @@ -1,7 +1,11 @@ use { crate::processor::*, pinocchio::{ - account_info::AccountInfo, no_allocator, nostd_panic_handler, program_entrypoint, program_error::{ProgramError, ToStr}, pubkey::Pubkey, ProgramResult + account_info::AccountInfo, + no_allocator, nostd_panic_handler, program_entrypoint, + program_error::{ProgramError, ToStr}, + pubkey::Pubkey, + ProgramResult, }, pinocchio_token_interface::error::TokenError, }; diff --git a/p-token/src/stubs.rs b/p-token/src/stubs.rs index 4ffb65f..1c74d35 100644 --- a/p-token/src/stubs.rs +++ b/p-token/src/stubs.rs @@ -9,4 +9,4 @@ pub unsafe extern "C" fn sol_memcpy_(dst: *mut u8, src: *const u8, n: usize) { if !dst.is_null() && !src.is_null() && n > 0 { core::ptr::copy_nonoverlapping(src, dst, n); } -} \ No newline at end of file +} diff --git a/p-token/tests/approve.rs b/p-token/tests/approve.rs index 76acefe..a37d657 100644 --- a/p-token/tests/approve.rs +++ b/p-token/tests/approve.rs @@ -144,7 +144,13 @@ async fn _approve_invalid_src() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } #[tokio::test] @@ -202,7 +208,11 @@ async fn approve_frozen() { &[&context.payer, &freeze_authority], context.last_blockhash, ); - context.banks_client.process_transaction(freeze_tx).await.unwrap(); + context + .banks_client + .process_transaction(freeze_tx) + .await + .unwrap(); // When we approve a delegate. @@ -226,5 +236,11 @@ async fn approve_frozen() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(17) + ) + ); } diff --git a/p-token/tests/approve_checked.rs b/p-token/tests/approve_checked.rs index 154d7b2..49bfef4 100644 --- a/p-token/tests/approve_checked.rs +++ b/p-token/tests/approve_checked.rs @@ -148,7 +148,13 @@ async fn _approve_checked_invalid_src() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } #[tokio::test] @@ -206,7 +212,11 @@ async fn approve_checked_frozen() { &[&context.payer, &freeze_authority], context.last_blockhash, ); - context.banks_client.process_transaction(freeze_tx).await.unwrap(); + context + .banks_client + .process_transaction(freeze_tx) + .await + .unwrap(); // When we approve a delegate. @@ -232,7 +242,13 @@ async fn approve_checked_frozen() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(17) + ) + ); } #[tokio::test] @@ -297,7 +313,13 @@ async fn approve_checked_mint_mismatch() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(3) + ) + ); } #[tokio::test] @@ -362,5 +384,11 @@ async fn approve_checked_incorrect_decimals() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(18))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(18) + ) + ); } diff --git a/p-token/tests/burn.rs b/p-token/tests/burn.rs index dc35ffc..03dd2ea 100644 --- a/p-token/tests/burn.rs +++ b/p-token/tests/burn.rs @@ -114,9 +114,15 @@ async fn _burn_invalid_source() { // When we burn 50 tokens. - let burn_ix = - spl_token::instruction::burn(&spl_token::ID, &Pubkey::new_unique(), &mint, &owner.pubkey(), &[], 50) - .unwrap(); // Invalid sender + let burn_ix = spl_token::instruction::burn( + &spl_token::ID, + &Pubkey::new_unique(), + &mint, + &owner.pubkey(), + &[], + 50, + ) + .unwrap(); // Invalid sender let tx = Transaction::new_signed_with_payer( &[burn_ix], @@ -126,7 +132,13 @@ async fn _burn_invalid_source() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } #[tokio::test] @@ -182,7 +194,11 @@ async fn burn_frozen_source() { &[&context.payer, &freeze_authority], context.last_blockhash, ); - context.banks_client.process_transaction(freeze_tx).await.unwrap(); + context + .banks_client + .process_transaction(freeze_tx) + .await + .unwrap(); // When we burn 50 tokens. @@ -198,7 +214,13 @@ async fn burn_frozen_source() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(17) + ) + ); } #[tokio::test] @@ -230,7 +252,13 @@ async fn burn_native() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(10))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(10) + ) + ); } #[tokio::test] @@ -285,7 +313,13 @@ async fn burn_excessive_amount() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(1))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(1) + ) + ); } #[tokio::test] @@ -330,9 +364,15 @@ async fn burn_different_mint() { // When we burn 50 tokens. - let burn_ix = - spl_token::instruction::burn(&spl_token::ID, &account, &native_mint, &owner.pubkey(), &[], 50) - .unwrap(); + let burn_ix = spl_token::instruction::burn( + &spl_token::ID, + &account, + &native_mint, + &owner.pubkey(), + &[], + 50, + ) + .unwrap(); let tx = Transaction::new_signed_with_payer( &[burn_ix], @@ -342,5 +382,11 @@ async fn burn_different_mint() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(3) + ) + ); } diff --git a/p-token/tests/burn_checked.rs b/p-token/tests/burn_checked.rs index 5fad0ba..1aaa743 100644 --- a/p-token/tests/burn_checked.rs +++ b/p-token/tests/burn_checked.rs @@ -140,7 +140,13 @@ async fn _burn_checked_invalid_source() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } #[tokio::test] @@ -196,7 +202,11 @@ async fn burn_checked_frozen_source() { &[&context.payer, &freeze_authority], context.last_blockhash, ); - context.banks_client.process_transaction(freeze_tx).await.unwrap(); + context + .banks_client + .process_transaction(freeze_tx) + .await + .unwrap(); // When we burn 50 tokens. @@ -219,7 +229,13 @@ async fn burn_checked_frozen_source() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(17) + ) + ); } #[tokio::test] @@ -258,7 +274,13 @@ async fn burn_checked_native() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(10))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(10) + ) + ); } #[tokio::test] @@ -320,7 +342,13 @@ async fn burn_checked_excessive_amount() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(1))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(1) + ) + ); } #[tokio::test] @@ -384,7 +412,13 @@ async fn burn_checked_different_mint() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(3) + ) + ); } #[tokio::test] @@ -446,5 +480,11 @@ async fn burn_checked_incorrect_decimals() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(18))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(18) + ) + ); } diff --git a/p-token/tests/close_account.rs b/p-token/tests/close_account.rs index 6d880e7..457a39d 100644 --- a/p-token/tests/close_account.rs +++ b/p-token/tests/close_account.rs @@ -113,7 +113,13 @@ async fn close_same_accounts() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } // #[tokio::test] @@ -165,7 +171,13 @@ async fn _close_invalid_source() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } #[tokio::test] @@ -228,5 +240,11 @@ async fn close_non_native_with_balance() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(11))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(11) + ) + ); } diff --git a/p-token/tests/freeze_account.rs b/p-token/tests/freeze_account.rs index a8f6691..5822383 100644 --- a/p-token/tests/freeze_account.rs +++ b/p-token/tests/freeze_account.rs @@ -120,14 +120,20 @@ async fn _freeze_account_invalid_source() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } // TODO: Why does this not fail? // #[tokio::test] // async fn freeze_account_double_freeze() { -// let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None) -// .start_with_context() +// let mut context = ProgramTest::new("pinocchio_token_program", +// TOKEN_PROGRAM_ID, None) .start_with_context() // .await; // // Given a mint account. @@ -149,10 +155,12 @@ async fn _freeze_account_invalid_source() { // let owner = Keypair::new(); // let account = -// account::initialize(&mut context, &mint, &owner.pubkey(), &TOKEN_PROGRAM_ID).await; +// account::initialize(&mut context, &mint, &owner.pubkey(), +// &TOKEN_PROGRAM_ID).await; -// let token_account = context.banks_client.get_account(account).await.unwrap(); -// assert!(token_account.is_some()); +// let token_account = +// context.banks_client.get_account(account).await.unwrap(); assert! +// (token_account.is_some()); // // When we freeze the account. @@ -175,11 +183,13 @@ async fn _freeze_account_invalid_source() { // // Then the account is frozen. -// let token_account = context.banks_client.get_account(account).await.unwrap(); -// assert!(token_account.is_some()); +// let token_account = +// context.banks_client.get_account(account).await.unwrap(); assert! +// (token_account.is_some()); // let token_account = token_account.unwrap(); -// let token_account = spl_token::state::Account::unpack(&token_account.data).unwrap(); +// let token_account = +// spl_token::state::Account::unpack(&token_account.data).unwrap(); // assert_eq!(token_account.state, AccountState::Frozen); @@ -202,8 +212,9 @@ async fn _freeze_account_invalid_source() { // ); // let result = context.banks_client.process_transaction(tx).await; // let inner_error = result.err().unwrap().unwrap(); -// assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(13))); -// } +// assert_eq!(inner_error, +// solana_transaction_error::TransactionError::InstructionError(0, +// solana_instruction::error::InstructionError::Custom(13))); } #[tokio::test] async fn freeze_account_native() { @@ -211,7 +222,6 @@ async fn freeze_account_native() { .start_with_context() .await; - let mint = Pubkey::from(pinocchio_token_interface::native_mint::ID); // And a token account. @@ -244,7 +254,13 @@ async fn freeze_account_native() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(10))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(10) + ) + ); } #[tokio::test] @@ -296,7 +312,13 @@ async fn freeze_account_mint_mismatch() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(3) + ) + ); } #[tokio::test] @@ -348,5 +370,11 @@ async fn freeze_account_no_freeze_auth() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(16))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(16) + ) + ); } diff --git a/p-token/tests/get_account_data_size.rs b/p-token/tests/get_account_data_size.rs index 8d13561..11134ec 100644 --- a/p-token/tests/get_account_data_size.rs +++ b/p-token/tests/get_account_data_size.rs @@ -28,7 +28,8 @@ async fn get_account_data_size() { .await .unwrap(); - let get_size_ix = spl_token::instruction::get_account_data_size(&TOKEN_PROGRAM_ID, &mint).unwrap(); + let get_size_ix = + spl_token::instruction::get_account_data_size(&TOKEN_PROGRAM_ID, &mint).unwrap(); let tx = Transaction::new_signed_with_payer( &[get_size_ix], diff --git a/p-token/tests/initialize_multisig.rs b/p-token/tests/initialize_multisig.rs index 0153ba0..7cc34a3 100644 --- a/p-token/tests/initialize_multisig.rs +++ b/p-token/tests/initialize_multisig.rs @@ -120,5 +120,11 @@ async fn _initialize_multisig_invalid_multisig() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(1, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 1, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } diff --git a/p-token/tests/initialize_multisig2.rs b/p-token/tests/initialize_multisig2.rs index 999b527..d289ce9 100644 --- a/p-token/tests/initialize_multisig2.rs +++ b/p-token/tests/initialize_multisig2.rs @@ -120,5 +120,11 @@ async fn _initialize_multisig2_invalid_multisig() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(1, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 1, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } diff --git a/p-token/tests/mint_to.rs b/p-token/tests/mint_to.rs index 6e36764..f8cc746 100644 --- a/p-token/tests/mint_to.rs +++ b/p-token/tests/mint_to.rs @@ -107,7 +107,13 @@ async fn _mint_to_invalid_destination() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } #[tokio::test] @@ -164,7 +170,11 @@ async fn mint_to_frozen_account() { &[&context.payer, &freeze_authority], context.last_blockhash, ); - context.banks_client.process_transaction(freeze_tx).await.unwrap(); + context + .banks_client + .process_transaction(freeze_tx) + .await + .unwrap(); let tx = Transaction::new_signed_with_payer( &[mint_ix], @@ -174,7 +184,13 @@ async fn mint_to_frozen_account() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(17) + ) + ); } #[tokio::test] @@ -216,7 +232,13 @@ async fn mint_to_native() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(10))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(10) + ) + ); } #[tokio::test] @@ -275,7 +297,13 @@ async fn mint_to_different_mint() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(3) + ) + ); } #[tokio::test] @@ -343,7 +371,13 @@ async fn mint_to_overflow() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(14))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(14) + ) + ); } #[tokio::test] diff --git a/p-token/tests/mint_to_checked.rs b/p-token/tests/mint_to_checked.rs index 8bf4df2..ae560f8 100644 --- a/p-token/tests/mint_to_checked.rs +++ b/p-token/tests/mint_to_checked.rs @@ -109,7 +109,13 @@ async fn _mint_to_checked_invalid_destination() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } #[tokio::test] @@ -167,7 +173,11 @@ async fn mint_to_checked_frozen_account() { &[&context.payer, &freeze_authority], context.last_blockhash, ); - context.banks_client.process_transaction(freeze_tx).await.unwrap(); + context + .banks_client + .process_transaction(freeze_tx) + .await + .unwrap(); let tx = Transaction::new_signed_with_payer( &[mint_ix], @@ -177,7 +187,13 @@ async fn mint_to_checked_frozen_account() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(17) + ) + ); } #[tokio::test] @@ -220,7 +236,13 @@ async fn mint_to_checked_native() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(10))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(10) + ) + ); } #[tokio::test] @@ -280,7 +302,13 @@ async fn mint_to_checked_different_mint() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(3) + ) + ); } #[tokio::test] @@ -331,7 +359,13 @@ async fn mint_to_checked_incorrect_decimals() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(18))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(18) + ) + ); } #[tokio::test] @@ -401,7 +435,13 @@ async fn mint_to_overflow() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(14))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(14) + ) + ); } #[tokio::test] diff --git a/p-token/tests/revoke.rs b/p-token/tests/revoke.rs index 9eab333..eac99a4 100644 --- a/p-token/tests/revoke.rs +++ b/p-token/tests/revoke.rs @@ -143,7 +143,8 @@ async fn _revoke_invalid_source() { // When we revoke the delegation. let revoke_ix = - spl_token::instruction::revoke(&spl_token::ID, &Pubkey::new_unique(), &owner.pubkey(), &[]).unwrap(); + spl_token::instruction::revoke(&spl_token::ID, &Pubkey::new_unique(), &owner.pubkey(), &[]) + .unwrap(); let tx = Transaction::new_signed_with_payer( &[revoke_ix], @@ -153,7 +154,13 @@ async fn _revoke_invalid_source() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } #[tokio::test] @@ -225,7 +232,11 @@ async fn revoke_frozen() { &[&context.payer, &freeze_authority], context.last_blockhash, ); - context.banks_client.process_transaction(freeze_tx).await.unwrap(); + context + .banks_client + .process_transaction(freeze_tx) + .await + .unwrap(); // When we revoke the delegation. @@ -240,5 +251,11 @@ async fn revoke_frozen() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(17) + ) + ); } diff --git a/p-token/tests/set_authority.rs b/p-token/tests/set_authority.rs index 75f44ba..c901d60 100644 --- a/p-token/tests/set_authority.rs +++ b/p-token/tests/set_authority.rs @@ -108,5 +108,11 @@ async fn _set_authority_invalid_account() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } diff --git a/p-token/tests/thaw_account.rs b/p-token/tests/thaw_account.rs index f41beab..7117157 100644 --- a/p-token/tests/thaw_account.rs +++ b/p-token/tests/thaw_account.rs @@ -138,14 +138,20 @@ async fn _thaw_account_invalid_src() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } // TODO: Why does this not fail? // #[tokio::test] // async fn thaw_account_double_thaw() { -// let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None) -// .start_with_context() +// let mut context = ProgramTest::new("pinocchio_token_program", +// TOKEN_PROGRAM_ID, None) .start_with_context() // .await; // // Given a mint account. @@ -167,10 +173,12 @@ async fn _thaw_account_invalid_src() { // let owner = Keypair::new(); // let account = -// account::initialize(&mut context, &mint, &owner.pubkey(), &TOKEN_PROGRAM_ID).await; +// account::initialize(&mut context, &mint, &owner.pubkey(), +// &TOKEN_PROGRAM_ID).await; -// let token_account = context.banks_client.get_account(account).await.unwrap(); -// assert!(token_account.is_some()); +// let token_account = +// context.banks_client.get_account(account).await.unwrap(); assert! +// (token_account.is_some()); // account::freeze( // &mut context, @@ -200,11 +208,13 @@ async fn _thaw_account_invalid_src() { // ); // context.banks_client.process_transaction(tx).await.unwrap(); -// let token_account = context.banks_client.get_account(account).await.unwrap(); -// assert!(token_account.is_some()); +// let token_account = +// context.banks_client.get_account(account).await.unwrap(); assert! +// (token_account.is_some()); // let token_account = token_account.unwrap(); -// let token_account = spl_token::state::Account::unpack(&token_account.data).unwrap(); +// let token_account = +// spl_token::state::Account::unpack(&token_account.data).unwrap(); // assert_eq!(token_account.state, AccountState::Initialized); @@ -227,8 +237,9 @@ async fn _thaw_account_invalid_src() { // ); // let result = context.banks_client.process_transaction(tx).await; // let inner_error = result.err().unwrap().unwrap(); -// assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(13))); -// } +// assert_eq!(inner_error, +// solana_transaction_error::TransactionError::InstructionError(0, +// solana_instruction::error::InstructionError::Custom(13))); } #[tokio::test] async fn thaw_account_already_thawed() { @@ -270,7 +281,13 @@ async fn thaw_account_already_thawed() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(13))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(13) + ) + ); } #[tokio::test] @@ -331,5 +348,11 @@ async fn thaw_account_mint_mismatch() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(3) + ) + ); } diff --git a/p-token/tests/transfer.rs b/p-token/tests/transfer.rs index a4d92e2..c12a402 100644 --- a/p-token/tests/transfer.rs +++ b/p-token/tests/transfer.rs @@ -148,7 +148,13 @@ async fn _transfer_src_uninit() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } // #[tokio::test] @@ -209,7 +215,13 @@ async fn _transfer_dst_uninit() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } #[tokio::test] @@ -272,7 +284,11 @@ async fn transfer_frozen() { &[&context.payer, &freeze_authority], context.last_blockhash, ); - context.banks_client.process_transaction(freeze_tx).await.unwrap(); + context + .banks_client + .process_transaction(freeze_tx) + .await + .unwrap(); let transfer_ix = spl_token::instruction::transfer( &spl_token::ID, @@ -293,7 +309,13 @@ async fn transfer_frozen() { let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(17) + ) + ); } #[tokio::test] @@ -351,7 +373,11 @@ async fn transfer_frozen_self() { &[&context.payer, &freeze_authority], context.last_blockhash, ); - context.banks_client.process_transaction(freeze_tx).await.unwrap(); + context + .banks_client + .process_transaction(freeze_tx) + .await + .unwrap(); let transfer_ix = spl_token::instruction::transfer( &spl_token::ID, @@ -372,7 +398,13 @@ async fn transfer_frozen_self() { let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(17) + ) + ); } #[tokio::test] @@ -439,7 +471,13 @@ async fn transfer_insufficient() { let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(1))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(1) + ) + ); } #[tokio::test] @@ -501,7 +539,13 @@ async fn transfer_insufficient_self() { let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(1))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(1) + ) + ); } #[tokio::test] @@ -523,7 +567,7 @@ async fn transfer_diff_mint() { ) .await .unwrap(); - + let mint2 = mint::initialize( &mut context, mint_authority.pubkey(), @@ -576,7 +620,13 @@ async fn transfer_diff_mint() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(3) + ) + ); } #[tokio::test] diff --git a/p-token/tests/transfer_checked.rs b/p-token/tests/transfer_checked.rs index 937f4c4..b711ed9 100644 --- a/p-token/tests/transfer_checked.rs +++ b/p-token/tests/transfer_checked.rs @@ -87,7 +87,6 @@ async fn transfer_checked() { assert!(account.amount == 0); } - // #[tokio::test] async fn _transfer_checked_src_uninit() { let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None) @@ -153,7 +152,13 @@ async fn _transfer_checked_src_uninit() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } // #[tokio::test] @@ -216,7 +221,13 @@ async fn _transfer_checked_dst_uninit() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidAccountData)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidAccountData + ) + ); } #[tokio::test] @@ -279,7 +290,11 @@ async fn transfer_checked_frozen() { &[&context.payer, &freeze_authority], context.last_blockhash, ); - context.banks_client.process_transaction(freeze_tx).await.unwrap(); + context + .banks_client + .process_transaction(freeze_tx) + .await + .unwrap(); let transfer_ix = spl_token::instruction::transfer_checked( &spl_token::ID, @@ -302,7 +317,13 @@ async fn transfer_checked_frozen() { let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(17) + ) + ); } #[tokio::test] @@ -360,7 +381,11 @@ async fn transfer_checked_frozen_self() { &[&context.payer, &freeze_authority], context.last_blockhash, ); - context.banks_client.process_transaction(freeze_tx).await.unwrap(); + context + .banks_client + .process_transaction(freeze_tx) + .await + .unwrap(); let transfer_ix = spl_token::instruction::transfer_checked( &spl_token::ID, @@ -383,7 +408,13 @@ async fn transfer_checked_frozen_self() { let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(17))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(17) + ) + ); } #[tokio::test] @@ -452,7 +483,13 @@ async fn transfer_checked_insufficient() { let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(1))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(1) + ) + ); } #[tokio::test] @@ -516,7 +553,13 @@ async fn transfer_checked_insufficient_self() { let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(1))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(1) + ) + ); } #[tokio::test] @@ -538,7 +581,7 @@ async fn transfer_checked_diff_mint() { ) .await .unwrap(); - + let mint2 = mint::initialize( &mut context, mint_authority.pubkey(), @@ -593,7 +636,13 @@ async fn transfer_checked_diff_mint() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(3) + ) + ); } #[tokio::test] @@ -615,7 +664,7 @@ async fn transfer_checked_diff_mint_supplied() { ) .await .unwrap(); - + let mint2 = mint::initialize( &mut context, mint_authority.pubkey(), @@ -670,7 +719,13 @@ async fn transfer_checked_diff_mint_supplied() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(3))); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(3) + ) + ); } #[tokio::test] @@ -816,5 +871,11 @@ async fn transfer_checked_decimals_diff() { let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::Custom(18))); -} \ No newline at end of file + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::Custom(18) + ) + ); +} diff --git a/p-token/tests/ui_amount_to_amount.rs b/p-token/tests/ui_amount_to_amount.rs index a66e698..d208fd2 100644 --- a/p-token/tests/ui_amount_to_amount.rs +++ b/p-token/tests/ui_amount_to_amount.rs @@ -77,8 +77,13 @@ async fn ui_amount_to_amount_empty() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); - + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } #[tokio::test] @@ -112,8 +117,13 @@ async fn ui_amount_to_amount_decimal_point_only() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); - + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } #[tokio::test] @@ -185,7 +195,13 @@ async fn ui_amount_to_amount_decimals_empty_ints_zero() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } #[tokio::test] @@ -295,7 +311,13 @@ async fn ui_amount_to_amount_decimals_double() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } #[tokio::test] @@ -329,7 +351,13 @@ async fn ui_amount_to_amount_decimals_excessive_fractions() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } #[tokio::test] @@ -363,7 +391,13 @@ async fn ui_amount_to_amount_decimals_excessive_ints() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } #[tokio::test] @@ -397,7 +431,13 @@ async fn ui_amount_to_amount_excessive_ints() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } #[tokio::test] @@ -585,7 +625,13 @@ async fn ui_amount_to_amount_minus_only() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } #[tokio::test] @@ -619,7 +665,13 @@ async fn ui_amount_to_amount_decimal_minus_zero() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } #[tokio::test] @@ -653,7 +705,13 @@ async fn ui_amount_to_amount_decimal_minus_only() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } #[tokio::test] @@ -687,7 +745,13 @@ async fn ui_amount_to_amount_invalid_char() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } #[tokio::test] @@ -721,7 +785,13 @@ async fn ui_amount_to_amount_decimal_invalid_char() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } // TODO: Why is 1844674407370955 the limit? @@ -746,7 +816,8 @@ async fn ui_amount_to_amount_max() { .unwrap(); let ui_amount_to_amount_ix = - spl_token::instruction::ui_amount_to_amount(&spl_token::ID, &mint, "1844674407370955").unwrap(); + spl_token::instruction::ui_amount_to_amount(&spl_token::ID, &mint, "1844674407370955") + .unwrap(); let tx = Transaction::new_signed_with_payer( &[ui_amount_to_amount_ix], @@ -785,7 +856,8 @@ async fn ui_amount_to_amount_execessive_magnitude() { .unwrap(); let ui_amount_to_amount_ix = - spl_token::instruction::ui_amount_to_amount(&spl_token::ID, &mint, "1844674407370956").unwrap(); + spl_token::instruction::ui_amount_to_amount(&spl_token::ID, &mint, "1844674407370956") + .unwrap(); let tx = Transaction::new_signed_with_payer( &[ui_amount_to_amount_ix], @@ -795,7 +867,13 @@ async fn ui_amount_to_amount_execessive_magnitude() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); } // TODO: Why is 1844674407370955 the limit? @@ -820,7 +898,8 @@ async fn ui_amount_to_amount_decimal_max() { .unwrap(); let ui_amount_to_amount_ix = - spl_token::instruction::ui_amount_to_amount(&spl_token::ID, &mint, "18446744073709.55").unwrap(); + spl_token::instruction::ui_amount_to_amount(&spl_token::ID, &mint, "18446744073709.55") + .unwrap(); let tx = Transaction::new_signed_with_payer( &[ui_amount_to_amount_ix], @@ -859,7 +938,8 @@ async fn ui_amount_to_amount_decimal_execessive_magnitude() { .unwrap(); let ui_amount_to_amount_ix = - spl_token::instruction::ui_amount_to_amount(&spl_token::ID, &mint, "1844674407370955.1").unwrap(); + spl_token::instruction::ui_amount_to_amount(&spl_token::ID, &mint, "1844674407370955.1") + .unwrap(); let tx = Transaction::new_signed_with_payer( &[ui_amount_to_amount_ix], @@ -898,7 +978,8 @@ async fn ui_amount_to_amount_decimal_execessive_magnitude1() { .unwrap(); let ui_amount_to_amount_ix = - spl_token::instruction::ui_amount_to_amount(&spl_token::ID, &mint, "1844674407370955.2").unwrap(); + spl_token::instruction::ui_amount_to_amount(&spl_token::ID, &mint, "1844674407370955.2") + .unwrap(); let tx = Transaction::new_signed_with_payer( &[ui_amount_to_amount_ix], @@ -908,5 +989,11 @@ async fn ui_amount_to_amount_decimal_execessive_magnitude1() { ); let result = context.banks_client.process_transaction(tx).await; let inner_error = result.err().unwrap().unwrap(); - assert_eq!(inner_error, solana_transaction_error::TransactionError::InstructionError(0, solana_instruction::error::InstructionError::InvalidArgument)); + assert_eq!( + inner_error, + solana_transaction_error::TransactionError::InstructionError( + 0, + solana_instruction::error::InstructionError::InvalidArgument + ) + ); }