1
0

batch.rs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  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. /// `bpf_account_data_direct_mapping` feature.
  273. fn mollusk() -> Mollusk {
  274. let feature_set = {
  275. let mut fs = FeatureSet::all_enabled();
  276. fs.active_mut()
  277. .remove(&agave_feature_set::bpf_account_data_direct_mapping::id());
  278. fs
  279. };
  280. let mut mollusk = Mollusk {
  281. feature_set,
  282. ..Default::default()
  283. };
  284. mollusk.add_program(
  285. &TOKEN_PROGRAM_ID,
  286. "pinocchio_token_program",
  287. &bpf_loader_upgradeable::id(),
  288. );
  289. mollusk
  290. }
  291. #[tokio::test]
  292. async fn batch_transfer() {
  293. let authority_key = Pubkey::new_unique();
  294. let mint_key = Pubkey::new_unique();
  295. // source account
  296. // - amount: 1_000_000_000
  297. // - mint: mint_key
  298. // - is_native: false
  299. // - program_id: TOKEN_PROGRAM_ID
  300. let source_account_key = Pubkey::new_unique();
  301. let source_account = create_token_account(
  302. &mint_key,
  303. &authority_key,
  304. false,
  305. 1_000_000_000,
  306. &TOKEN_PROGRAM_ID,
  307. );
  308. // destination account
  309. // - amount: 0
  310. // - mint: mint_key
  311. // - is_native: false
  312. // - program_id: TOKEN_PROGRAM_ID
  313. let destination_account_key = Pubkey::new_unique();
  314. let destination_account =
  315. create_token_account(&mint_key, &authority_key, false, 0, &TOKEN_PROGRAM_ID);
  316. let instruction = batch_instruction(vec![spl_token_interface::instruction::transfer(
  317. &TOKEN_PROGRAM_ID,
  318. &source_account_key,
  319. &destination_account_key,
  320. &authority_key,
  321. &[],
  322. 500_000_000,
  323. )
  324. .unwrap()])
  325. .unwrap();
  326. // Expected to succeed.
  327. mollusk().process_and_validate_instruction_chain(
  328. &[(&instruction, &[Check::success(), Check::all_rent_exempt()])],
  329. &[
  330. (source_account_key, source_account),
  331. (destination_account_key, destination_account),
  332. (
  333. authority_key,
  334. Account {
  335. lamports: Rent::default().minimum_balance(0),
  336. ..Default::default()
  337. },
  338. ),
  339. ],
  340. );
  341. }
  342. #[tokio::test]
  343. async fn batch_fail_transfer_with_invalid_program_owner() {
  344. let invalid_program_id = Pubkey::new_from_array([2; 32]);
  345. let native_mint = Pubkey::new_from_array(native_mint::ID);
  346. let authority_key = Pubkey::new_unique();
  347. // source account
  348. // - amount: 1_000_000_000
  349. // - mint: native_mint
  350. // - is_native: true
  351. // - program_id: invalid_program_id
  352. let source_account_key = Pubkey::new_unique();
  353. let source_account = create_token_account(
  354. &native_mint,
  355. &authority_key,
  356. true,
  357. 1_000_000_000,
  358. &invalid_program_id,
  359. );
  360. // destination account
  361. // - amount: 0
  362. // - mint: native_mint
  363. // - is_native: true
  364. // - program_id: TOKEN_PROGRAM_ID
  365. let destination_account_key = Pubkey::new_unique();
  366. let destination_account =
  367. create_token_account(&native_mint, &authority_key, true, 0, &TOKEN_PROGRAM_ID);
  368. let instruction = batch_instruction(vec![spl_token_interface::instruction::transfer(
  369. &TOKEN_PROGRAM_ID,
  370. &source_account_key,
  371. &destination_account_key,
  372. &authority_key,
  373. &[],
  374. 500_000_000,
  375. )
  376. .unwrap()])
  377. .unwrap();
  378. // Expected to fail since source account has an invalid program owner.
  379. mollusk().process_and_validate_instruction_chain(
  380. &[(
  381. &instruction,
  382. &[
  383. Check::err(ProgramError::IncorrectProgramId),
  384. Check::all_rent_exempt(),
  385. ],
  386. )],
  387. &[
  388. (source_account_key, source_account),
  389. (destination_account_key, destination_account),
  390. (
  391. authority_key,
  392. Account {
  393. lamports: Rent::default().minimum_balance(0),
  394. ..Default::default()
  395. },
  396. ),
  397. ],
  398. );
  399. }
  400. #[tokio::test]
  401. async fn batch_fail_transfer_checked_with_invalid_program_owner() {
  402. let invalid_program_id = Pubkey::new_from_array([2; 32]);
  403. let authority_key = Pubkey::new_unique();
  404. let native_mint_key = Pubkey::new_from_array(native_mint::ID);
  405. let native_mint = create_mint(&authority_key, 5_000_000_000, 9, &TOKEN_PROGRAM_ID);
  406. // source account
  407. // - amount: 1_000_000_000
  408. // - mint: native_mint
  409. // - is_native: true
  410. // - program_id: invalid_program_id
  411. let source_account_key = Pubkey::new_unique();
  412. let source_account = create_token_account(
  413. &native_mint_key,
  414. &authority_key,
  415. true,
  416. 1_000_000_000,
  417. &invalid_program_id,
  418. );
  419. // destination account
  420. // - amount: 0
  421. // - mint: native_mint
  422. // - is_native: true
  423. // - program_id: TOKEN_PROGRAM_ID
  424. let destination_account_key = Pubkey::new_unique();
  425. let destination_account =
  426. create_token_account(&native_mint_key, &authority_key, true, 0, &TOKEN_PROGRAM_ID);
  427. let instruction = batch_instruction(vec![spl_token_interface::instruction::transfer_checked(
  428. &TOKEN_PROGRAM_ID,
  429. &source_account_key,
  430. &native_mint_key,
  431. &destination_account_key,
  432. &authority_key,
  433. &[],
  434. 500_000_000,
  435. 9,
  436. )
  437. .unwrap()])
  438. .unwrap();
  439. // Expected to fail since source account has an invalid program owner.
  440. mollusk().process_and_validate_instruction_chain(
  441. &[(
  442. &instruction,
  443. &[
  444. Check::err(ProgramError::IncorrectProgramId),
  445. Check::all_rent_exempt(),
  446. ],
  447. )],
  448. &[
  449. (source_account_key, source_account),
  450. (destination_account_key, destination_account),
  451. (native_mint_key, native_mint),
  452. (
  453. authority_key,
  454. Account {
  455. lamports: Rent::default().minimum_balance(0),
  456. ..Default::default()
  457. },
  458. ),
  459. ],
  460. );
  461. }
  462. #[tokio::test]
  463. async fn batch_fail_swap_tokens_with_invalid_program_owner() {
  464. let native_mint = Pubkey::new_from_array(native_mint::ID);
  465. let invalid_program_id = Pubkey::new_from_array([2; 32]);
  466. let authority_key = Pubkey::new_unique();
  467. // Account A
  468. // - amount: 1_000
  469. // - mint: native_mint
  470. // - is_native: false
  471. // - program_id: invalid_program_id
  472. let account_a_key = Pubkey::new_unique();
  473. let account_a = create_token_account(
  474. &native_mint,
  475. &authority_key,
  476. false,
  477. 1_000,
  478. &invalid_program_id,
  479. );
  480. // Account B
  481. // - amount: 0
  482. // - mint: native_mint
  483. // - is_native: true
  484. // - program_id: TOKEN_PROGRAM_ID
  485. let account_b_key = Pubkey::new_unique();
  486. let account_b = create_token_account(&native_mint, &authority_key, true, 0, &TOKEN_PROGRAM_ID);
  487. // Account C
  488. // - amount: 0
  489. // - mint: native_mint
  490. // - is_native: true
  491. // - program_id: TOKEN_PROGRAM_ID
  492. let account_c_key = Pubkey::new_unique();
  493. let account_c =
  494. create_token_account(&native_mint, &authority_key, true, 1_000, &TOKEN_PROGRAM_ID);
  495. // Batch instruction to swap tokens
  496. // - transfer 300 from account A to account B
  497. // - transfer 300 from account C to account A
  498. let instruction = batch_instruction(vec![
  499. spl_token_interface::instruction::sync_native(&TOKEN_PROGRAM_ID, &account_b_key).unwrap(),
  500. spl_token_interface::instruction::sync_native(&TOKEN_PROGRAM_ID, &account_c_key).unwrap(),
  501. spl_token_interface::instruction::transfer(
  502. &TOKEN_PROGRAM_ID,
  503. &account_a_key,
  504. &account_b_key,
  505. &authority_key,
  506. &[],
  507. 300,
  508. )
  509. .unwrap(),
  510. spl_token_interface::instruction::transfer(
  511. &TOKEN_PROGRAM_ID,
  512. &account_c_key,
  513. &account_a_key,
  514. &authority_key,
  515. &[],
  516. 300,
  517. )
  518. .unwrap(),
  519. ])
  520. .unwrap();
  521. // Expected to fail since account A has an invalid program owner.
  522. mollusk().process_and_validate_instruction_chain(
  523. &[(
  524. &instruction,
  525. &[
  526. Check::err(ProgramError::IncorrectProgramId),
  527. Check::all_rent_exempt(),
  528. ],
  529. )],
  530. &[
  531. (account_a_key, account_a),
  532. (account_b_key, account_b),
  533. (account_c_key, account_c),
  534. (
  535. authority_key,
  536. Account {
  537. lamports: Rent::default().minimum_balance(0),
  538. ..Default::default()
  539. },
  540. ),
  541. ],
  542. );
  543. }
  544. #[tokio::test]
  545. async fn batch_fail_mint_to_with_invalid_program_owner() {
  546. let invalid_program_id = Pubkey::new_from_array([2; 32]);
  547. let authority_key = Pubkey::new_unique();
  548. let mint_key = Pubkey::new_unique();
  549. let mint = create_mint(&authority_key, 0, 0, &TOKEN_PROGRAM_ID);
  550. // account A (invalid)
  551. // - amount: 1_000_000_000
  552. // - mint: native_mint
  553. // - is_native: false
  554. // - program_id: invalid_program_id
  555. let account_a_key = Pubkey::new_unique();
  556. let account_a = create_token_account(&mint_key, &authority_key, false, 0, &invalid_program_id);
  557. // account B
  558. // - amount: 0
  559. // - mint: native_mint
  560. // - is_native: false
  561. // - program_id: TOKEN_PROGRAM_ID
  562. let account_b_key = Pubkey::new_unique();
  563. let account_b = create_token_account(&mint_key, &authority_key, false, 0, &TOKEN_PROGRAM_ID);
  564. let instruction = batch_instruction(vec![
  565. spl_token_interface::instruction::mint_to(
  566. &TOKEN_PROGRAM_ID,
  567. &mint_key,
  568. &account_a_key,
  569. &authority_key,
  570. &[],
  571. 1_000_000_000,
  572. )
  573. .unwrap(),
  574. spl_token_interface::instruction::mint_to(
  575. &TOKEN_PROGRAM_ID,
  576. &mint_key,
  577. &account_b_key,
  578. &authority_key,
  579. &[],
  580. 1_000_000_000,
  581. )
  582. .unwrap(),
  583. ])
  584. .unwrap();
  585. // Expected to fail since source account has an invalid program owner.
  586. mollusk().process_and_validate_instruction_chain(
  587. &[(
  588. &instruction,
  589. &[
  590. Check::err(ProgramError::IncorrectProgramId),
  591. Check::all_rent_exempt(),
  592. ],
  593. )],
  594. &[
  595. (mint_key, mint),
  596. (account_a_key, account_a),
  597. (account_b_key, account_b),
  598. (
  599. authority_key,
  600. Account {
  601. lamports: Rent::default().minimum_balance(0),
  602. ..Default::default()
  603. },
  604. ),
  605. ],
  606. );
  607. }
  608. #[tokio::test]
  609. async fn batch_fail_burn_with_invalid_program_owner() {
  610. let invalid_program_id = Pubkey::new_from_array([2; 32]);
  611. let authority_key = Pubkey::new_unique();
  612. let mint_key = Pubkey::new_unique();
  613. let mint = create_mint(&authority_key, 2_000_000_000, 0, &TOKEN_PROGRAM_ID);
  614. // account A
  615. // - amount: 0
  616. // - mint: native_mint
  617. // - is_native: false
  618. // - program_id: TOKEN_PROGRAM_ID
  619. let account_a_key = Pubkey::new_unique();
  620. let account_a = create_token_account(&mint_key, &authority_key, false, 0, &TOKEN_PROGRAM_ID);
  621. // account B (invalid)
  622. // - amount: 1_000_000_000
  623. // - mint: native_mint
  624. // - is_native: false
  625. // - program_id: invalid_program_id
  626. let account_b_key = Pubkey::new_unique();
  627. let account_b = create_token_account(
  628. &mint_key,
  629. &authority_key,
  630. false,
  631. 1_000_000_000,
  632. &invalid_program_id,
  633. );
  634. let instruction = batch_instruction(vec![
  635. spl_token_interface::instruction::mint_to(
  636. &TOKEN_PROGRAM_ID,
  637. &mint_key,
  638. &account_a_key,
  639. &authority_key,
  640. &[],
  641. 1_000_000_000,
  642. )
  643. .unwrap(),
  644. spl_token_interface::instruction::mint_to(
  645. &TOKEN_PROGRAM_ID,
  646. &mint_key,
  647. &account_b_key,
  648. &authority_key,
  649. &[],
  650. 1_000_000_000,
  651. )
  652. .unwrap(),
  653. spl_token_interface::instruction::burn(
  654. &TOKEN_PROGRAM_ID,
  655. &account_a_key,
  656. &mint_key,
  657. &authority_key,
  658. &[],
  659. 1_000_000_000,
  660. )
  661. .unwrap(),
  662. spl_token_interface::instruction::burn(
  663. &TOKEN_PROGRAM_ID,
  664. &account_b_key,
  665. &mint_key,
  666. &authority_key,
  667. &[],
  668. 1_000_000_000,
  669. )
  670. .unwrap(),
  671. ])
  672. .unwrap();
  673. // Expected to fail since source account has an invalid program owner.
  674. mollusk().process_and_validate_instruction_chain(
  675. &[(
  676. &instruction,
  677. &[
  678. Check::err(ProgramError::IncorrectProgramId),
  679. Check::all_rent_exempt(),
  680. ],
  681. )],
  682. &[
  683. (mint_key, mint),
  684. (account_a_key, account_a),
  685. (account_b_key, account_b),
  686. (
  687. authority_key,
  688. Account {
  689. lamports: Rent::default().minimum_balance(0),
  690. ..Default::default()
  691. },
  692. ),
  693. ],
  694. );
  695. }