diff --git a/Cargo.lock b/Cargo.lock index 48b0c96..e98547a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1559,8 +1559,7 @@ dependencies = [ [[package]] name = "mollusk-svm" version = "0.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fceaf67fe3f95a9478f4f5b0d71e77c073eee7a795a74d6143317a22454c289" +source = "git+https://github.com/buffalojoec/mollusk.git#c01523016195c315870bd9e4bfa3a64a6cffa659" dependencies = [ "bincode", "mollusk-svm-error", @@ -1577,8 +1576,7 @@ dependencies = [ [[package]] name = "mollusk-svm-error" version = "0.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8738bc85a52d123012209a573f17faffa1db440493396ae2e1f64fbb8f3579bf" +source = "git+https://github.com/buffalojoec/mollusk.git#c01523016195c315870bd9e4bfa3a64a6cffa659" dependencies = [ "solana-sdk", "thiserror 1.0.69", @@ -1587,8 +1585,7 @@ dependencies = [ [[package]] name = "mollusk-svm-keys" version = "0.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8a7656d86d743de0a9788ce4c0e9ff63028a42e350131ebe67c476cdde6ac9f" +source = "git+https://github.com/buffalojoec/mollusk.git#c01523016195c315870bd9e4bfa3a64a6cffa659" dependencies = [ "mollusk-svm-error", "solana-sdk", diff --git a/program/Cargo.toml b/program/Cargo.toml index 21b18ad..66123c2 100644 --- a/program/Cargo.toml +++ b/program/Cargo.toml @@ -22,7 +22,7 @@ thiserror = "2.0" [dev-dependencies] lazy_static = "1.5.0" -mollusk-svm = "0.0.13" +mollusk-svm = { version = "0.0.13", git = "https://github.com/buffalojoec/mollusk.git" } proptest = "1.5" serial_test = "3.2.0" solana-sdk = "2.1.0" diff --git a/program/tests/processor.rs b/program/tests/processor.rs index d4aa2a1..e4c75e0 100644 --- a/program/tests/processor.rs +++ b/program/tests/processor.rs @@ -3,7 +3,10 @@ //! Program state processor tests use { - mollusk_svm::{result::ProgramResult as MolluskResult, Mollusk}, + mollusk_svm::{ + result::{Check, ProgramResult as MolluskResult}, + Mollusk, + }, serial_test::serial, solana_sdk::{ account::{create_account_for_test, Account as SolanaAccount, AccountSharedData}, @@ -42,6 +45,7 @@ lazy_static::lazy_static! { fn do_process_instruction( instruction: Instruction, mut accounts: Vec<&mut SolanaAccount>, + checks: &[Check], ) -> ProgramResult { let mut instruction_accounts = Vec::new(); @@ -61,7 +65,8 @@ fn do_process_instruction( }); let mollusk = Mollusk::new(&spl_token::ID, "spl_token"); - let result = mollusk.process_and_validate_instruction(&instruction, &instruction_accounts, &[]); + let result = + mollusk.process_and_validate_instruction(&instruction, &instruction_accounts, checks); // Update accounts after the instruction is processed. for (original, (_, updated)) in accounts.iter_mut().zip(result.resulting_accounts.iter()) { @@ -81,6 +86,7 @@ fn do_process_instruction( fn do_process_instruction_dups( instruction: Instruction, account_infos: Vec, + checks: &[Check], ) -> ProgramResult { let mut cached_accounts = HashMap::new(); let mut dedup_accounts = Vec::new(); @@ -101,7 +107,7 @@ fn do_process_instruction_dups( }); let mollusk = Mollusk::new(&spl_token::ID, "spl_token"); - let result = mollusk.process_and_validate_instruction(&instruction, &dedup_accounts, &[]); + let result = mollusk.process_and_validate_instruction(&instruction, &dedup_accounts, checks); // Update accounts after the instruction is processed. result @@ -167,7 +173,8 @@ fn test_initialize_mint() { Err(TokenError::NotRentExempt.into()), do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), - vec![&mut mint_account, &mut rent_sysvar] + vec![&mut mint_account, &mut rent_sysvar], + &[Check::err(TokenError::NotRentExempt.into())], ) ); @@ -177,6 +184,7 @@ fn test_initialize_mint() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -185,7 +193,8 @@ fn test_initialize_mint() { Err(TokenError::AlreadyInUse.into()), do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2,).unwrap(), - vec![&mut mint_account, &mut rent_sysvar] + vec![&mut mint_account, &mut rent_sysvar], + &[Check::err(TokenError::AlreadyInUse.into())], ) ); @@ -193,6 +202,17 @@ fn test_initialize_mint() { do_process_instruction( initialize_mint(&program_id, &mint2_key, &owner_key, Some(&owner_key), 2).unwrap(), vec![&mut mint2_account, &mut rent_sysvar], + &[ + Check::success(), + // freeze authority is set + Check::account(&mint2_key) + .data_slice(46, &[1, 0, 0, 0]) + .build(), + // freeze authority matches owner + Check::account(&mint2_key) + .data_slice(50, owner_key.as_ref()) + .build(), + ], ) .unwrap(); let mint = Mint::unpack_unchecked(&mint2_account.data).unwrap(); @@ -214,7 +234,8 @@ fn test_initialize_mint2() { Err(TokenError::NotRentExempt.into()), do_process_instruction( initialize_mint2(&program_id, &mint_key, &owner_key, None, 2).unwrap(), - vec![&mut mint_account] + vec![&mut mint_account], + &[Check::err(TokenError::NotRentExempt.into())], ) ); @@ -224,6 +245,7 @@ fn test_initialize_mint2() { do_process_instruction( initialize_mint2(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -232,7 +254,8 @@ fn test_initialize_mint2() { Err(TokenError::AlreadyInUse.into()), do_process_instruction( initialize_mint2(&program_id, &mint_key, &owner_key, None, 2,).unwrap(), - vec![&mut mint_account] + vec![&mut mint_account], + &[Check::err(TokenError::AlreadyInUse.into())], ) ); @@ -240,6 +263,17 @@ fn test_initialize_mint2() { do_process_instruction( initialize_mint2(&program_id, &mint2_key, &owner_key, Some(&owner_key), 2).unwrap(), vec![&mut mint2_account], + &[ + Check::success(), + // freeze authority is set + Check::account(&mint2_key) + .data_slice(46, &[1, 0, 0, 0]) + .build(), + // freeze authority matches owner + Check::account(&mint2_key) + .data_slice(50, owner_key.as_ref()) + .build(), + ], ) .unwrap(); let mint = Mint::unpack_unchecked(&mint2_account.data).unwrap(); @@ -269,6 +303,7 @@ fn test_initialize_mint_account() { &mut owner_account, &mut rent_sysvar ], + &[Check::err(TokenError::NotRentExempt.into())], ) ); @@ -285,6 +320,7 @@ fn test_initialize_mint_account() { &mut owner_account, &mut rent_sysvar ], + &[Check::err(TokenError::InvalidMint.into())], ) ); @@ -292,6 +328,7 @@ fn test_initialize_mint_account() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -308,6 +345,7 @@ fn test_initialize_mint_account() { &mut owner_account, &mut rent_sysvar ], + &[Check::err(ProgramError::IncorrectProgramId)], ) ); mint_account.owner = program_id; @@ -321,6 +359,7 @@ fn test_initialize_mint_account() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -335,6 +374,7 @@ fn test_initialize_mint_account() { &mut owner_account, &mut rent_sysvar ], + &[Check::err(TokenError::AlreadyInUse.into())], ) ); } @@ -392,6 +432,7 @@ fn test_transfer_dups() { do_process_instruction_dups( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![mint_info.clone(), rent_info.clone()], + &[Check::success()], ) .unwrap(); @@ -404,6 +445,7 @@ fn test_transfer_dups() { account1_info.clone(), rent_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -416,6 +458,7 @@ fn test_transfer_dups() { owner_info.clone(), rent_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -423,6 +466,7 @@ fn test_transfer_dups() { do_process_instruction_dups( mint_to(&program_id, &mint_key, &account1_key, &owner_key, &[], 1000).unwrap(), vec![mint_info.clone(), account1_info.clone(), owner_info.clone()], + &[Check::success()], ) .unwrap(); @@ -442,6 +486,7 @@ fn test_transfer_dups() { account2_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -464,6 +509,7 @@ fn test_transfer_dups() { account2_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -490,6 +536,7 @@ fn test_transfer_dups() { account2_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -512,6 +559,7 @@ fn test_transfer_dups() { account2_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -524,11 +572,13 @@ fn test_transfer_dups() { account2_info.clone(), rent_info.clone(), ], + &[Check::success()], ) .unwrap(); do_process_instruction_dups( mint_to(&program_id, &mint_key, &account3_key, &owner_key, &[], 1000).unwrap(), vec![mint_info.clone(), account3_info.clone(), owner_info.clone()], + &[Check::success()], ) .unwrap(); @@ -549,6 +599,7 @@ fn test_transfer_dups() { account2_info.clone(), account2_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -571,6 +622,7 @@ fn test_transfer_dups() { account2_info.clone(), account2_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -582,6 +634,7 @@ fn test_transfer_dups() { rent_info.clone(), account4_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -593,12 +646,14 @@ fn test_transfer_dups() { multisig_info.clone(), rent_info.clone(), ], + &[Check::success()], ) .unwrap(); do_process_instruction_dups( mint_to(&program_id, &mint_key, &account4_key, &owner_key, &[], 1000).unwrap(), vec![mint_info.clone(), account4_info.clone(), owner_info.clone()], + &[Check::success()], ) .unwrap(); @@ -619,6 +674,7 @@ fn test_transfer_dups() { multisig_info.clone(), account4_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -642,6 +698,7 @@ fn test_transfer_dups() { multisig_info.clone(), account4_info.clone(), ], + &[Check::success()], ) .unwrap(); } @@ -689,6 +746,7 @@ fn test_transfer() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -701,6 +759,7 @@ fn test_transfer() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -713,6 +772,7 @@ fn test_transfer() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -725,6 +785,7 @@ fn test_transfer() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -737,6 +798,7 @@ fn test_transfer() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); let mut account = Account::unpack_unchecked(&mismatch_account.data).unwrap(); @@ -747,6 +809,7 @@ fn test_transfer() { do_process_instruction( mint_to(&program_id, &mint_key, &account_key, &owner_key, &[], 1000).unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[Check::success()], ) .unwrap(); @@ -770,6 +833,7 @@ fn test_transfer() { &mut account2_account, &mut owner_account, ], + &[Check::err(ProgramError::MissingRequiredSignature)], ) ); @@ -791,6 +855,7 @@ fn test_transfer() { &mut mismatch_account, &mut owner_account, ], + &[Check::err(TokenError::MintMismatch.into())], ) ); @@ -812,6 +877,7 @@ fn test_transfer() { &mut account2_account, &mut owner2_account, ], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -827,6 +893,7 @@ fn test_transfer() { &mut account2_account, &mut owner2_account, ], + &[Check::err(ProgramError::IncorrectProgramId)], ) ); account_account.owner = program_id; @@ -843,6 +910,7 @@ fn test_transfer() { &mut account2_account, &mut owner2_account, ], + &[Check::err(ProgramError::IncorrectProgramId)], ) ); account2_account.owner = program_id; @@ -863,6 +931,7 @@ fn test_transfer() { &mut account2_account, &mut owner_account, ], + &[Check::success()], ) .unwrap(); @@ -876,6 +945,7 @@ fn test_transfer() { &mut account2_account, &mut owner_account, ], + &[Check::err(TokenError::InsufficientFunds.into())], ) ); @@ -895,6 +965,7 @@ fn test_transfer() { &mut account_account, &mut owner_account, ], + &[Check::success()], ) .unwrap(); @@ -919,6 +990,7 @@ fn test_transfer() { &mut account_account, &mut owner_account, ], + &[Check::err(TokenError::MintDecimalsMismatch.into())], ) ); @@ -943,6 +1015,7 @@ fn test_transfer() { &mut account_account, &mut owner_account, ], + &[Check::err(TokenError::MintMismatch.into())], ) ); // transfer rest with explicit decimals @@ -964,6 +1037,7 @@ fn test_transfer() { &mut account_account, &mut owner_account, ], + &[Check::success()], ) .unwrap(); @@ -977,6 +1051,7 @@ fn test_transfer() { &mut account_account, &mut owner_account, ], + &[Check::err(TokenError::InsufficientFunds.into())], ) ); @@ -996,6 +1071,7 @@ fn test_transfer() { &mut delegate_account, &mut owner_account, ], + &[Check::success()], ) .unwrap(); @@ -1017,6 +1093,7 @@ fn test_transfer() { &mut account2_account, &mut owner2_account, ], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -1038,6 +1115,7 @@ fn test_transfer() { &mut account2_account, &mut delegate_account, ], + &[Check::err(TokenError::InsufficientFunds.into())], ) ); @@ -1057,6 +1135,7 @@ fn test_transfer() { &mut account2_account, &mut delegate_account, ], + &[Check::success()], ) .unwrap(); @@ -1078,6 +1157,7 @@ fn test_transfer() { &mut account2_account, &mut delegate_account, ], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -1097,6 +1177,7 @@ fn test_transfer() { &mut account2_account, &mut owner_account, ], + &[Check::success()], ) .unwrap(); @@ -1116,6 +1197,7 @@ fn test_transfer() { &mut delegate_account, &mut owner_account, ], + &[Check::success()], ) .unwrap(); @@ -1137,6 +1219,7 @@ fn test_transfer() { &mut account2_account, &mut delegate_account, ], + &[Check::err(TokenError::InsufficientFunds.into())], ) ); } @@ -1177,6 +1260,7 @@ fn test_self_transfer() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -1189,6 +1273,7 @@ fn test_self_transfer() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -1201,6 +1286,7 @@ fn test_self_transfer() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -1213,6 +1299,7 @@ fn test_self_transfer() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -1220,6 +1307,7 @@ fn test_self_transfer() { do_process_instruction( mint_to(&program_id, &mint_key, &account_key, &owner_key, &[], 1000).unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[Check::success()], ) .unwrap(); @@ -1249,6 +1337,12 @@ fn test_self_transfer() { account_info.clone(), owner_info.clone(), ], + &[ + Check::success(), + Check::account(account_info.key) + .data_slice(64, &1000u64.to_le_bytes()) + .build() + ], ) ); // no balance change... @@ -1277,6 +1371,12 @@ fn test_self_transfer() { account_info.clone(), owner_info.clone(), ], + &[ + Check::success(), + Check::account(account_info.key) + .data_slice(64, &1000u64.to_le_bytes()) + .build() + ], ) ); // no balance change... @@ -1305,6 +1405,7 @@ fn test_self_transfer() { account_info.clone(), owner_no_sign_info.clone(), ], + &[Check::err(ProgramError::MissingRequiredSignature)], ) ); @@ -1331,6 +1432,7 @@ fn test_self_transfer() { account_info.clone(), owner_no_sign_info, ], + &[Check::err(ProgramError::MissingRequiredSignature)], ) ); @@ -1353,6 +1455,7 @@ fn test_self_transfer() { account_info.clone(), owner2_info.clone(), ], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -1378,6 +1481,7 @@ fn test_self_transfer() { account_info.clone(), owner2_info.clone(), ], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -1400,6 +1504,7 @@ fn test_self_transfer() { account_info.clone(), owner_info.clone(), ], + &[Check::err(TokenError::InsufficientFunds.into())], ) ); @@ -1425,6 +1530,7 @@ fn test_self_transfer() { account_info.clone(), owner_info.clone(), ], + &[Check::err(TokenError::InsufficientFunds.into())], ) ); @@ -1450,6 +1556,7 @@ fn test_self_transfer() { account_info.clone(), owner_info.clone(), ], + &[Check::err(TokenError::MintDecimalsMismatch.into())], ) ); @@ -1475,6 +1582,7 @@ fn test_self_transfer() { account_info.clone(), owner_info.clone(), ], + &[Check::err(TokenError::MintMismatch.into())], ) ); @@ -1495,6 +1603,7 @@ fn test_self_transfer() { delegate_info.clone(), owner_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -1517,6 +1626,15 @@ fn test_self_transfer() { account_info.clone(), delegate_info.clone(), ], + &[ + Check::success(), + Check::account(account_info.key) + .data_slice(64, &1000u64.to_le_bytes()) + .build(), + Check::account(&account_key) + .data_slice(121, &100u64.to_le_bytes()) + .build(), + ], ) ); // no balance change... @@ -1546,6 +1664,15 @@ fn test_self_transfer() { account_info.clone(), delegate_info.clone(), ], + &[ + Check::success(), + Check::account(account_info.key) + .data_slice(64, &1000u64.to_le_bytes()) + .build(), + Check::account(&account_key) + .data_slice(121, &100u64.to_le_bytes()) + .build(), + ], ) ); // no balance change... @@ -1572,6 +1699,7 @@ fn test_self_transfer() { account_info.clone(), delegate_info.clone(), ], + &[Check::err(TokenError::InsufficientFunds.into())], ) ); @@ -1597,6 +1725,7 @@ fn test_self_transfer() { account_info.clone(), delegate_info.clone(), ], + &[Check::err(TokenError::InsufficientFunds.into())], ) ); @@ -1619,6 +1748,12 @@ fn test_self_transfer() { account_info.clone(), owner_info.clone(), ], + &[ + Check::success(), + Check::account(account_info.key) + .data_slice(64, &1000u64.to_le_bytes()) + .build(), + ], ) ); // no balance change... @@ -1647,6 +1782,12 @@ fn test_self_transfer() { account_info.clone(), owner_info.clone(), ], + &[ + Check::success(), + Check::account(account_info.key) + .data_slice(64, &1000u64.to_le_bytes()) + .build(), + ], ) ); // no balance change... @@ -1672,22 +1813,26 @@ fn test_mintable_token_with_zero_supply() { // create mint-able token with zero supply let decimals = 2; + let expected_mint = Mint { + mint_authority: COption::Some(owner_key), + supply: 0, + decimals, + is_initialized: true, + freeze_authority: COption::None, + }; + let mut mint_data = [0u8; Mint::LEN]; + expected_mint.pack_into_slice(&mut mint_data); do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, decimals).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[ + Check::success(), + Check::account(&mint_key).data(&mint_data).build(), + ], ) .unwrap(); let mint = Mint::unpack_unchecked(&mint_account.data).unwrap(); - assert_eq!( - mint, - Mint { - mint_authority: COption::Some(owner_key), - supply: 0, - decimals, - is_initialized: true, - freeze_authority: COption::None, - } - ); + assert_eq!(mint, expected_mint); // create account do_process_instruction( @@ -1698,6 +1843,7 @@ fn test_mintable_token_with_zero_supply() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -1705,6 +1851,12 @@ fn test_mintable_token_with_zero_supply() { do_process_instruction( mint_to(&program_id, &mint_key, &account_key, &owner_key, &[], 42).unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[ + Check::success(), + Check::account(&account_key) + .data_slice(64, &42u64.to_le_bytes()) + .build(), + ], ) .unwrap(); let _ = Mint::unpack(&mint_account.data).unwrap(); @@ -1726,6 +1878,12 @@ fn test_mintable_token_with_zero_supply() { ) .unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[ + Check::err(TokenError::MintDecimalsMismatch.into()), + Check::account(&account_key) + .data_slice(64, &42u64.to_le_bytes()) + .build(), + ], ) ); @@ -1746,6 +1904,12 @@ fn test_mintable_token_with_zero_supply() { ) .unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[ + Check::success(), + Check::account(&account_key) + .data_slice(64, &84u64.to_le_bytes()) + .build(), + ], ) .unwrap(); let _ = Mint::unpack(&mint_account.data).unwrap(); @@ -1799,6 +1963,7 @@ fn test_approve_dups() { do_process_instruction_dups( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![mint_info.clone(), rent_info.clone()], + &[Check::success()], ) .unwrap(); @@ -1811,6 +1976,7 @@ fn test_approve_dups() { account1_info.clone(), rent_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -1823,6 +1989,7 @@ fn test_approve_dups() { owner_info.clone(), rent_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -1830,6 +1997,7 @@ fn test_approve_dups() { do_process_instruction_dups( mint_to(&program_id, &mint_key, &account1_key, &owner_key, &[], 1000).unwrap(), vec![mint_info.clone(), account1_info.clone(), owner_info.clone()], + &[Check::success()], ) .unwrap(); @@ -1849,6 +2017,7 @@ fn test_approve_dups() { account2_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -1871,6 +2040,7 @@ fn test_approve_dups() { account2_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -1878,6 +2048,7 @@ fn test_approve_dups() { do_process_instruction_dups( revoke(&program_id, &account1_key, &account1_key, &[]).unwrap(), vec![account1_info.clone(), account1_info.clone()], + &[Check::success()], ) .unwrap(); @@ -1889,6 +2060,7 @@ fn test_approve_dups() { rent_info.clone(), account3_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -1900,12 +2072,14 @@ fn test_approve_dups() { multisig_info.clone(), rent_info.clone(), ], + &[Check::success()], ) .unwrap(); do_process_instruction_dups( mint_to(&program_id, &mint_key, &account3_key, &owner_key, &[], 1000).unwrap(), vec![mint_info.clone(), account3_info.clone(), owner_info.clone()], + &[Check::success()], ) .unwrap(); @@ -1926,6 +2100,7 @@ fn test_approve_dups() { multisig_info.clone(), account3_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -1949,6 +2124,7 @@ fn test_approve_dups() { multisig_info.clone(), account3_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -1960,6 +2136,7 @@ fn test_approve_dups() { multisig_info.clone(), account3_info.clone(), ], + &[Check::success()], ) .unwrap(); } @@ -1994,6 +2171,7 @@ fn test_approve() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -2006,6 +2184,7 @@ fn test_approve() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -2018,6 +2197,7 @@ fn test_approve() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -2025,6 +2205,7 @@ fn test_approve() { do_process_instruction( mint_to(&program_id, &mint_key, &account_key, &owner_key, &[], 1000).unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[Check::success()], ) .unwrap(); @@ -2048,6 +2229,7 @@ fn test_approve() { &mut delegate_account, &mut owner_account, ], + &[Check::err(ProgramError::MissingRequiredSignature)], ) ); @@ -2069,6 +2251,7 @@ fn test_approve() { &mut delegate_account, &mut owner2_account, ], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -2088,6 +2271,7 @@ fn test_approve() { &mut delegate_account, &mut owner_account, ], + &[Check::success()], ) .unwrap(); @@ -2112,6 +2296,7 @@ fn test_approve() { &mut delegate_account, &mut owner_account, ], + &[Check::err(TokenError::MintDecimalsMismatch.into())], ) ); @@ -2136,6 +2321,7 @@ fn test_approve() { &mut delegate_account, &mut owner_account, ], + &[Check::err(TokenError::MintMismatch.into())], ) ); @@ -2158,6 +2344,7 @@ fn test_approve() { &mut delegate_account, &mut owner_account, ], + &[Check::success()], ) .unwrap(); @@ -2165,6 +2352,7 @@ fn test_approve() { do_process_instruction( revoke(&program_id, &account_key, &owner_key, &[]).unwrap(), vec![&mut account_account, &mut owner_account], + &[Check::success()], ) .unwrap(); } @@ -2192,6 +2380,7 @@ fn test_set_authority_dups() { do_process_instruction_dups( initialize_mint(&program_id, &mint_key, &mint_key, Some(&mint_key), 2).unwrap(), vec![mint_info.clone(), rent_info.clone()], + &[Check::success()], ) .unwrap(); @@ -2204,6 +2393,7 @@ fn test_set_authority_dups() { account1_info.clone(), rent_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -2219,6 +2409,7 @@ fn test_set_authority_dups() { ) .unwrap(), vec![mint_info.clone(), mint_info.clone()], + &[Check::success()], ) .unwrap(); @@ -2234,6 +2425,7 @@ fn test_set_authority_dups() { ) .unwrap(), vec![mint_info.clone(), mint_info.clone()], + &[Check::success()], ) .unwrap(); @@ -2249,6 +2441,7 @@ fn test_set_authority_dups() { ) .unwrap(), vec![account1_info.clone(), account1_info.clone()], + &[Check::success()], ) .unwrap(); @@ -2268,6 +2461,7 @@ fn test_set_authority_dups() { ) .unwrap(), vec![account1_info.clone(), account1_info.clone()], + &[Check::success()], ) .unwrap(); } @@ -2305,6 +2499,7 @@ fn test_set_authority() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -2312,6 +2507,7 @@ fn test_set_authority() { do_process_instruction( initialize_mint(&program_id, &mint2_key, &owner_key, Some(&owner_key), 2).unwrap(), vec![&mut mint2_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -2329,6 +2525,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut account_account, &mut owner_account], + &[Check::err(ProgramError::UninitializedAccount)], ) ); @@ -2341,6 +2538,7 @@ fn test_set_authority() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -2353,6 +2551,7 @@ fn test_set_authority() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -2370,6 +2569,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut account_account, &mut owner2_account], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -2386,7 +2586,11 @@ fn test_set_authority() { instruction.accounts[1].is_signer = false; assert_eq!( Err(ProgramError::MissingRequiredSignature), - do_process_instruction(instruction, vec![&mut account_account, &mut owner_account,],) + do_process_instruction( + instruction, + vec![&mut account_account, &mut owner_account,], + &[Check::err(ProgramError::MissingRequiredSignature)] + ), ); // wrong authority type @@ -2403,6 +2607,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut account_account, &mut owner_account], + &[Check::err(TokenError::AuthorityTypeNotSupported.into())], ) ); @@ -2420,6 +2625,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut account_account, &mut owner_account], + &[Check::err(TokenError::InvalidInstruction.into())], ) ); @@ -2439,6 +2645,21 @@ fn test_set_authority() { &mut owner2_account, &mut owner_account, ], + &[ + Check::success(), + // delegate set + Check::account(&account_key) + .data_slice(72, &[1, 0, 0, 0]) + .build(), + // delegate + Check::account(&account_key) + .data_slice(76, owner2_key.as_ref()) + .build(), + // delegated amount + Check::account(&account_key) + .data_slice(121, &u64::MAX.to_le_bytes()) + .build(), + ], ) .unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); @@ -2457,6 +2678,17 @@ fn test_set_authority() { ) .unwrap(), vec![&mut account_account, &mut owner_account], + &[ + Check::success(), + // delegate not set + Check::account(&account_key) + .data_slice(72, &[0, 0, 0, 0]) + .build(), + // delegated amount + Check::account(&account_key) + .data_slice(121, &0u64.to_le_bytes()) + .build(), + ], ) .unwrap(); @@ -2477,6 +2709,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut account_account, &mut owner3_account], + &[Check::success()], ) .unwrap(); @@ -2492,6 +2725,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut account_account, &mut owner2_account], + &[Check::success()], ) .unwrap(); @@ -2507,6 +2741,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut account_account, &mut owner2_account], + &[Check::success()], ) .unwrap(); @@ -2524,6 +2759,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut mint_account, &mut owner2_account], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -2540,7 +2776,11 @@ fn test_set_authority() { instruction.accounts[1].is_signer = false; assert_eq!( Err(ProgramError::MissingRequiredSignature), - do_process_instruction(instruction, vec![&mut mint_account, &mut owner_account],) + do_process_instruction( + instruction, + vec![&mut mint_account, &mut owner_account], + &[Check::err(ProgramError::MissingRequiredSignature)] + ), ); // cannot freeze @@ -2557,6 +2797,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut mint_account, &mut owner_account], + &[Check::err(TokenError::MintCannotFreeze.into())], ) ); @@ -2572,6 +2813,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut mint_account, &mut owner_account], + &[Check::success()], ) .unwrap(); @@ -2587,6 +2829,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut mint_account, &mut owner2_account], + &[Check::success()], ) .unwrap(); @@ -2604,6 +2847,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut mint_account, &mut owner_account], + &[Check::err(TokenError::FixedSupply.into())], ) ); @@ -2619,6 +2863,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut mint2_account, &mut owner_account], + &[Check::success()], ) .unwrap(); @@ -2634,6 +2879,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut mint2_account, &mut owner2_account], + &[Check::success()], ) .unwrap(); @@ -2650,6 +2896,7 @@ fn test_set_authority() { ) .unwrap(), vec![&mut mint2_account, &mut owner2_account], + &[Check::err(TokenError::MintCannotFreeze.into())], ) ); } @@ -2679,6 +2926,7 @@ fn test_mint_to_dups() { do_process_instruction_dups( initialize_mint(&program_id, &mint_key, &mint_key, None, 2).unwrap(), vec![mint_info.clone(), rent_info.clone()], + &[Check::success()], ) .unwrap(); @@ -2691,6 +2939,7 @@ fn test_mint_to_dups() { owner_info.clone(), rent_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -2698,6 +2947,7 @@ fn test_mint_to_dups() { do_process_instruction_dups( mint_to(&program_id, &mint_key, &account1_key, &mint_key, &[], 42).unwrap(), vec![mint_info.clone(), account1_info.clone(), mint_info.clone()], + &[Check::success()], ) .unwrap(); @@ -2705,6 +2955,7 @@ fn test_mint_to_dups() { do_process_instruction_dups( mint_to_checked(&program_id, &mint_key, &account1_key, &mint_key, &[], 42, 2).unwrap(), vec![mint_info.clone(), account1_info.clone(), mint_info.clone()], + &[Check::success()], ) .unwrap(); @@ -2727,6 +2978,7 @@ fn test_mint_to_dups() { account1_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -2746,6 +2998,7 @@ fn test_mint_to_dups() { account1_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); } @@ -2797,6 +3050,7 @@ fn test_mint_to() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -2809,6 +3063,7 @@ fn test_mint_to() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -2821,6 +3076,7 @@ fn test_mint_to() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -2833,6 +3089,7 @@ fn test_mint_to() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -2845,6 +3102,7 @@ fn test_mint_to() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); let mut account = Account::unpack_unchecked(&mismatch_account.data).unwrap(); @@ -2855,6 +3113,15 @@ fn test_mint_to() { do_process_instruction( mint_to(&program_id, &mint_key, &account_key, &owner_key, &[], 42).unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[ + Check::success(), + Check::account(&mint_key) + .data_slice(36, &42u64.to_le_bytes()) + .build(), + Check::account(&account_key) + .data_slice(64, &42u64.to_le_bytes()) + .build(), + ], ) .unwrap(); @@ -2867,6 +3134,15 @@ fn test_mint_to() { do_process_instruction( mint_to(&program_id, &mint_key, &account2_key, &owner_key, &[], 42).unwrap(), vec![&mut mint_account, &mut account2_account, &mut owner_account], + &[ + Check::success(), + Check::account(&mint_key) + .data_slice(36, &84u64.to_le_bytes()) + .build(), + Check::account(&account2_key) + .data_slice(64, &42u64.to_le_bytes()) + .build(), + ], ) .unwrap(); @@ -2884,6 +3160,7 @@ fn test_mint_to() { do_process_instruction( instruction, vec![&mut mint_account, &mut account2_account, &mut owner_account], + &[Check::err(ProgramError::MissingRequiredSignature)], ) ); @@ -2893,6 +3170,7 @@ fn test_mint_to() { do_process_instruction( mint_to(&program_id, &mint_key, &mismatch_key, &owner_key, &[], 42).unwrap(), vec![&mut mint_account, &mut mismatch_account, &mut owner_account], + &[Check::err(TokenError::MintMismatch.into())], ) ); @@ -2906,6 +3184,7 @@ fn test_mint_to() { &mut account2_account, &mut owner2_account, ], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -2917,6 +3196,7 @@ fn test_mint_to() { do_process_instruction( mint_to(&program_id, &mint_key, &account_key, &owner_key, &[], 0).unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[Check::err(ProgramError::IncorrectProgramId)], ) ); mint_account.owner = program_id; @@ -2929,6 +3209,7 @@ fn test_mint_to() { do_process_instruction( mint_to(&program_id, &mint_key, &account_key, &owner_key, &[], 0).unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[Check::err(ProgramError::IncorrectProgramId)], ) ); account_account.owner = program_id; @@ -2951,6 +3232,7 @@ fn test_mint_to() { &mut uninitialized_account, &mut owner_account, ], + &[Check::err(ProgramError::UninitializedAccount)], ) ); @@ -2966,6 +3248,7 @@ fn test_mint_to() { ) .unwrap(), vec![&mut mint_account, &mut owner_account], + &[Check::success()], ) .unwrap(); assert_eq!( @@ -2973,6 +3256,7 @@ fn test_mint_to() { do_process_instruction( mint_to(&program_id, &mint_key, &account2_key, &owner_key, &[], 42).unwrap(), vec![&mut mint_account, &mut account2_account, &mut owner_account], + &[Check::err(TokenError::FixedSupply.into())], ) ); } @@ -3002,6 +3286,7 @@ fn test_burn_dups() { do_process_instruction_dups( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![mint_info.clone(), rent_info.clone()], + &[Check::success()], ) .unwrap(); @@ -3014,6 +3299,7 @@ fn test_burn_dups() { account1_info.clone(), rent_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -3021,6 +3307,7 @@ fn test_burn_dups() { do_process_instruction_dups( mint_to(&program_id, &mint_key, &account1_key, &owner_key, &[], 1000).unwrap(), vec![mint_info.clone(), account1_info.clone(), owner_info.clone()], + &[Check::success()], ) .unwrap(); @@ -3040,6 +3327,7 @@ fn test_burn_dups() { mint_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -3060,6 +3348,7 @@ fn test_burn_dups() { mint_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -3067,6 +3356,7 @@ fn test_burn_dups() { do_process_instruction_dups( mint_to(&program_id, &mint_key, &account1_key, &owner_key, &[], 1000).unwrap(), vec![mint_info.clone(), account1_info.clone(), owner_info.clone()], + &[Check::success()], ) .unwrap(); let mut account = Account::unpack_unchecked(&account1_info.data.borrow()).unwrap(); @@ -3075,6 +3365,7 @@ fn test_burn_dups() { do_process_instruction_dups( burn(&program_id, &account1_key, &mint_key, &mint_key, &[], 500).unwrap(), vec![account1_info.clone(), mint_info.clone(), mint_info.clone()], + &[Check::success()], ) .unwrap(); @@ -3091,6 +3382,7 @@ fn test_burn_dups() { ) .unwrap(), vec![account1_info.clone(), mint_info.clone(), mint_info.clone()], + &[Check::success()], ) .unwrap(); @@ -3098,6 +3390,7 @@ fn test_burn_dups() { do_process_instruction_dups( mint_to(&program_id, &mint_key, &account1_key, &owner_key, &[], 1000).unwrap(), vec![mint_info.clone(), account1_info.clone(), owner_info.clone()], + &[Check::success()], ) .unwrap(); let mut account = Account::unpack_unchecked(&account1_info.data.borrow()).unwrap(); @@ -3120,6 +3413,7 @@ fn test_burn_dups() { mint_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -3140,6 +3434,7 @@ fn test_burn_dups() { mint_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -3147,6 +3442,7 @@ fn test_burn_dups() { do_process_instruction_dups( mint_to(&program_id, &mint_key, &account1_key, &owner_key, &[], 1000).unwrap(), vec![mint_info.clone(), account1_info.clone(), owner_info.clone()], + &[Check::success()], ) .unwrap(); let mut account = Account::unpack_unchecked(&account1_info.data.borrow()).unwrap(); @@ -3157,6 +3453,7 @@ fn test_burn_dups() { do_process_instruction_dups( burn(&program_id, &account1_key, &mint_key, &mint_key, &[], 500).unwrap(), vec![account1_info.clone(), mint_info.clone(), mint_info.clone()], + &[Check::success()], ) .unwrap(); @@ -3173,6 +3470,7 @@ fn test_burn_dups() { ) .unwrap(), vec![account1_info.clone(), mint_info.clone(), mint_info.clone()], + &[Check::success()], ) .unwrap(); } @@ -3220,6 +3518,7 @@ fn test_burn() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -3232,6 +3531,7 @@ fn test_burn() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -3244,6 +3544,7 @@ fn test_burn() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -3256,6 +3557,7 @@ fn test_burn() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -3268,6 +3570,7 @@ fn test_burn() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -3275,6 +3578,7 @@ fn test_burn() { do_process_instruction( mint_to(&program_id, &mint_key, &account_key, &owner_key, &[], 1000).unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[Check::success()], ) .unwrap(); @@ -3282,6 +3586,7 @@ fn test_burn() { do_process_instruction( mint_to(&program_id, &mint_key, &mismatch_key, &owner_key, &[], 1000).unwrap(), vec![&mut mint_account, &mut mismatch_account, &mut owner_account], + &[Check::success()], ) .unwrap(); let mut account = Account::unpack_unchecked(&mismatch_account.data).unwrap(); @@ -3301,6 +3606,7 @@ fn test_burn() { &mut mint_account, &mut delegate_account ], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -3310,6 +3616,7 @@ fn test_burn() { do_process_instruction( burn(&program_id, &account_key, &mint_key, &owner2_key, &[], 42).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner2_account], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -3321,6 +3628,7 @@ fn test_burn() { do_process_instruction( burn(&program_id, &account_key, &mint_key, &owner_key, &[], 0).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner_account], + &[Check::err(ProgramError::IncorrectProgramId)], ) ); account_account.owner = program_id; @@ -3333,6 +3641,7 @@ fn test_burn() { do_process_instruction( burn(&program_id, &account_key, &mint_key, &owner_key, &[], 0).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner_account], + &[Check::err(ProgramError::IncorrectProgramId)], ) ); mint_account.owner = program_id; @@ -3343,6 +3652,7 @@ fn test_burn() { do_process_instruction( burn(&program_id, &mismatch_key, &mint_key, &owner_key, &[], 42).unwrap(), vec![&mut mismatch_account, &mut mint_account, &mut owner_account], + &[Check::err(TokenError::MintMismatch.into())], ) ); @@ -3350,6 +3660,7 @@ fn test_burn() { do_process_instruction( burn(&program_id, &account_key, &mint_key, &owner_key, &[], 21).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner_account], + &[Check::success()], ) .unwrap(); @@ -3359,6 +3670,7 @@ fn test_burn() { do_process_instruction( burn_checked(&program_id, &account_key, &mint_key, &owner_key, &[], 21, 3).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner_account], + &[Check::err(TokenError::MintDecimalsMismatch.into())], ) ); @@ -3366,6 +3678,15 @@ fn test_burn() { do_process_instruction( burn_checked(&program_id, &account_key, &mint_key, &owner_key, &[], 21, 2).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner_account], + &[ + Check::success(), + Check::account(&mint_key) + .data_slice(36, &(2000u64 - 42).to_le_bytes()) + .build(), + Check::account(&account_key) + .data_slice(64, &(1000u64 - 42).to_le_bytes()) + .build(), + ], ) .unwrap(); @@ -3388,6 +3709,7 @@ fn test_burn() { ) .unwrap(), vec![&mut account_account, &mut mint_account, &mut owner_account], + &[Check::err(TokenError::InsufficientFunds.into())], ) ); @@ -3407,6 +3729,7 @@ fn test_burn() { &mut delegate_account, &mut owner_account, ], + &[Check::success()], ) .unwrap(); @@ -3424,6 +3747,7 @@ fn test_burn() { ) .unwrap(), vec![&mut account_account, &mut mint_account, &mut owner2_account], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -3437,6 +3761,7 @@ fn test_burn() { &mut mint_account, &mut delegate_account ], + &[Check::err(TokenError::InsufficientFunds.into())], ) ); @@ -3448,6 +3773,15 @@ fn test_burn() { &mut mint_account, &mut delegate_account, ], + &[ + Check::success(), + Check::account(&mint_key) + .data_slice(36, &(2000u64 - 42 - 84).to_le_bytes()) + .build(), + Check::account(&account_key) + .data_slice(64, &(1000u64 - 42 - 84).to_le_bytes()) + .build(), + ], ) .unwrap(); @@ -3467,6 +3801,7 @@ fn test_burn() { &mut mint_account, &mut delegate_account ], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); } @@ -3505,6 +3840,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { do_process_instruction( initialize_mint2(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -3512,6 +3848,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { do_process_instruction( initialize_account3(&program_id, &account_key, &mint_key, &owner_key).unwrap(), vec![&mut account_account, &mut mint_account], + &[Check::success()], ) .unwrap(); @@ -3525,6 +3862,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { ) .unwrap(), vec![&mut incinerator_account, &mut mint_account], + &[Check::success()], ) .unwrap(); do_process_instruction( @@ -3536,6 +3874,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { ) .unwrap(), vec![&mut system_account, &mut mint_account], + &[Check::success()], ) .unwrap(); @@ -3543,6 +3882,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { do_process_instruction( mint_to(&program_id, &mint_key, &account_key, &owner_key, &[], 1000).unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[Check::success()], ) .unwrap(); @@ -3562,6 +3902,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { &mut incinerator_account, &mut owner_account, ], + &[Check::success()], ) .unwrap(); do_process_instruction( @@ -3579,6 +3920,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { &mut system_account, &mut owner_account, ], + &[Check::success()], ) .unwrap(); @@ -3599,6 +3941,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { &mut mock_incinerator_account, &mut owner_account, ], + &[Check::err(TokenError::NonNativeHasBalance.into())], ) ); assert_eq!( @@ -3617,6 +3960,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { &mut mock_incinerator_account, &mut owner_account, ], + &[Check::err(TokenError::NonNativeHasBalance.into())], ) ); @@ -3636,6 +3980,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { &mut mint_account, &mut recipient_account, ], + &[Check::success()], ) .unwrap(); do_process_instruction( @@ -3653,6 +3998,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { &mut mint_account, &mut recipient_account, ], + &[Check::success()], ) .unwrap(); @@ -3673,6 +4019,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { &mut recipient_account, &mut owner_account, ], + &[Check::err(ProgramError::InvalidAccountData)], ) ); assert_eq!( @@ -3691,6 +4038,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { &mut recipient_account, &mut owner_account, ], + &[Check::err(ProgramError::InvalidAccountData)], ) ); @@ -3709,6 +4057,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { &mut mock_incinerator_account, &mut owner_account, ], + &[Check::success()], ) .unwrap(); @@ -3726,6 +4075,7 @@ fn test_burn_and_close_system_and_incinerator_tokens() { &mut mock_incinerator_account, &mut owner_account, ], + &[Check::success()], ) .unwrap(); } @@ -3774,6 +4124,7 @@ fn test_multisig() { &mut rent_sysvar, account_info_iter.next().unwrap(), ], + &[Check::err(TokenError::NotRentExempt.into())], ) ); @@ -3789,6 +4140,7 @@ fn test_multisig() { &mut rent_sysvar, account_info_iter.next().unwrap(), ], + &[Check::success()], ) .unwrap(); @@ -3797,6 +4149,7 @@ fn test_multisig() { do_process_instruction( initialize_multisig2(&program_id, &multisig_key, &[&signer_keys[0]], 1).unwrap(), vec![&mut multisig_account2, account_info_iter.next().unwrap()], + &[Check::success()], ) .unwrap(); @@ -3825,6 +4178,7 @@ fn test_multisig() { account_info_iter.next().unwrap(), account_info_iter.next().unwrap(), ], + &[Check::success()], ) .unwrap(); @@ -3832,6 +4186,7 @@ fn test_multisig() { do_process_instruction( initialize_mint(&program_id, &mint_key, &multisig_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -3844,6 +4199,7 @@ fn test_multisig() { &mut multisig_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -3862,6 +4218,7 @@ fn test_multisig() { &mut multisig_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -3883,6 +4240,7 @@ fn test_multisig() { &mut multisig_account, account_info_iter.next().unwrap(), ], + &[Check::success()], ) .unwrap(); @@ -3904,6 +4262,7 @@ fn test_multisig() { &mut multisig_account, account_info_iter.next().unwrap(), ], + &[Check::success()], ) .unwrap(); @@ -3925,6 +4284,7 @@ fn test_multisig() { &mut multisig_account, account_info_iter.next().unwrap(), ], + &[Check::success()], ) .unwrap(); @@ -3956,6 +4316,7 @@ fn test_multisig() { account_info_iter.next().unwrap(), account_info_iter.next().unwrap(), ], + &[Check::success()], ) .unwrap(); @@ -3977,6 +4338,7 @@ fn test_multisig() { &mut multisig_account, account_info_iter.next().unwrap(), ], + &[Check::success()], ) .unwrap(); @@ -3998,6 +4360,7 @@ fn test_multisig() { &mut multisig_account, account_info_iter.next().unwrap(), ], + &[Check::success()], ) .unwrap(); @@ -4029,6 +4392,7 @@ fn test_multisig() { account_info_iter.next().unwrap(), account_info_iter.next().unwrap(), ], + &[Check::success()], ) .unwrap(); @@ -4052,6 +4416,7 @@ fn test_multisig() { ) .unwrap(), vec![&mut mint2_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); do_process_instruction( @@ -4062,6 +4427,7 @@ fn test_multisig() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); let account_info_iter = &mut signer_accounts.iter_mut(); @@ -4081,6 +4447,7 @@ fn test_multisig() { &mut multisig_account, account_info_iter.next().unwrap(), ], + &[Check::success()], ) .unwrap(); let account_info_iter = &mut signer_accounts.iter_mut(); @@ -4099,6 +4466,7 @@ fn test_multisig() { &mut multisig_account, account_info_iter.next().unwrap(), ], + &[Check::success()], ) .unwrap(); @@ -4119,6 +4487,7 @@ fn test_multisig() { &mut multisig_account, account_info_iter.next().unwrap(), ], + &[Check::success()], ) .unwrap(); @@ -4139,6 +4508,7 @@ fn test_multisig() { &mut multisig_account, account_info_iter.next().unwrap(), ], + &[Check::success()], ) .unwrap(); } @@ -4159,6 +4529,7 @@ fn test_owner_close_account_dups() { do_process_instruction_dups( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![mint_info.clone(), rent_info.clone()], + &[Check::success()], ) .unwrap(); @@ -4186,6 +4557,7 @@ fn test_owner_close_account_dups() { to_close_account_info.clone(), rent_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -4204,6 +4576,10 @@ fn test_owner_close_account_dups() { destination_account_info.clone(), to_close_account_info.clone(), ], + &[ + Check::success(), + Check::account(&to_close_key).data(&[]).build(), + ], ) .unwrap(); assert_eq!(*to_close_account_info.data.borrow(), &[0u8; Account::LEN]); @@ -4225,6 +4601,7 @@ fn test_close_authority_close_account_dups() { do_process_instruction_dups( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![mint_info.clone(), rent_info.clone()], + &[Check::success()], ) .unwrap(); @@ -4252,6 +4629,7 @@ fn test_close_authority_close_account_dups() { to_close_account_info.clone(), rent_info.clone(), ], + &[Check::success()], ) .unwrap(); let mut account = Account::unpack_unchecked(&to_close_account_info.data.borrow()).unwrap(); @@ -4272,6 +4650,10 @@ fn test_close_authority_close_account_dups() { destination_account_info.clone(), to_close_account_info.clone(), ], + &[ + Check::success(), + Check::account(&to_close_key).data(&[]).build(), + ], ) .unwrap(); assert_eq!(*to_close_account_info.data.borrow(), &[0u8; Account::LEN]); @@ -4317,6 +4699,7 @@ fn test_close_account() { &mut account3_account, &mut owner2_account, ], + &[Check::err(ProgramError::UninitializedAccount)], ) ); @@ -4324,6 +4707,7 @@ fn test_close_account() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); do_process_instruction( @@ -4334,6 +4718,7 @@ fn test_close_account() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); do_process_instruction( @@ -4344,6 +4729,12 @@ fn test_close_account() { &mut owner_account, &mut rent_sysvar, ], + &[ + Check::success(), + Check::account(&account_key) + .data_slice(64, &42u64.to_le_bytes()) + .build(), + ], ) .unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); @@ -4364,6 +4755,15 @@ fn test_close_account() { &mut owner_account, &mut rent_sysvar, ], + &[ + Check::success(), + Check::account(&account2_key) + .data_slice(109, &[1, 0, 0, 0]) + .build(), + Check::account(&account2_key) + .data_slice(64, &42u64.to_le_bytes()) + .build(), + ], ) .unwrap(); let account = Account::unpack_unchecked(&account2_account.data).unwrap(); @@ -4380,6 +4780,12 @@ fn test_close_account() { &mut account3_account, &mut owner_account, ], + &[ + Check::err(TokenError::NonNativeHasBalance.into()), + Check::account(&account_key) + .lamports(account_minimum_balance()) + .build() + ], ) ); assert_eq!(account_account.lamports, account_minimum_balance()); @@ -4388,6 +4794,7 @@ fn test_close_account() { do_process_instruction( burn(&program_id, &account_key, &mint_key, &owner_key, &[], 42).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner_account], + &[Check::success()], ) .unwrap(); @@ -4401,6 +4808,7 @@ fn test_close_account() { &mut account3_account, &mut owner2_account, ], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -4412,6 +4820,14 @@ fn test_close_account() { &mut account3_account, &mut owner_account, ], + &[ + Check::success(), + Check::account(&account_key).data(&[]).build(), + Check::account(&account_key).lamports(0).build(), + Check::account(&account3_key) + .lamports(2 * account_minimum_balance()) + .build(), + ], ) .unwrap(); assert!(account_account.data.is_empty()); @@ -4439,6 +4855,7 @@ fn test_close_account() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); account_account.lamports = 2; @@ -4454,6 +4871,7 @@ fn test_close_account() { ) .unwrap(), vec![&mut account_account, &mut owner_account], + &[Check::success()], ) .unwrap(); @@ -4467,6 +4885,7 @@ fn test_close_account() { &mut account3_account, &mut owner_account, ], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -4478,6 +4897,14 @@ fn test_close_account() { &mut account3_account, &mut owner2_account, ], + &[ + Check::success(), + Check::account(&account_key).data(&[]).build(), + Check::account(&account_key).lamports(0).build(), + Check::account(&account3_key) + .lamports(2 * account_minimum_balance() + 2) + .build(), + ], ) .unwrap(); assert!(account_account.data.is_empty()); @@ -4492,6 +4919,13 @@ fn test_close_account() { &mut account3_account, &mut owner_account, ], + &[ + Check::success(), + Check::account(&account2_key).data(&[]).build(), + Check::account(&account3_key) + .lamports(3 * account_minimum_balance() + 2 + 42) + .build(), + ], ) .unwrap(); assert!(account2_account.data.is_empty()); @@ -4542,6 +4976,15 @@ fn test_native_token() { &mut owner_account, &mut rent_sysvar, ], + &[ + Check::success(), + Check::account(&account_key) + .data_slice(109, &[1, 0, 0, 0]) + .build(), + Check::account(&account_key) + .data_slice(64, &40u64.to_le_bytes()) + .build(), + ], ) .unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); @@ -4563,6 +5006,15 @@ fn test_native_token() { &mut owner_account, &mut rent_sysvar, ], + &[ + Check::success(), + Check::account(&account2_key) + .data_slice(109, &[1, 0, 0, 0]) + .build(), + Check::account(&account2_key) + .data_slice(64, &0u64.to_le_bytes()) + .build(), + ], ) .unwrap(); let account = Account::unpack_unchecked(&account2_account.data).unwrap(); @@ -4583,6 +5035,7 @@ fn test_native_token() { ) .unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[Check::err(TokenError::NativeNotSupported.into())], ) ); @@ -4593,6 +5046,7 @@ fn test_native_token() { do_process_instruction( initialize_mint(&program_id, &bogus_mint_key, &owner_key, None, 2).unwrap(), vec![&mut bogus_mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -4613,6 +5067,7 @@ fn test_native_token() { &mut bogus_mint_account, &mut owner_account ], + &[Check::err(TokenError::NativeNotSupported.into())], ) ); @@ -4634,6 +5089,7 @@ fn test_native_token() { &mut account2_account, &mut owner_account, ], + &[Check::err(TokenError::InsufficientFunds.into())], ) ); @@ -4653,6 +5109,27 @@ fn test_native_token() { &mut account2_account, &mut owner_account, ], + &[ + Check::success(), + Check::account(&account_key) + .lamports(account_minimum_balance()) + .build(), + Check::account(&account_key) + .data_slice(109, &[1, 0, 0, 0]) + .build(), + Check::account(&account_key) + .data_slice(64, &0u64.to_le_bytes()) + .build(), + Check::account(&account2_key) + .lamports(account_minimum_balance() + 40) + .build(), + Check::account(&account_key) + .data_slice(109, &[1, 0, 0, 0]) + .build(), + Check::account(&account2_key) + .data_slice(64, &40u64.to_le_bytes()) + .build(), + ], ) .unwrap(); assert_eq!(account_account.lamports, account_minimum_balance()); @@ -4676,6 +5153,15 @@ fn test_native_token() { ) .unwrap(), vec![&mut account_account, &mut owner_account], + &[ + Check::success(), + Check::account(&account_key) + .data_slice(129, &[1, 0, 0, 0]) + .build(), + Check::account(&account_key) + .data_slice(133, owner3_key.as_ref()) + .build(), + ], ) .unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); @@ -4693,6 +5179,12 @@ fn test_native_token() { ) .unwrap(), vec![&mut account_account, &mut owner_account], + &[ + Check::success(), + Check::account(&account_key) + .data_slice(129, &[0, 0, 0, 0]) + .build(), + ], ) .unwrap(); @@ -4708,6 +5200,14 @@ fn test_native_token() { &mut account3_account, &mut owner2_account, ], + &[ + Check::success(), + Check::account(&account_key).lamports(0).build(), + Check::account(&account3_key) + .lamports(2 * account_minimum_balance()) + .build(), + Check::account(&account_key).data(&[]).build(), + ], ) .unwrap(); assert_eq!(account_account.lamports, 0); @@ -4745,6 +5245,7 @@ fn test_overflow() { do_process_instruction( initialize_mint(&program_id, &mint_key, &mint_owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -4757,6 +5258,7 @@ fn test_overflow() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -4769,6 +5271,7 @@ fn test_overflow() { &mut owner2_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -4788,6 +5291,12 @@ fn test_overflow() { &mut account_account, &mut mint_owner_account, ], + &[ + Check::success(), + Check::account(&account_key) + .data_slice(64, &u64::MAX.to_le_bytes()) + .build(), + ], ) .unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); @@ -4811,6 +5320,12 @@ fn test_overflow() { &mut account_account, &mut mint_owner_account, ], + &[ + Check::err(TokenError::Overflow.into()), + Check::account(&account_key) + .data_slice(64, &u64::MAX.to_le_bytes()) + .build(), + ], ) ); let account = Account::unpack_unchecked(&account_account.data).unwrap(); @@ -4834,6 +5349,7 @@ fn test_overflow() { &mut account2_account, &mut mint_owner_account, ], + &[Check::err(TokenError::Overflow.into())], ) ); @@ -4841,6 +5357,12 @@ fn test_overflow() { do_process_instruction( burn(&program_id, &account_key, &mint_key, &owner_key, &[], 100).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner_account], + &[ + Check::success(), + Check::account(&account_key) + .data_slice(64, &(u64::MAX - 100).to_le_bytes()) + .build(), + ], ) .unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); @@ -4861,6 +5383,12 @@ fn test_overflow() { &mut account_account, &mut mint_owner_account, ], + &[ + Check::success(), + Check::account(&account_key) + .data_slice(64, &u64::MAX.to_le_bytes()) + .build(), + ], ) .unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); @@ -4888,6 +5416,7 @@ fn test_overflow() { &mut account_account, &mut owner2_account, ], + &[Check::err(TokenError::Overflow.into())], ) ); } @@ -4918,6 +5447,7 @@ fn test_frozen() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -4930,6 +5460,7 @@ fn test_frozen() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -4942,6 +5473,7 @@ fn test_frozen() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -4949,6 +5481,7 @@ fn test_frozen() { do_process_instruction( mint_to(&program_id, &mint_key, &account_key, &owner_key, &[], 1000).unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[Check::success()], ) .unwrap(); @@ -4973,6 +5506,7 @@ fn test_frozen() { &mut account2_account, &mut owner_account, ], + &[Check::err(TokenError::AccountFrozen.into())], ) ); @@ -4999,6 +5533,7 @@ fn test_frozen() { &mut account2_account, &mut owner_account, ], + &[Check::err(TokenError::AccountFrozen.into())], ) ); @@ -5025,6 +5560,7 @@ fn test_frozen() { &mut delegate_account, &mut owner_account, ], + &[Check::err(TokenError::AccountFrozen.into())], ) ); @@ -5038,6 +5574,7 @@ fn test_frozen() { do_process_instruction( revoke(&program_id, &account_key, &owner_key, &[]).unwrap(), vec![&mut account_account, &mut owner_account], + &[Check::err(TokenError::AccountFrozen.into())], ) ); @@ -5056,6 +5593,7 @@ fn test_frozen() { ) .unwrap(), vec![&mut account_account, &mut owner_account,], + &[Check::err(TokenError::AccountFrozen.into())], ) ); @@ -5065,6 +5603,7 @@ fn test_frozen() { do_process_instruction( mint_to(&program_id, &mint_key, &account_key, &owner_key, &[], 100).unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account,], + &[Check::err(TokenError::AccountFrozen.into())], ) ); @@ -5074,6 +5613,7 @@ fn test_frozen() { do_process_instruction( burn(&program_id, &account_key, &mint_key, &owner_key, &[], 100).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner_account], + &[Check::err(TokenError::AccountFrozen.into())], ) ); } @@ -5101,6 +5641,7 @@ fn test_freeze_thaw_dups() { do_process_instruction_dups( initialize_mint(&program_id, &mint_key, &owner_key, Some(&account1_key), 2).unwrap(), vec![mint_info.clone(), rent_info.clone()], + &[Check::success()], ) .unwrap(); @@ -5113,6 +5654,7 @@ fn test_freeze_thaw_dups() { account1_info.clone(), rent_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -5124,6 +5666,7 @@ fn test_freeze_thaw_dups() { mint_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); @@ -5138,6 +5681,7 @@ fn test_freeze_thaw_dups() { mint_info.clone(), account1_info.clone(), ], + &[Check::success()], ) .unwrap(); } @@ -5166,6 +5710,7 @@ fn test_freeze_account() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -5178,6 +5723,7 @@ fn test_freeze_account() { &mut account_owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -5185,6 +5731,7 @@ fn test_freeze_account() { do_process_instruction( mint_to(&program_id, &mint_key, &account_key, &owner_key, &[], 1000).unwrap(), vec![&mut mint_account, &mut account_account, &mut owner_account], + &[Check::success()], ) .unwrap(); @@ -5194,6 +5741,7 @@ fn test_freeze_account() { do_process_instruction( freeze_account(&program_id, &account_key, &mint_key, &owner_key, &[]).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner_account], + &[Check::err(TokenError::MintCannotFreeze.into())], ) ); @@ -5206,6 +5754,7 @@ fn test_freeze_account() { do_process_instruction( freeze_account(&program_id, &account_key, &mint_key, &owner2_key, &[]).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner2_account], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -5215,6 +5764,7 @@ fn test_freeze_account() { do_process_instruction( thaw_account(&program_id, &account_key, &mint_key, &owner2_key, &[]).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner2_account], + &[Check::err(TokenError::InvalidState.into())], ) ); @@ -5222,6 +5772,12 @@ fn test_freeze_account() { do_process_instruction( freeze_account(&program_id, &account_key, &mint_key, &owner_key, &[]).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner_account], + &[ + Check::success(), + Check::account(&account_key) + .data_slice(108, &[AccountState::Frozen as u8]) + .build(), + ], ) .unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); @@ -5233,6 +5789,7 @@ fn test_freeze_account() { do_process_instruction( freeze_account(&program_id, &account_key, &mint_key, &owner_key, &[]).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner_account], + &[Check::err(TokenError::InvalidState.into())], ) ); @@ -5242,6 +5799,7 @@ fn test_freeze_account() { do_process_instruction( thaw_account(&program_id, &account_key, &mint_key, &owner2_key, &[]).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner2_account], + &[Check::err(TokenError::OwnerMismatch.into())], ) ); @@ -5249,6 +5807,12 @@ fn test_freeze_account() { do_process_instruction( thaw_account(&program_id, &account_key, &mint_key, &owner_key, &[]).unwrap(), vec![&mut account_account, &mut mint_account, &mut owner_account], + &[ + Check::success(), + Check::account(&account_key) + .data_slice(108, &[AccountState::Initialized as u8]) + .build(), + ], ) .unwrap(); let account = Account::unpack_unchecked(&account_account.data).unwrap(); @@ -5285,6 +5849,7 @@ fn test_initialize_account2_and_3() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -5296,12 +5861,14 @@ fn test_initialize_account2_and_3() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); do_process_instruction( initialize_account2(&program_id, &account_key, &mint_key, &owner_key).unwrap(), vec![&mut account2_account, &mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -5310,6 +5877,7 @@ fn test_initialize_account2_and_3() { do_process_instruction( initialize_account3(&program_id, &account_key, &mint_key, &owner_key).unwrap(), vec![&mut account3_account, &mut mint_account], + &[Check::success()], ) .unwrap(); @@ -5344,6 +5912,7 @@ fn test_sync_native() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -5356,6 +5925,7 @@ fn test_sync_native() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -5369,6 +5939,7 @@ fn test_sync_native() { do_process_instruction( sync_native(&program_id, &non_native_account_key,).unwrap(), vec![&mut non_native_account], + &[Check::err(TokenError::NonNativeNotSupported.into())], ) ); @@ -5378,6 +5949,7 @@ fn test_sync_native() { do_process_instruction( sync_native(&program_id, &native_account_key,).unwrap(), vec![&mut native_account], + &[Check::err(ProgramError::UninitializedAccount)], ) ); @@ -5396,6 +5968,7 @@ fn test_sync_native() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -5407,6 +5980,15 @@ fn test_sync_native() { do_process_instruction( sync_native(&program_id, &native_account_key,).unwrap(), vec![&mut native_account], + &[ + Check::err(ProgramError::IncorrectProgramId), + Check::account(&native_account_key) + .data_slice(109, &[1, 0, 0, 0]) + .build(), + Check::account(&native_account_key) + .data_slice(64, &lamports.to_le_bytes()) + .build() + ], ) ); native_account.owner = program_id; @@ -5419,6 +6001,12 @@ fn test_sync_native() { do_process_instruction( sync_native(&program_id, &native_account_key).unwrap(), vec![&mut native_account], + &[ + Check::success(), + Check::account(&native_account_key) + .data_slice(64, &lamports.to_le_bytes()) + .build(), + ], ) .unwrap(); let account = Account::unpack_unchecked(&native_account.data).unwrap(); @@ -5432,6 +6020,12 @@ fn test_sync_native() { do_process_instruction( sync_native(&program_id, &native_account_key).unwrap(), vec![&mut native_account], + &[ + Check::success(), + Check::account(&native_account_key) + .data_slice(64, &new_lamports.to_le_bytes()) + .build(), + ], ) .unwrap(); let account = Account::unpack_unchecked(&native_account.data).unwrap(); @@ -5446,6 +6040,7 @@ fn test_sync_native() { do_process_instruction( sync_native(&program_id, &native_account_key,).unwrap(), vec![&mut native_account], + &[Check::err(TokenError::InvalidState.into())], ) ); } @@ -5466,12 +6061,14 @@ fn test_get_account_data_size() { do_process_instruction( get_account_data_size(&program_id, &mint_key).unwrap(), vec![&mut mint_account], + &[Check::err(TokenError::InvalidMint.into())], ) ); do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -5479,6 +6076,7 @@ fn test_get_account_data_size() { do_process_instruction( get_account_data_size(&program_id, &mint_key).unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); } @@ -5503,6 +6101,7 @@ fn test_initialize_immutable_owner() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -5510,6 +6109,7 @@ fn test_initialize_immutable_owner() { do_process_instruction( initialize_immutable_owner(&program_id, &account_key).unwrap(), vec![&mut account_account], + &[Check::success()], ) .unwrap(); @@ -5522,6 +6122,7 @@ fn test_initialize_immutable_owner() { &mut owner_account, &mut rent_sysvar, ], + &[Check::success()], ) .unwrap(); @@ -5531,6 +6132,7 @@ fn test_initialize_immutable_owner() { do_process_instruction( initialize_immutable_owner(&program_id, &account_key).unwrap(), vec![&mut account_account], + &[Check::err(TokenError::AlreadyInUse.into())], ) ); } @@ -5551,6 +6153,7 @@ fn test_amount_to_ui_amount() { do_process_instruction( amount_to_ui_amount(&program_id, &mint_key, 110).unwrap(), vec![&mut mint_account], + &[Check::err(TokenError::InvalidMint.into())], ) ); @@ -5558,6 +6161,7 @@ fn test_amount_to_ui_amount() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -5565,6 +6169,7 @@ fn test_amount_to_ui_amount() { do_process_instruction( amount_to_ui_amount(&program_id, &mint_key, 23).unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -5572,6 +6177,7 @@ fn test_amount_to_ui_amount() { do_process_instruction( amount_to_ui_amount(&program_id, &mint_key, 110).unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -5579,6 +6185,7 @@ fn test_amount_to_ui_amount() { do_process_instruction( amount_to_ui_amount(&program_id, &mint_key, 4200).unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -5586,6 +6193,7 @@ fn test_amount_to_ui_amount() { do_process_instruction( amount_to_ui_amount(&program_id, &mint_key, 0).unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); } @@ -5606,6 +6214,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, "1.1").unwrap(), vec![&mut mint_account], + &[Check::err(TokenError::InvalidMint.into())], ) ); @@ -5613,6 +6222,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( initialize_mint(&program_id, &mint_key, &owner_key, None, 2).unwrap(), vec![&mut mint_account, &mut rent_sysvar], + &[Check::success()], ) .unwrap(); @@ -5620,6 +6230,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, "0.23").unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -5627,6 +6238,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, "0.20").unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -5634,6 +6246,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, "0.2000").unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -5641,6 +6254,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, ".20").unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -5648,6 +6262,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, "1.1").unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -5655,6 +6270,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, "1.10").unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -5662,6 +6278,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, "42").unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -5669,6 +6286,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, "42.").unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -5676,6 +6294,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, "0").unwrap(), vec![&mut mint_account], + &[Check::success()], ) .unwrap(); @@ -5685,6 +6304,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, "").unwrap(), vec![&mut mint_account], + &[Check::err(ProgramError::InvalidArgument)], ) ); assert_eq!( @@ -5692,6 +6312,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, ".").unwrap(), vec![&mut mint_account], + &[Check::err(ProgramError::InvalidArgument)], ) ); assert_eq!( @@ -5699,6 +6320,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, "0.111").unwrap(), vec![&mut mint_account], + &[Check::err(ProgramError::InvalidArgument)], ) ); assert_eq!( @@ -5706,6 +6328,7 @@ fn test_ui_amount_to_amount() { do_process_instruction( ui_amount_to_amount(&program_id, &mint_key, "0.t").unwrap(), vec![&mut mint_account], + &[Check::err(ProgramError::InvalidArgument)], ) ); }