Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Main

on:
push:
branches: [main,mollusk-tests-7-move-lamports]
branches: [main,mollusk-tests-8-move-stake]
pull_request:

env:
Expand Down
70 changes: 70 additions & 0 deletions program/tests/helpers/instruction_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,73 @@ impl InstructionConfig for MoveLamportsFullConfig<'_> {
accounts
}
}

pub struct MoveStakeConfig<'a> {
pub source: (&'a Pubkey, &'a AccountSharedData),
pub destination: (&'a Pubkey, &'a AccountSharedData),
pub amount: u64,
/// Override signer for testing wrong signer scenarios (defaults to ctx.staker)
pub override_signer: Option<&'a Pubkey>,
}

impl<'a> MoveStakeConfig<'a> {
/// Helper to get the default source vote account from context
pub fn with_default_vote(self, ctx: &'a StakeTestContext) -> MoveStakeWithVoteConfig<'a> {
MoveStakeWithVoteConfig {
source: self.source,
destination: self.destination,
override_signer: self.override_signer,
amount: self.amount,
source_vote: (
ctx.vote_account.as_ref().expect("vote_account required"),
ctx.vote_account_data
.as_ref()
.expect("vote_account_data required"),
),
dest_vote: None,
}
}
}

impl InstructionConfig for MoveStakeConfig<'_> {
fn build_instruction(&self, ctx: &StakeTestContext) -> Instruction {
let signer = self.override_signer.unwrap_or(&ctx.staker);
ixn::move_stake(self.source.0, self.destination.0, signer, self.amount)
}

fn build_accounts(&self) -> Vec<(Pubkey, AccountSharedData)> {
vec![
(*self.source.0, self.source.1.clone()),
(*self.destination.0, self.destination.1.clone()),
]
}
}

pub struct MoveStakeWithVoteConfig<'a> {
pub source: (&'a Pubkey, &'a AccountSharedData),
pub destination: (&'a Pubkey, &'a AccountSharedData),
pub amount: u64,
/// Override signer for testing wrong signer scenarios (defaults to ctx.staker)
pub override_signer: Option<&'a Pubkey>,
pub source_vote: (&'a Pubkey, &'a AccountSharedData),
pub dest_vote: Option<(&'a Pubkey, &'a AccountSharedData)>,
}

impl InstructionConfig for MoveStakeWithVoteConfig<'_> {
fn build_instruction(&self, ctx: &StakeTestContext) -> Instruction {
let signer = self.override_signer.unwrap_or(&ctx.staker);
ixn::move_stake(self.source.0, self.destination.0, signer, self.amount)
}

fn build_accounts(&self) -> Vec<(Pubkey, AccountSharedData)> {
let mut accounts = vec![
(*self.source.0, self.source.1.clone()),
(*self.destination.0, self.destination.1.clone()),
(*self.source_vote.0, self.source_vote.1.clone()),
];
if let Some((vote_pk, vote_acc)) = self.dest_vote {
accounts.push((*vote_pk, vote_acc.clone()));
}
accounts
}
}
Loading