|
7 | 7 | solana_account::AccountSharedData, |
8 | 8 | solana_keypair::Keypair, |
9 | 9 | solana_native_token::LAMPORTS_PER_SOL, |
| 10 | + solana_program_error::ProgramError, |
10 | 11 | solana_program_test::*, |
11 | 12 | solana_pubkey::Pubkey, |
12 | 13 | solana_signer::Signer, |
@@ -298,3 +299,49 @@ async fn fail_bad_deposit(stake_version: StakeProgramVersion) { |
298 | 299 | // fail: bad owner |
299 | 300 | check_error(e, SinglePoolError::InvalidDepositSolSource); |
300 | 301 | } |
| 302 | + |
| 303 | +// this is a canary for if/when we convert from solana-program-test to mollusk. |
| 304 | +// to be able to self-cpi, we must explicitly pass the program account itself as an instruction account. |
| 305 | +// js testing with litesvm reveals that more abstracted svm-based test harnesses might not enforce this. |
| 306 | +// if this test no longer passes when we convert, we have our answer, and can simply assert the AccountMeta exists |
| 307 | +#[test_matrix( |
| 308 | + [StakeProgramVersion::Stable, StakeProgramVersion::Beta, StakeProgramVersion::Edge] |
| 309 | +)] |
| 310 | +#[tokio::test] |
| 311 | +async fn fail_bad_cpi(stake_version: StakeProgramVersion) { |
| 312 | + let Some(program_test) = program_test(stake_version) else { |
| 313 | + return; |
| 314 | + }; |
| 315 | + let mut context = program_test.start_with_context().await; |
| 316 | + |
| 317 | + let accounts = SinglePoolAccounts::default(); |
| 318 | + accounts.initialize(&mut context).await; |
| 319 | + |
| 320 | + advance_epoch(&mut context).await; |
| 321 | + |
| 322 | + let mut instruction = instruction::deposit_sol( |
| 323 | + &id(), |
| 324 | + &accounts.vote_account.pubkey(), |
| 325 | + &accounts.alice.pubkey(), |
| 326 | + &accounts.alice_token, |
| 327 | + TEST_STAKE_AMOUNT, |
| 328 | + ); |
| 329 | + let svsp_account_meta = instruction.accounts.pop().unwrap(); |
| 330 | + assert_eq!(svsp_account_meta.pubkey, id()); |
| 331 | + |
| 332 | + let transaction = Transaction::new_signed_with_payer( |
| 333 | + &[instruction], |
| 334 | + Some(&context.payer.pubkey()), |
| 335 | + &[&context.payer, &accounts.alice], |
| 336 | + context.last_blockhash, |
| 337 | + ); |
| 338 | + |
| 339 | + let e = context |
| 340 | + .banks_client |
| 341 | + .process_transaction(transaction) |
| 342 | + .await |
| 343 | + .unwrap_err(); |
| 344 | + |
| 345 | + // fail: missing svsp |
| 346 | + check_error(e, ProgramError::NotEnoughAccountKeys); |
| 347 | +} |
0 commit comments