batch.rs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. mod setup;
  2. use {
  3. crate::setup::TOKEN_PROGRAM_ID,
  4. agave_feature_set::FeatureSet,
  5. mollusk_svm::{result::Check, Mollusk},
  6. pinocchio_token_interface::{
  7. native_mint,
  8. state::{
  9. account::Account as TokenAccount, account_state::AccountState, load_mut_unchecked,
  10. mint::Mint,
  11. },
  12. },
  13. solana_account::Account,
  14. solana_instruction::{AccountMeta, Instruction},
  15. solana_keypair::Keypair,
  16. solana_program_error::ProgramError,
  17. solana_program_pack::Pack,
  18. solana_program_test::{tokio, ProgramTest},
  19. solana_pubkey::Pubkey,
  20. solana_rent::Rent,
  21. solana_sdk_ids::bpf_loader_upgradeable,
  22. solana_signer::Signer,
  23. solana_system_interface::instruction::create_account,
  24. solana_transaction::Transaction,
  25. };
  26. fn batch_instruction(instructions: Vec<Instruction>) -> Result<Instruction, ProgramError> {
  27. // Create a `Vec` of ordered `AccountMeta`s
  28. let mut accounts: Vec<AccountMeta> = vec![];
  29. // Start with the batch discriminator
  30. let mut data: Vec<u8> = vec![0xff];
  31. for instruction in instructions {
  32. // Error out on non-token IX.
  33. if instruction.program_id.ne(&spl_token_interface::ID) {
  34. return Err(ProgramError::IncorrectProgramId);
  35. }
  36. data.push(instruction.accounts.len() as u8);
  37. data.push(instruction.data.len() as u8);
  38. data.extend_from_slice(&instruction.data);
  39. accounts.extend_from_slice(&instruction.accounts);
  40. }
  41. Ok(Instruction {
  42. program_id: spl_token_interface::ID,
  43. data,
  44. accounts,
  45. })
  46. }
  47. #[tokio::test]
  48. async fn batch_initialize_mint_transfer_close() {
  49. let context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
  50. .start_with_context()
  51. .await;
  52. let rent = context.banks_client.get_rent().await.unwrap();
  53. let mint_len = spl_token_interface::state::Mint::LEN;
  54. let mint_rent = rent.minimum_balance(mint_len);
  55. let account_len = spl_token_interface::state::Account::LEN;
  56. let account_rent = rent.minimum_balance(account_len);
  57. // Create a mint
  58. let mint_a = Keypair::new();
  59. let mint_authority = Keypair::new();
  60. let create_mint_a = create_account(
  61. &context.payer.pubkey(),
  62. &mint_a.pubkey(),
  63. mint_rent,
  64. mint_len as u64,
  65. &TOKEN_PROGRAM_ID,
  66. );
  67. let initialize_mint_ix = spl_token_interface::instruction::initialize_mint(
  68. &TOKEN_PROGRAM_ID,
  69. &mint_a.pubkey(),
  70. &mint_authority.pubkey(),
  71. None,
  72. 6,
  73. )
  74. .unwrap();
  75. // Create a mint 2 with a freeze authority
  76. let mint_b = Keypair::new();
  77. let freeze_authority = Pubkey::new_unique();
  78. let create_mint_b = create_account(
  79. &context.payer.pubkey(),
  80. &mint_b.pubkey(),
  81. mint_rent,
  82. mint_len as u64,
  83. &TOKEN_PROGRAM_ID,
  84. );
  85. let initialize_mint_with_freeze_authority_ix =
  86. spl_token_interface::instruction::initialize_mint2(
  87. &TOKEN_PROGRAM_ID,
  88. &mint_b.pubkey(),
  89. &mint_authority.pubkey(),
  90. Some(&freeze_authority),
  91. 6,
  92. )
  93. .unwrap();
  94. // Create 2 token accounts for mint A and 1 for mint B
  95. let owner_a = Keypair::new();
  96. let owner_b = Keypair::new();
  97. let owner_a_ta_a = Keypair::new();
  98. let owner_b_ta_a = Keypair::new();
  99. let create_owner_a_ta_a = create_account(
  100. &context.payer.pubkey(),
  101. &owner_a_ta_a.pubkey(),
  102. account_rent,
  103. account_len as u64,
  104. &TOKEN_PROGRAM_ID,
  105. );
  106. let create_owner_b_ta_a = create_account(
  107. &context.payer.pubkey(),
  108. &owner_b_ta_a.pubkey(),
  109. account_rent,
  110. account_len as u64,
  111. &TOKEN_PROGRAM_ID,
  112. );
  113. let intialize_owner_a_ta_a = spl_token_interface::instruction::initialize_account3(
  114. &TOKEN_PROGRAM_ID,
  115. &owner_a_ta_a.pubkey(),
  116. &mint_a.pubkey(),
  117. &owner_a.pubkey(),
  118. )
  119. .unwrap();
  120. let intialize_owner_b_ta_a = spl_token_interface::instruction::initialize_account3(
  121. &TOKEN_PROGRAM_ID,
  122. &owner_b_ta_a.pubkey(),
  123. &mint_a.pubkey(),
  124. &owner_b.pubkey(),
  125. )
  126. .unwrap();
  127. // Mint Token A to Owner A
  128. let mint_token_a_to_owner_a = spl_token_interface::instruction::mint_to(
  129. &TOKEN_PROGRAM_ID,
  130. &mint_a.pubkey(),
  131. &owner_a_ta_a.pubkey(),
  132. &mint_authority.pubkey(),
  133. &[],
  134. 1_000_000,
  135. )
  136. .unwrap();
  137. // Transfer Token A from Owner A to Owner B
  138. let transfer_token_a_to_owner_b = spl_token_interface::instruction::transfer(
  139. &TOKEN_PROGRAM_ID,
  140. &owner_a_ta_a.pubkey(),
  141. &owner_b_ta_a.pubkey(),
  142. &owner_a.pubkey(),
  143. &[],
  144. 1_000_000,
  145. )
  146. .unwrap();
  147. // Close Token A
  148. let close_owner_a_ta_a = spl_token_interface::instruction::close_account(
  149. &TOKEN_PROGRAM_ID,
  150. &owner_a_ta_a.pubkey(),
  151. &owner_a.pubkey(),
  152. &owner_a.pubkey(),
  153. &[],
  154. )
  155. .unwrap();
  156. let batch_ix = batch_instruction(vec![
  157. initialize_mint_ix,
  158. initialize_mint_with_freeze_authority_ix,
  159. intialize_owner_a_ta_a,
  160. intialize_owner_b_ta_a,
  161. mint_token_a_to_owner_a,
  162. transfer_token_a_to_owner_b,
  163. close_owner_a_ta_a,
  164. ])
  165. .unwrap();
  166. let tx = Transaction::new_signed_with_payer(
  167. &[
  168. create_mint_a,
  169. create_mint_b,
  170. create_owner_a_ta_a,
  171. create_owner_b_ta_a,
  172. batch_ix,
  173. ],
  174. Some(&context.payer.pubkey()),
  175. &vec![
  176. &context.payer,
  177. &mint_a,
  178. &mint_b,
  179. &owner_a_ta_a,
  180. &owner_b_ta_a,
  181. &mint_authority,
  182. &owner_a,
  183. ],
  184. context.last_blockhash,
  185. );
  186. context.banks_client.process_transaction(tx).await.unwrap();
  187. let mint_a_account = context
  188. .banks_client
  189. .get_account(mint_a.pubkey())
  190. .await
  191. .unwrap();
  192. assert!(mint_a_account.is_some());
  193. let mint_a_account =
  194. spl_token_interface::state::Mint::unpack(&mint_a_account.unwrap().data).unwrap();
  195. assert_eq!(mint_a_account.supply, 1000000);
  196. let mint_b_account = context
  197. .banks_client
  198. .get_account(mint_b.pubkey())
  199. .await
  200. .unwrap();
  201. assert!(mint_b_account.is_some());
  202. let mint_b_account =
  203. spl_token_interface::state::Mint::unpack(&mint_b_account.unwrap().data).unwrap();
  204. assert_eq!(mint_b_account.supply, 0);
  205. let owner_b_ta_a_account = context
  206. .banks_client
  207. .get_account(owner_b_ta_a.pubkey())
  208. .await
  209. .unwrap();
  210. assert!(owner_b_ta_a_account.is_some());
  211. let owner_b_ta_a_account =
  212. spl_token_interface::state::Account::unpack(&owner_b_ta_a_account.unwrap().data).unwrap();
  213. assert_eq!(owner_b_ta_a_account.amount, 1000000);
  214. let closed_owner_a_ta_a = context
  215. .banks_client
  216. .get_account(owner_a_ta_a.pubkey())
  217. .await
  218. .unwrap();
  219. assert!(closed_owner_a_ta_a.is_none());
  220. }
  221. fn create_mint(
  222. mint_authority: &Pubkey,
  223. supply: u64,
  224. decimals: u8,
  225. program_owner: &Pubkey,
  226. ) -> Account {
  227. let space = size_of::<Mint>();
  228. let lamports = Rent::default().minimum_balance(space);
  229. let mut data: Vec<u8> = vec![0u8; space];
  230. let mint = unsafe { load_mut_unchecked::<Mint>(data.as_mut_slice()).unwrap() };
  231. mint.set_initialized();
  232. mint.set_supply(supply);
  233. mint.set_mint_authority(mint_authority.as_array());
  234. mint.decimals = decimals;
  235. Account {
  236. lamports,
  237. data,
  238. owner: *program_owner,
  239. executable: false,
  240. ..Default::default()
  241. }
  242. }
  243. fn create_token_account(
  244. mint: &Pubkey,
  245. owner: &Pubkey,
  246. is_native: bool,
  247. amount: u64,
  248. program_owner: &Pubkey,
  249. ) -> Account {
  250. let space = size_of::<TokenAccount>();
  251. let mut lamports = Rent::default().minimum_balance(space);
  252. let mut data: Vec<u8> = vec![0u8; space];
  253. let token = unsafe { load_mut_unchecked::<TokenAccount>(data.as_mut_slice()).unwrap() };
  254. token.set_account_state(AccountState::Initialized);
  255. token.mint = *mint.as_array();
  256. token.owner = *owner.as_array();
  257. token.set_amount(amount);
  258. token.set_native(is_native);
  259. token.set_native_amount(amount);
  260. if is_native {
  261. lamports = lamports.saturating_add(amount);
  262. }
  263. Account {
  264. lamports,
  265. data,
  266. owner: *program_owner,
  267. executable: false,
  268. ..Default::default()
  269. }
  270. }
  271. /// Creates a Mollusk instance with the default feature set, excluding the
  272. /// `account_data_direct_mapping` feature.
  273. fn mollusk() -> Mollusk {
  274. let feature_set = {
  275. // When upgrading to v3.1, add this back in
  276. //let fs = FeatureSet::all_enabled();
  277. //fs.active_mut()
  278. // .remove(&agave_feature_set::account_data_direct_mapping::id());
  279. //fs
  280. FeatureSet::all_enabled()
  281. };
  282. let mut mollusk = Mollusk {
  283. feature_set,
  284. ..Default::default()
  285. };
  286. mollusk.add_program(
  287. &TOKEN_PROGRAM_ID,
  288. "pinocchio_token_program",
  289. &bpf_loader_upgradeable::id(),
  290. );
  291. mollusk
  292. }
  293. #[tokio::test]
  294. async fn batch_transfer() {
  295. let authority_key = Pubkey::new_unique();
  296. let mint_key = Pubkey::new_unique();
  297. // source account
  298. // - amount: 1_000_000_000
  299. // - mint: mint_key
  300. // - is_native: false
  301. // - program_id: TOKEN_PROGRAM_ID
  302. let source_account_key = Pubkey::new_unique();
  303. let source_account = create_token_account(
  304. &mint_key,
  305. &authority_key,
  306. false,
  307. 1_000_000_000,
  308. &TOKEN_PROGRAM_ID,
  309. );
  310. // destination account
  311. // - amount: 0
  312. // - mint: mint_key
  313. // - is_native: false
  314. // - program_id: TOKEN_PROGRAM_ID
  315. let destination_account_key = Pubkey::new_unique();
  316. let destination_account =
  317. create_token_account(&mint_key, &authority_key, false, 0, &TOKEN_PROGRAM_ID);
  318. let instruction = batch_instruction(vec![spl_token_interface::instruction::transfer(
  319. &TOKEN_PROGRAM_ID,
  320. &source_account_key,
  321. &destination_account_key,
  322. &authority_key,
  323. &[],
  324. 500_000_000,
  325. )
  326. .unwrap()])
  327. .unwrap();
  328. // Expected to succeed.
  329. mollusk().process_and_validate_instruction_chain(
  330. &[(&instruction, &[Check::success(), Check::all_rent_exempt()])],
  331. &[
  332. (source_account_key, source_account),
  333. (destination_account_key, destination_account),
  334. (
  335. authority_key,
  336. Account {
  337. lamports: Rent::default().minimum_balance(0),
  338. ..Default::default()
  339. },
  340. ),
  341. ],
  342. );
  343. }
  344. #[tokio::test]
  345. async fn batch_fail_transfer_with_invalid_program_owner() {
  346. let invalid_program_id = Pubkey::new_from_array([2; 32]);
  347. let native_mint = Pubkey::new_from_array(native_mint::ID);
  348. let authority_key = Pubkey::new_unique();
  349. // source account
  350. // - amount: 1_000_000_000
  351. // - mint: native_mint
  352. // - is_native: true
  353. // - program_id: invalid_program_id
  354. let source_account_key = Pubkey::new_unique();
  355. let source_account = create_token_account(
  356. &native_mint,
  357. &authority_key,
  358. true,
  359. 1_000_000_000,
  360. &invalid_program_id,
  361. );
  362. // destination account
  363. // - amount: 0
  364. // - mint: native_mint
  365. // - is_native: true
  366. // - program_id: TOKEN_PROGRAM_ID
  367. let destination_account_key = Pubkey::new_unique();
  368. let destination_account =
  369. create_token_account(&native_mint, &authority_key, true, 0, &TOKEN_PROGRAM_ID);
  370. let instruction = batch_instruction(vec![spl_token_interface::instruction::transfer(
  371. &TOKEN_PROGRAM_ID,
  372. &source_account_key,
  373. &destination_account_key,
  374. &authority_key,
  375. &[],
  376. 500_000_000,
  377. )
  378. .unwrap()])
  379. .unwrap();
  380. // Expected to fail since source account has an invalid program owner.
  381. mollusk().process_and_validate_instruction_chain(
  382. &[(
  383. &instruction,
  384. &[
  385. Check::err(ProgramError::IncorrectProgramId),
  386. Check::all_rent_exempt(),
  387. ],
  388. )],
  389. &[
  390. (source_account_key, source_account),
  391. (destination_account_key, destination_account),
  392. (
  393. authority_key,
  394. Account {
  395. lamports: Rent::default().minimum_balance(0),
  396. ..Default::default()
  397. },
  398. ),
  399. ],
  400. );
  401. }
  402. #[tokio::test]
  403. async fn batch_fail_transfer_checked_with_invalid_program_owner() {
  404. let invalid_program_id = Pubkey::new_from_array([2; 32]);
  405. let authority_key = Pubkey::new_unique();
  406. let native_mint_key = Pubkey::new_from_array(native_mint::ID);
  407. let native_mint = create_mint(&authority_key, 5_000_000_000, 9, &TOKEN_PROGRAM_ID);
  408. // source account
  409. // - amount: 1_000_000_000
  410. // - mint: native_mint
  411. // - is_native: true
  412. // - program_id: invalid_program_id
  413. let source_account_key = Pubkey::new_unique();
  414. let source_account = create_token_account(
  415. &native_mint_key,
  416. &authority_key,
  417. true,
  418. 1_000_000_000,
  419. &invalid_program_id,
  420. );
  421. // destination account
  422. // - amount: 0
  423. // - mint: native_mint
  424. // - is_native: true
  425. // - program_id: TOKEN_PROGRAM_ID
  426. let destination_account_key = Pubkey::new_unique();
  427. let destination_account =
  428. create_token_account(&native_mint_key, &authority_key, true, 0, &TOKEN_PROGRAM_ID);
  429. let instruction = batch_instruction(vec![spl_token_interface::instruction::transfer_checked(
  430. &TOKEN_PROGRAM_ID,
  431. &source_account_key,
  432. &native_mint_key,
  433. &destination_account_key,
  434. &authority_key,
  435. &[],
  436. 500_000_000,
  437. 9,
  438. )
  439. .unwrap()])
  440. .unwrap();
  441. // Expected to fail since source account has an invalid program owner.
  442. mollusk().process_and_validate_instruction_chain(
  443. &[(
  444. &instruction,
  445. &[
  446. Check::err(ProgramError::IncorrectProgramId),
  447. Check::all_rent_exempt(),
  448. ],
  449. )],
  450. &[
  451. (source_account_key, source_account),
  452. (destination_account_key, destination_account),
  453. (native_mint_key, native_mint),
  454. (
  455. authority_key,
  456. Account {
  457. lamports: Rent::default().minimum_balance(0),
  458. ..Default::default()
  459. },
  460. ),
  461. ],
  462. );
  463. }
  464. #[tokio::test]
  465. async fn batch_fail_swap_tokens_with_invalid_program_owner() {
  466. let native_mint = Pubkey::new_from_array(native_mint::ID);
  467. let invalid_program_id = Pubkey::new_from_array([2; 32]);
  468. let authority_key = Pubkey::new_unique();
  469. // Account A
  470. // - amount: 1_000
  471. // - mint: native_mint
  472. // - is_native: false
  473. // - program_id: invalid_program_id
  474. let account_a_key = Pubkey::new_unique();
  475. let account_a = create_token_account(
  476. &native_mint,
  477. &authority_key,
  478. false,
  479. 1_000,
  480. &invalid_program_id,
  481. );
  482. // Account B
  483. // - amount: 0
  484. // - mint: native_mint
  485. // - is_native: true
  486. // - program_id: TOKEN_PROGRAM_ID
  487. let account_b_key = Pubkey::new_unique();
  488. let account_b = create_token_account(&native_mint, &authority_key, true, 0, &TOKEN_PROGRAM_ID);
  489. // Account C
  490. // - amount: 0
  491. // - mint: native_mint
  492. // - is_native: true
  493. // - program_id: TOKEN_PROGRAM_ID
  494. let account_c_key = Pubkey::new_unique();
  495. let account_c =
  496. create_token_account(&native_mint, &authority_key, true, 1_000, &TOKEN_PROGRAM_ID);
  497. // Batch instruction to swap tokens
  498. // - transfer 300 from account A to account B
  499. // - transfer 300 from account C to account A
  500. let instruction = batch_instruction(vec![
  501. spl_token_interface::instruction::sync_native(&TOKEN_PROGRAM_ID, &account_b_key).unwrap(),
  502. spl_token_interface::instruction::sync_native(&TOKEN_PROGRAM_ID, &account_c_key).unwrap(),
  503. spl_token_interface::instruction::transfer(
  504. &TOKEN_PROGRAM_ID,
  505. &account_a_key,
  506. &account_b_key,
  507. &authority_key,
  508. &[],
  509. 300,
  510. )
  511. .unwrap(),
  512. spl_token_interface::instruction::transfer(
  513. &TOKEN_PROGRAM_ID,
  514. &account_c_key,
  515. &account_a_key,
  516. &authority_key,
  517. &[],
  518. 300,
  519. )
  520. .unwrap(),
  521. ])
  522. .unwrap();
  523. // Expected to fail since account A has an invalid program owner.
  524. mollusk().process_and_validate_instruction_chain(
  525. &[(
  526. &instruction,
  527. &[
  528. Check::err(ProgramError::IncorrectProgramId),
  529. Check::all_rent_exempt(),
  530. ],
  531. )],
  532. &[
  533. (account_a_key, account_a),
  534. (account_b_key, account_b),
  535. (account_c_key, account_c),
  536. (
  537. authority_key,
  538. Account {
  539. lamports: Rent::default().minimum_balance(0),
  540. ..Default::default()
  541. },
  542. ),
  543. ],
  544. );
  545. }
  546. #[tokio::test]
  547. async fn batch_fail_mint_to_with_invalid_program_owner() {
  548. let invalid_program_id = Pubkey::new_from_array([2; 32]);
  549. let authority_key = Pubkey::new_unique();
  550. let mint_key = Pubkey::new_unique();
  551. let mint = create_mint(&authority_key, 0, 0, &TOKEN_PROGRAM_ID);
  552. // account A (invalid)
  553. // - amount: 1_000_000_000
  554. // - mint: native_mint
  555. // - is_native: false
  556. // - program_id: invalid_program_id
  557. let account_a_key = Pubkey::new_unique();
  558. let account_a = create_token_account(&mint_key, &authority_key, false, 0, &invalid_program_id);
  559. // account B
  560. // - amount: 0
  561. // - mint: native_mint
  562. // - is_native: false
  563. // - program_id: TOKEN_PROGRAM_ID
  564. let account_b_key = Pubkey::new_unique();
  565. let account_b = create_token_account(&mint_key, &authority_key, false, 0, &TOKEN_PROGRAM_ID);
  566. let instruction = batch_instruction(vec![
  567. spl_token_interface::instruction::mint_to(
  568. &TOKEN_PROGRAM_ID,
  569. &mint_key,
  570. &account_a_key,
  571. &authority_key,
  572. &[],
  573. 1_000_000_000,
  574. )
  575. .unwrap(),
  576. spl_token_interface::instruction::mint_to(
  577. &TOKEN_PROGRAM_ID,
  578. &mint_key,
  579. &account_b_key,
  580. &authority_key,
  581. &[],
  582. 1_000_000_000,
  583. )
  584. .unwrap(),
  585. ])
  586. .unwrap();
  587. // Expected to fail since source account has an invalid program owner.
  588. mollusk().process_and_validate_instruction_chain(
  589. &[(
  590. &instruction,
  591. &[
  592. Check::err(ProgramError::IncorrectProgramId),
  593. Check::all_rent_exempt(),
  594. ],
  595. )],
  596. &[
  597. (mint_key, mint),
  598. (account_a_key, account_a),
  599. (account_b_key, account_b),
  600. (
  601. authority_key,
  602. Account {
  603. lamports: Rent::default().minimum_balance(0),
  604. ..Default::default()
  605. },
  606. ),
  607. ],
  608. );
  609. }
  610. #[tokio::test]
  611. async fn batch_fail_burn_with_invalid_program_owner() {
  612. let invalid_program_id = Pubkey::new_from_array([2; 32]);
  613. let authority_key = Pubkey::new_unique();
  614. let mint_key = Pubkey::new_unique();
  615. let mint = create_mint(&authority_key, 2_000_000_000, 0, &TOKEN_PROGRAM_ID);
  616. // account A
  617. // - amount: 0
  618. // - mint: native_mint
  619. // - is_native: false
  620. // - program_id: TOKEN_PROGRAM_ID
  621. let account_a_key = Pubkey::new_unique();
  622. let account_a = create_token_account(&mint_key, &authority_key, false, 0, &TOKEN_PROGRAM_ID);
  623. // account B (invalid)
  624. // - amount: 1_000_000_000
  625. // - mint: native_mint
  626. // - is_native: false
  627. // - program_id: invalid_program_id
  628. let account_b_key = Pubkey::new_unique();
  629. let account_b = create_token_account(
  630. &mint_key,
  631. &authority_key,
  632. false,
  633. 1_000_000_000,
  634. &invalid_program_id,
  635. );
  636. let instruction = batch_instruction(vec![
  637. spl_token_interface::instruction::mint_to(
  638. &TOKEN_PROGRAM_ID,
  639. &mint_key,
  640. &account_a_key,
  641. &authority_key,
  642. &[],
  643. 1_000_000_000,
  644. )
  645. .unwrap(),
  646. spl_token_interface::instruction::mint_to(
  647. &TOKEN_PROGRAM_ID,
  648. &mint_key,
  649. &account_b_key,
  650. &authority_key,
  651. &[],
  652. 1_000_000_000,
  653. )
  654. .unwrap(),
  655. spl_token_interface::instruction::burn(
  656. &TOKEN_PROGRAM_ID,
  657. &account_a_key,
  658. &mint_key,
  659. &authority_key,
  660. &[],
  661. 1_000_000_000,
  662. )
  663. .unwrap(),
  664. spl_token_interface::instruction::burn(
  665. &TOKEN_PROGRAM_ID,
  666. &account_b_key,
  667. &mint_key,
  668. &authority_key,
  669. &[],
  670. 1_000_000_000,
  671. )
  672. .unwrap(),
  673. ])
  674. .unwrap();
  675. // Expected to fail since source account has an invalid program owner.
  676. mollusk().process_and_validate_instruction_chain(
  677. &[(
  678. &instruction,
  679. &[
  680. Check::err(ProgramError::IncorrectProgramId),
  681. Check::all_rent_exempt(),
  682. ],
  683. )],
  684. &[
  685. (mint_key, mint),
  686. (account_a_key, account_a),
  687. (account_b_key, account_b),
  688. (
  689. authority_key,
  690. Account {
  691. lamports: Rent::default().minimum_balance(0),
  692. ..Default::default()
  693. },
  694. ),
  695. ],
  696. );
  697. }