Skip to content

Commit 5e9dfae

Browse files
committed
fix js for replenish
1 parent 95decf7 commit 5e9dfae

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

clients/js/src/instructions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ type DepositSolInstruction = Instruction<typeof SINGLE_POOL_PROGRAM_ID> &
175175
ReadonlyAccount<typeof SYSTEM_PROGRAM_ID>,
176176
ReadonlyAccount<typeof TOKEN_PROGRAM_ID>,
177177
ReadonlyAccount<typeof STAKE_PROGRAM_ID>,
178+
ReadonlyAccount<typeof SINGLE_POOL_PROGRAM_ID>,
178179
]
179180
> &
180181
InstructionWithData<Uint8Array>;
@@ -491,6 +492,7 @@ export async function depositSolInstruction(
491492
{ address: SYSTEM_PROGRAM_ID, role: AccountRole.READONLY },
492493
{ address: TOKEN_PROGRAM_ID, role: AccountRole.READONLY },
493494
{ address: STAKE_PROGRAM_ID, role: AccountRole.READONLY },
495+
{ address: SINGLE_POOL_PROGRAM_ID, role: AccountRole.READONLY },
494496
],
495497
programAddress,
496498
};

program/src/instruction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ pub enum SinglePoolInstruction {
187187
/// 12. `[]` System program
188188
/// 13. `[]` Token program
189189
/// 14. `[]` Stake program
190+
/// 15. `[]` Single-validator stake pool program
190191
DepositSol {
191192
/// Amount of sol to deposit
192193
lamports: u64,

program/tests/deposit_sol.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use {
77
solana_account::AccountSharedData,
88
solana_keypair::Keypair,
99
solana_native_token::LAMPORTS_PER_SOL,
10+
solana_program_error::ProgramError,
1011
solana_program_test::*,
1112
solana_pubkey::Pubkey,
1213
solana_signer::Signer,
@@ -298,3 +299,49 @@ async fn fail_bad_deposit(stake_version: StakeProgramVersion) {
298299
// fail: bad owner
299300
check_error(e, SinglePoolError::InvalidDepositSolSource);
300301
}
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

Comments
 (0)