Skip to content

Commit f4a831f

Browse files
committed
migrate move_stake tests
1 parent 55d0b85 commit f4a831f

File tree

4 files changed

+528
-277
lines changed

4 files changed

+528
-277
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Main
22

33
on:
44
push:
5-
branches: [main,mollusk-tests-7-move-lamports]
5+
branches: [main,mollusk-tests-8-move-stake]
66
pull_request:
77

88
env:

program/tests/helpers/instruction_builders.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,73 @@ impl InstructionConfig for MoveLamportsFullConfig<'_> {
271271
accounts
272272
}
273273
}
274+
275+
pub struct MoveStakeConfig<'a> {
276+
pub source: (&'a Pubkey, &'a AccountSharedData),
277+
pub destination: (&'a Pubkey, &'a AccountSharedData),
278+
pub amount: u64,
279+
/// Override signer for testing wrong signer scenarios (defaults to ctx.staker)
280+
pub override_signer: Option<&'a Pubkey>,
281+
}
282+
283+
impl<'a> MoveStakeConfig<'a> {
284+
/// Helper to get the default source vote account from context
285+
pub fn with_default_vote(self, ctx: &'a StakeTestContext) -> MoveStakeWithVoteConfig<'a> {
286+
MoveStakeWithVoteConfig {
287+
source: self.source,
288+
destination: self.destination,
289+
override_signer: self.override_signer,
290+
amount: self.amount,
291+
source_vote: (
292+
ctx.vote_account.as_ref().expect("vote_account required"),
293+
ctx.vote_account_data
294+
.as_ref()
295+
.expect("vote_account_data required"),
296+
),
297+
dest_vote: None,
298+
}
299+
}
300+
}
301+
302+
impl InstructionConfig for MoveStakeConfig<'_> {
303+
fn build_instruction(&self, ctx: &StakeTestContext) -> Instruction {
304+
let signer = self.override_signer.unwrap_or(&ctx.staker);
305+
ixn::move_stake(self.source.0, self.destination.0, signer, self.amount)
306+
}
307+
308+
fn build_accounts(&self) -> Vec<(Pubkey, AccountSharedData)> {
309+
vec![
310+
(*self.source.0, self.source.1.clone()),
311+
(*self.destination.0, self.destination.1.clone()),
312+
]
313+
}
314+
}
315+
316+
pub struct MoveStakeWithVoteConfig<'a> {
317+
pub source: (&'a Pubkey, &'a AccountSharedData),
318+
pub destination: (&'a Pubkey, &'a AccountSharedData),
319+
pub amount: u64,
320+
/// Override signer for testing wrong signer scenarios (defaults to ctx.staker)
321+
pub override_signer: Option<&'a Pubkey>,
322+
pub source_vote: (&'a Pubkey, &'a AccountSharedData),
323+
pub dest_vote: Option<(&'a Pubkey, &'a AccountSharedData)>,
324+
}
325+
326+
impl InstructionConfig for MoveStakeWithVoteConfig<'_> {
327+
fn build_instruction(&self, ctx: &StakeTestContext) -> Instruction {
328+
let signer = self.override_signer.unwrap_or(&ctx.staker);
329+
ixn::move_stake(self.source.0, self.destination.0, signer, self.amount)
330+
}
331+
332+
fn build_accounts(&self) -> Vec<(Pubkey, AccountSharedData)> {
333+
let mut accounts = vec![
334+
(*self.source.0, self.source.1.clone()),
335+
(*self.destination.0, self.destination.1.clone()),
336+
(*self.source_vote.0, self.source_vote.1.clone()),
337+
];
338+
if let Some((vote_pk, vote_acc)) = self.dest_vote {
339+
accounts.push((*vote_pk, vote_acc.clone()));
340+
}
341+
accounts
342+
}
343+
}

0 commit comments

Comments
 (0)