withdraw_excess_lamports.rs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. #![cfg(not(feature = "fuzzing"))]
  2. #![allow(clippy::arithmetic_side_effects)]
  3. mod setup;
  4. use {
  5. assert_matches::assert_matches,
  6. setup::{mint, TOKEN_PROGRAM_ID},
  7. solana_program_test::{tokio, BanksClientError, ProgramTest},
  8. solana_sdk::{
  9. instruction::InstructionError,
  10. pubkey::Pubkey,
  11. signature::{Keypair, Signer},
  12. system_instruction,
  13. transaction::{Transaction, TransactionError},
  14. },
  15. spl_token_interface::state::{account::Account, mint::Mint, multisig::Multisig},
  16. std::mem::size_of,
  17. };
  18. #[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
  19. #[tokio::test]
  20. async fn withdraw_excess_lamports_from_mint(token_program: Pubkey) {
  21. let context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
  22. .start_with_context()
  23. .await;
  24. let excess_lamports = 4_000_000_000_000;
  25. // Given a mint authority, freeze authority and an account keypair.
  26. let mint_authority = Keypair::new();
  27. let freeze_authority = Pubkey::new_unique();
  28. let account = Keypair::new();
  29. let account_pubkey = account.pubkey();
  30. let account_size = size_of::<Mint>();
  31. let rent = context.banks_client.get_rent().await.unwrap();
  32. let mut initialize_ix = spl_token::instruction::initialize_mint(
  33. &spl_token::ID,
  34. &account.pubkey(),
  35. &mint_authority.pubkey(),
  36. Some(&freeze_authority),
  37. 0,
  38. )
  39. .unwrap();
  40. // Switches the program id to the token program.
  41. initialize_ix.program_id = token_program;
  42. // And we initialize a mint account with excess lamports.
  43. let instructions = vec![
  44. system_instruction::create_account(
  45. &context.payer.pubkey(),
  46. &account.pubkey(),
  47. rent.minimum_balance(account_size) + excess_lamports,
  48. account_size as u64,
  49. &token_program,
  50. ),
  51. initialize_ix,
  52. ];
  53. let tx = Transaction::new_signed_with_payer(
  54. &instructions,
  55. Some(&context.payer.pubkey()),
  56. &[&context.payer, &account],
  57. context.last_blockhash,
  58. );
  59. context.banks_client.process_transaction(tx).await.unwrap();
  60. let account = context
  61. .banks_client
  62. .get_account(account.pubkey())
  63. .await
  64. .unwrap();
  65. assert!(account.is_some());
  66. let account = account.unwrap();
  67. assert_eq!(
  68. account.lamports,
  69. rent.minimum_balance(account_size) + excess_lamports
  70. );
  71. // When we withdraw the excess lamports.
  72. let destination = Pubkey::new_unique();
  73. let mut withdraw_ix = spl_token_2022::instruction::withdraw_excess_lamports(
  74. &spl_token_2022::ID,
  75. &account_pubkey,
  76. &destination,
  77. &mint_authority.pubkey(),
  78. &[],
  79. )
  80. .unwrap();
  81. // Switches the program id to the token program.
  82. withdraw_ix.program_id = token_program;
  83. let tx = Transaction::new_signed_with_payer(
  84. &[withdraw_ix],
  85. Some(&context.payer.pubkey()),
  86. &[&context.payer, &mint_authority],
  87. context.last_blockhash,
  88. );
  89. context.banks_client.process_transaction(tx).await.unwrap();
  90. // Then the destination account has the excess lamports.
  91. let destination = context.banks_client.get_account(destination).await.unwrap();
  92. assert!(destination.is_some());
  93. let destination = destination.unwrap();
  94. assert_eq!(destination.lamports, excess_lamports);
  95. }
  96. #[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
  97. #[tokio::test]
  98. async fn withdraw_excess_lamports_from_account(token_program: Pubkey) {
  99. let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
  100. .start_with_context()
  101. .await;
  102. let excess_lamports = 4_000_000_000_000;
  103. // Given a mint account.
  104. let mint_authority = Pubkey::new_unique();
  105. let freeze_authority = Pubkey::new_unique();
  106. let mint = mint::initialize(
  107. &mut context,
  108. mint_authority,
  109. Some(freeze_authority),
  110. &token_program,
  111. )
  112. .await
  113. .unwrap();
  114. // Given a mint authority, freeze authority and an account keypair.
  115. let owner = Keypair::new();
  116. let account = Keypair::new();
  117. let account_pubkey = account.pubkey();
  118. let account_size = size_of::<Account>();
  119. let rent = context.banks_client.get_rent().await.unwrap();
  120. let mut initialize_ix = spl_token::instruction::initialize_account(
  121. &spl_token::ID,
  122. &account.pubkey(),
  123. &mint,
  124. &owner.pubkey(),
  125. )
  126. .unwrap();
  127. // Switches the program id to the token program.
  128. initialize_ix.program_id = token_program;
  129. // When a new mint account is created and initialized.
  130. let instructions = vec![
  131. system_instruction::create_account(
  132. &context.payer.pubkey(),
  133. &account.pubkey(),
  134. rent.minimum_balance(account_size) + excess_lamports,
  135. account_size as u64,
  136. &token_program,
  137. ),
  138. initialize_ix,
  139. ];
  140. let tx = Transaction::new_signed_with_payer(
  141. &instructions,
  142. Some(&context.payer.pubkey()),
  143. &[&context.payer, &account],
  144. context.last_blockhash,
  145. );
  146. context.banks_client.process_transaction(tx).await.unwrap();
  147. let account = context
  148. .banks_client
  149. .get_account(account.pubkey())
  150. .await
  151. .unwrap();
  152. assert!(account.is_some());
  153. let account = account.unwrap();
  154. assert_eq!(
  155. account.lamports,
  156. rent.minimum_balance(account_size) + excess_lamports
  157. );
  158. // When we withdraw the excess lamports.
  159. let destination = Pubkey::new_unique();
  160. let mut withdraw_ix = spl_token_2022::instruction::withdraw_excess_lamports(
  161. &spl_token_2022::ID,
  162. &account_pubkey,
  163. &destination,
  164. &owner.pubkey(),
  165. &[],
  166. )
  167. .unwrap();
  168. // Switches the program id to the token program.
  169. withdraw_ix.program_id = token_program;
  170. let tx = Transaction::new_signed_with_payer(
  171. &[withdraw_ix],
  172. Some(&context.payer.pubkey()),
  173. &[&context.payer, &owner],
  174. context.last_blockhash,
  175. );
  176. context.banks_client.process_transaction(tx).await.unwrap();
  177. // Then the destination account has the excess lamports.
  178. let destination = context.banks_client.get_account(destination).await.unwrap();
  179. assert!(destination.is_some());
  180. let destination = destination.unwrap();
  181. assert_eq!(destination.lamports, excess_lamports);
  182. }
  183. #[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
  184. #[tokio::test]
  185. async fn withdraw_excess_lamports_from_multisig(token_program: Pubkey) {
  186. let context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
  187. .start_with_context()
  188. .await;
  189. let excess_lamports = 4_000_000_000_000;
  190. // Given an account
  191. let multisig = Keypair::new();
  192. let signer1 = Keypair::new();
  193. let signer1_pubkey = signer1.pubkey();
  194. let signer2 = Keypair::new();
  195. let signer2_pubkey = signer2.pubkey();
  196. let signer3 = Keypair::new();
  197. let signer3_pubkey = signer3.pubkey();
  198. let signers = vec![&signer1_pubkey, &signer2_pubkey, &signer3_pubkey];
  199. let rent = context.banks_client.get_rent().await.unwrap();
  200. let account_size = size_of::<Multisig>();
  201. let mut initialize_ix = spl_token::instruction::initialize_multisig(
  202. &spl_token::ID,
  203. &multisig.pubkey(),
  204. &signers,
  205. 3,
  206. )
  207. .unwrap();
  208. // Switches the program id to the token program.
  209. initialize_ix.program_id = token_program;
  210. // And we initialize the multisig account.
  211. let instructions = vec![
  212. system_instruction::create_account(
  213. &context.payer.pubkey(),
  214. &multisig.pubkey(),
  215. rent.minimum_balance(account_size) + excess_lamports,
  216. account_size as u64,
  217. &token_program,
  218. ),
  219. initialize_ix,
  220. ];
  221. let tx = Transaction::new_signed_with_payer(
  222. &instructions,
  223. Some(&context.payer.pubkey()),
  224. &[&context.payer, &multisig],
  225. context.last_blockhash,
  226. );
  227. context.banks_client.process_transaction(tx).await.unwrap();
  228. let account = context
  229. .banks_client
  230. .get_account(multisig.pubkey())
  231. .await
  232. .unwrap();
  233. assert!(account.is_some());
  234. let account = account.unwrap();
  235. assert_eq!(
  236. account.lamports,
  237. rent.minimum_balance(account_size) + excess_lamports
  238. );
  239. // When we withdraw the excess lamports.
  240. let destination = Pubkey::new_unique();
  241. let mut withdraw_ix = spl_token_2022::instruction::withdraw_excess_lamports(
  242. &spl_token_2022::ID,
  243. &multisig.pubkey(),
  244. &destination,
  245. &multisig.pubkey(),
  246. &signers,
  247. )
  248. .unwrap();
  249. // Switches the program id to the token program.
  250. withdraw_ix.program_id = token_program;
  251. let tx = Transaction::new_signed_with_payer(
  252. &[withdraw_ix],
  253. Some(&context.payer.pubkey()),
  254. &[&context.payer, &signer1, &signer2, &signer3],
  255. context.last_blockhash,
  256. );
  257. context.banks_client.process_transaction(tx).await.unwrap();
  258. // Then the destination account has the excess lamports.
  259. let destination = context.banks_client.get_account(destination).await.unwrap();
  260. assert!(destination.is_some());
  261. let destination = destination.unwrap();
  262. assert_eq!(destination.lamports, excess_lamports);
  263. }
  264. #[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
  265. #[tokio::test]
  266. async fn fail_withdraw_excess_lamports_from_mint_wrong_authority(token_program: Pubkey) {
  267. let context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
  268. .start_with_context()
  269. .await;
  270. let excess_lamports = 4_000_000_000_000;
  271. // Given a mint authority, freeze authority and an account keypair.
  272. let mint_authority = Keypair::new();
  273. let freeze_authority = Pubkey::new_unique();
  274. let account = Keypair::new();
  275. let account_pubkey = account.pubkey();
  276. let account_size = size_of::<Mint>();
  277. let rent = context.banks_client.get_rent().await.unwrap();
  278. let mut initialize_ix = spl_token::instruction::initialize_mint(
  279. &spl_token::ID,
  280. &account.pubkey(),
  281. &mint_authority.pubkey(),
  282. Some(&freeze_authority),
  283. 0,
  284. )
  285. .unwrap();
  286. // Switches the program id to the token program.
  287. initialize_ix.program_id = token_program;
  288. // And we initialize a mint account with excess lamports.
  289. let instructions = vec![
  290. system_instruction::create_account(
  291. &context.payer.pubkey(),
  292. &account.pubkey(),
  293. rent.minimum_balance(account_size) + excess_lamports,
  294. account_size as u64,
  295. &token_program,
  296. ),
  297. initialize_ix,
  298. ];
  299. let tx = Transaction::new_signed_with_payer(
  300. &instructions,
  301. Some(&context.payer.pubkey()),
  302. &[&context.payer, &account],
  303. context.last_blockhash,
  304. );
  305. context.banks_client.process_transaction(tx).await.unwrap();
  306. let account = context
  307. .banks_client
  308. .get_account(account.pubkey())
  309. .await
  310. .unwrap();
  311. assert!(account.is_some());
  312. let account = account.unwrap();
  313. assert_eq!(
  314. account.lamports,
  315. rent.minimum_balance(account_size) + excess_lamports
  316. );
  317. // When we try to withdraw the excess lamports with the wrong authority.
  318. let destination = Pubkey::new_unique();
  319. let wrong_authority = Keypair::new();
  320. let mut withdraw_ix = spl_token_2022::instruction::withdraw_excess_lamports(
  321. &spl_token_2022::ID,
  322. &account_pubkey,
  323. &destination,
  324. &wrong_authority.pubkey(),
  325. &[],
  326. )
  327. .unwrap();
  328. // Switches the program id to the token program.
  329. withdraw_ix.program_id = token_program;
  330. let tx = Transaction::new_signed_with_payer(
  331. &[withdraw_ix],
  332. Some(&context.payer.pubkey()),
  333. &[&context.payer, &wrong_authority],
  334. context.last_blockhash,
  335. );
  336. let error = context
  337. .banks_client
  338. .process_transaction(tx)
  339. .await
  340. .unwrap_err();
  341. // The we expect an error.
  342. assert_matches!(
  343. error,
  344. BanksClientError::TransactionError(TransactionError::InstructionError(
  345. _,
  346. InstructionError::Custom(4) // TokenError::OwnerMismatch
  347. ))
  348. );
  349. }
  350. #[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
  351. #[tokio::test]
  352. async fn fail_withdraw_excess_lamports_from_account_wrong_authority(token_program: Pubkey) {
  353. let mut context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
  354. .start_with_context()
  355. .await;
  356. let excess_lamports = 4_000_000_000_000;
  357. // Given a mint account.
  358. let mint_authority = Pubkey::new_unique();
  359. let freeze_authority = Pubkey::new_unique();
  360. let mint = mint::initialize(
  361. &mut context,
  362. mint_authority,
  363. Some(freeze_authority),
  364. &token_program,
  365. )
  366. .await
  367. .unwrap();
  368. // Given a mint authority, freeze authority and an account keypair.
  369. let owner = Keypair::new();
  370. let account = Keypair::new();
  371. let account_pubkey = account.pubkey();
  372. let account_size = size_of::<Account>();
  373. let rent = context.banks_client.get_rent().await.unwrap();
  374. let mut initialize_ix = spl_token::instruction::initialize_account(
  375. &spl_token::ID,
  376. &account.pubkey(),
  377. &mint,
  378. &owner.pubkey(),
  379. )
  380. .unwrap();
  381. // Switches the program id to the token program.
  382. initialize_ix.program_id = token_program;
  383. // When a new mint account is created and initialized.
  384. let instructions = vec![
  385. system_instruction::create_account(
  386. &context.payer.pubkey(),
  387. &account.pubkey(),
  388. rent.minimum_balance(account_size) + excess_lamports,
  389. account_size as u64,
  390. &token_program,
  391. ),
  392. initialize_ix,
  393. ];
  394. let tx = Transaction::new_signed_with_payer(
  395. &instructions,
  396. Some(&context.payer.pubkey()),
  397. &[&context.payer, &account],
  398. context.last_blockhash,
  399. );
  400. context.banks_client.process_transaction(tx).await.unwrap();
  401. let account = context
  402. .banks_client
  403. .get_account(account.pubkey())
  404. .await
  405. .unwrap();
  406. assert!(account.is_some());
  407. let account = account.unwrap();
  408. assert_eq!(
  409. account.lamports,
  410. rent.minimum_balance(account_size) + excess_lamports
  411. );
  412. // When we try to withdraw the excess lamports with the wrong owner.
  413. let destination = Pubkey::new_unique();
  414. let wrong_owner = Keypair::new();
  415. let mut withdraw_ix = spl_token_2022::instruction::withdraw_excess_lamports(
  416. &spl_token_2022::ID,
  417. &account_pubkey,
  418. &destination,
  419. &wrong_owner.pubkey(),
  420. &[],
  421. )
  422. .unwrap();
  423. // Switches the program id to the token program.
  424. withdraw_ix.program_id = token_program;
  425. let tx = Transaction::new_signed_with_payer(
  426. &[withdraw_ix],
  427. Some(&context.payer.pubkey()),
  428. &[&context.payer, &wrong_owner],
  429. context.last_blockhash,
  430. );
  431. let error = context
  432. .banks_client
  433. .process_transaction(tx)
  434. .await
  435. .unwrap_err();
  436. // The we expect an error.
  437. assert_matches!(
  438. error,
  439. BanksClientError::TransactionError(TransactionError::InstructionError(
  440. _,
  441. InstructionError::Custom(4) // TokenError::OwnerMismatch
  442. ))
  443. );
  444. }
  445. #[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
  446. #[tokio::test]
  447. async fn fail_withdraw_excess_lamports_from_multisig_wrong_authority(token_program: Pubkey) {
  448. let context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
  449. .start_with_context()
  450. .await;
  451. let excess_lamports = 4_000_000_000_000;
  452. // Given an account
  453. let multisig = Keypair::new();
  454. let signer1 = Keypair::new();
  455. let signer1_pubkey = signer1.pubkey();
  456. let signer2 = Keypair::new();
  457. let signer2_pubkey = signer2.pubkey();
  458. let signer3 = Keypair::new();
  459. let signer3_pubkey = signer3.pubkey();
  460. let signers = vec![&signer1_pubkey, &signer2_pubkey, &signer3_pubkey];
  461. let rent = context.banks_client.get_rent().await.unwrap();
  462. let account_size = size_of::<Multisig>();
  463. let mut initialize_ix = spl_token::instruction::initialize_multisig(
  464. &spl_token::ID,
  465. &multisig.pubkey(),
  466. &signers,
  467. 3,
  468. )
  469. .unwrap();
  470. // Switches the program id to the token program.
  471. initialize_ix.program_id = token_program;
  472. // And we initialize the multisig account.
  473. let instructions = vec![
  474. system_instruction::create_account(
  475. &context.payer.pubkey(),
  476. &multisig.pubkey(),
  477. rent.minimum_balance(account_size) + excess_lamports,
  478. account_size as u64,
  479. &token_program,
  480. ),
  481. initialize_ix,
  482. ];
  483. let tx = Transaction::new_signed_with_payer(
  484. &instructions,
  485. Some(&context.payer.pubkey()),
  486. &[&context.payer, &multisig],
  487. context.last_blockhash,
  488. );
  489. context.banks_client.process_transaction(tx).await.unwrap();
  490. let account = context
  491. .banks_client
  492. .get_account(multisig.pubkey())
  493. .await
  494. .unwrap();
  495. assert!(account.is_some());
  496. let account = account.unwrap();
  497. assert_eq!(
  498. account.lamports,
  499. rent.minimum_balance(account_size) + excess_lamports
  500. );
  501. // When we try to withdraw the excess lamports with the wrong authority.
  502. let destination = Pubkey::new_unique();
  503. let wrong_authority = Keypair::new();
  504. let mut withdraw_ix = spl_token_2022::instruction::withdraw_excess_lamports(
  505. &spl_token_2022::ID,
  506. &multisig.pubkey(),
  507. &destination,
  508. &wrong_authority.pubkey(),
  509. &signers,
  510. )
  511. .unwrap();
  512. // Switches the program id to the token program.
  513. withdraw_ix.program_id = token_program;
  514. let tx = Transaction::new_signed_with_payer(
  515. &[withdraw_ix],
  516. Some(&context.payer.pubkey()),
  517. &[&context.payer, &signer1, &signer2, &signer3],
  518. context.last_blockhash,
  519. );
  520. let error = context
  521. .banks_client
  522. .process_transaction(tx)
  523. .await
  524. .unwrap_err();
  525. // The we expect an error.
  526. assert_matches!(
  527. error,
  528. BanksClientError::TransactionError(TransactionError::InstructionError(
  529. _,
  530. InstructionError::Custom(4) // TokenError::OwnerMismatch
  531. ))
  532. );
  533. }
  534. #[test_case::test_case(TOKEN_PROGRAM_ID ; "p-token")]
  535. #[tokio::test]
  536. async fn fail_withdraw_excess_lamports_from_multisig_missing_signer(token_program: Pubkey) {
  537. let context = ProgramTest::new("pinocchio_token_program", TOKEN_PROGRAM_ID, None)
  538. .start_with_context()
  539. .await;
  540. let excess_lamports = 4_000_000_000_000;
  541. // Given an account
  542. let multisig = Keypair::new();
  543. let signer1 = Keypair::new();
  544. let signer1_pubkey = signer1.pubkey();
  545. let signer2 = Keypair::new();
  546. let signer2_pubkey = signer2.pubkey();
  547. let signer3 = Keypair::new();
  548. let signer3_pubkey = signer3.pubkey();
  549. let signers = vec![&signer1_pubkey, &signer2_pubkey, &signer3_pubkey];
  550. let rent = context.banks_client.get_rent().await.unwrap();
  551. let account_size = size_of::<Multisig>();
  552. let mut initialize_ix = spl_token::instruction::initialize_multisig(
  553. &spl_token::ID,
  554. &multisig.pubkey(),
  555. &signers,
  556. 3,
  557. )
  558. .unwrap();
  559. // Switches the program id to the token program.
  560. initialize_ix.program_id = token_program;
  561. // And we initialize the multisig account.
  562. let instructions = vec![
  563. system_instruction::create_account(
  564. &context.payer.pubkey(),
  565. &multisig.pubkey(),
  566. rent.minimum_balance(account_size) + excess_lamports,
  567. account_size as u64,
  568. &token_program,
  569. ),
  570. initialize_ix,
  571. ];
  572. let tx = Transaction::new_signed_with_payer(
  573. &instructions,
  574. Some(&context.payer.pubkey()),
  575. &[&context.payer, &multisig],
  576. context.last_blockhash,
  577. );
  578. context.banks_client.process_transaction(tx).await.unwrap();
  579. let account = context
  580. .banks_client
  581. .get_account(multisig.pubkey())
  582. .await
  583. .unwrap();
  584. assert!(account.is_some());
  585. let account = account.unwrap();
  586. assert_eq!(
  587. account.lamports,
  588. rent.minimum_balance(account_size) + excess_lamports
  589. );
  590. // When we try to withdraw the excess lamports with the wrong authority.
  591. let destination = Pubkey::new_unique();
  592. let mut withdraw_ix = spl_token_2022::instruction::withdraw_excess_lamports(
  593. &spl_token_2022::ID,
  594. &multisig.pubkey(),
  595. &destination,
  596. &multisig.pubkey(),
  597. &[&signer1_pubkey, &signer2_pubkey],
  598. )
  599. .unwrap();
  600. // Switches the program id to the token program.
  601. withdraw_ix.program_id = token_program;
  602. let tx = Transaction::new_signed_with_payer(
  603. &[withdraw_ix],
  604. Some(&context.payer.pubkey()),
  605. &[&context.payer, &signer1, &signer2],
  606. context.last_blockhash,
  607. );
  608. let error = context
  609. .banks_client
  610. .process_transaction(tx)
  611. .await
  612. .unwrap_err();
  613. // The we expect an error.
  614. assert_matches!(
  615. error,
  616. BanksClientError::TransactionError(TransactionError::InstructionError(
  617. _,
  618. InstructionError::MissingRequiredSignature
  619. ))
  620. );
  621. }