Add tests for split() from Uninitialized account where dest=source (#23442)
This commit is contained in:
parent
e87b941a51
commit
79a515e88e
|
@ -3959,8 +3959,35 @@ mod tests {
|
||||||
Err(InstructionError::MissingRequiredSignature)
|
Err(InstructionError::MissingRequiredSignature)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let signers = HashSet::from([stake_pubkey]);
|
||||||
|
|
||||||
|
// splitting an uninitialized account where the destination is the same as the source
|
||||||
|
{
|
||||||
|
// splitting should work when...
|
||||||
|
// - when split amount is the full balance
|
||||||
|
// - when split amount is zero
|
||||||
|
// - when split amount is non-zero and less than the full balance
|
||||||
|
//
|
||||||
|
// and splitting should fail when the split amount is greater than the balance
|
||||||
|
assert_eq!(
|
||||||
|
stake_keyed_account.split(stake_lamports, &stake_keyed_account, &signers),
|
||||||
|
Ok(()),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
stake_keyed_account.split(0, &stake_keyed_account, &signers),
|
||||||
|
Ok(()),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
stake_keyed_account.split(stake_lamports / 2, &stake_keyed_account, &signers),
|
||||||
|
Ok(()),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
stake_keyed_account.split(stake_lamports + 1, &stake_keyed_account, &signers),
|
||||||
|
Err(InstructionError::InsufficientFunds),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// this should work
|
// this should work
|
||||||
let signers = vec![stake_pubkey].into_iter().collect();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.split(stake_lamports / 2, &split_stake_keyed_account, &signers),
|
stake_keyed_account.split(stake_lamports / 2, &split_stake_keyed_account, &signers),
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -3982,24 +4009,30 @@ mod tests {
|
||||||
&id(),
|
&id(),
|
||||||
)
|
)
|
||||||
.expect("stake_account");
|
.expect("stake_account");
|
||||||
|
|
||||||
let split_stake_pubkey = solana_sdk::pubkey::new_rand();
|
|
||||||
let split_stake_account = AccountSharedData::new_ref_data_with_space(
|
|
||||||
0,
|
|
||||||
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
|
|
||||||
std::mem::size_of::<StakeState>(),
|
|
||||||
&id(),
|
|
||||||
)
|
|
||||||
.expect("stake_account");
|
|
||||||
|
|
||||||
let signers = vec![stake_pubkey].into_iter().collect();
|
|
||||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
|
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
|
||||||
let split_stake_keyed_account =
|
let signers = vec![stake_pubkey].into_iter().collect();
|
||||||
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_account);
|
|
||||||
assert_eq!(
|
for split_stake_state in &[
|
||||||
stake_keyed_account.split(stake_lamports / 2, &split_stake_keyed_account, &signers),
|
StakeState::Initialized(Meta::default()),
|
||||||
Err(InstructionError::InvalidAccountData)
|
StakeState::Stake(Meta::default(), Stake::default()),
|
||||||
);
|
StakeState::RewardsPool,
|
||||||
|
] {
|
||||||
|
let split_stake_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
|
let split_stake_account = AccountSharedData::new_ref_data_with_space(
|
||||||
|
0,
|
||||||
|
split_stake_state,
|
||||||
|
std::mem::size_of::<StakeState>(),
|
||||||
|
&id(),
|
||||||
|
)
|
||||||
|
.expect("split_stake_account");
|
||||||
|
|
||||||
|
let split_stake_keyed_account =
|
||||||
|
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_account);
|
||||||
|
assert_eq!(
|
||||||
|
stake_keyed_account.split(stake_lamports / 2, &split_stake_keyed_account, &signers),
|
||||||
|
Err(InstructionError::InvalidAccountData)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn just_stake(stake: u64) -> Stake {
|
fn just_stake(stake: u64) -> Stake {
|
||||||
Stake {
|
Stake {
|
||||||
|
|
Loading…
Reference in New Issue