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)
|
||||
);
|
||||
|
||||
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
|
||||
let signers = vec![stake_pubkey].into_iter().collect();
|
||||
assert_eq!(
|
||||
stake_keyed_account.split(stake_lamports / 2, &split_stake_keyed_account, &signers),
|
||||
Ok(())
|
||||
|
@ -3982,18 +4009,23 @@ mod tests {
|
|||
&id(),
|
||||
)
|
||||
.expect("stake_account");
|
||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
|
||||
let signers = vec![stake_pubkey].into_iter().collect();
|
||||
|
||||
for split_stake_state in &[
|
||||
StakeState::Initialized(Meta::default()),
|
||||
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,
|
||||
&StakeState::Initialized(Meta::auto(&stake_pubkey)),
|
||||
split_stake_state,
|
||||
std::mem::size_of::<StakeState>(),
|
||||
&id(),
|
||||
)
|
||||
.expect("stake_account");
|
||||
.expect("split_stake_account");
|
||||
|
||||
let signers = vec![stake_pubkey].into_iter().collect();
|
||||
let stake_keyed_account = KeyedAccount::new(&stake_pubkey, true, &stake_account);
|
||||
let split_stake_keyed_account =
|
||||
KeyedAccount::new(&split_stake_pubkey, true, &split_stake_account);
|
||||
assert_eq!(
|
||||
|
@ -4001,6 +4033,7 @@ mod tests {
|
|||
Err(InstructionError::InvalidAccountData)
|
||||
);
|
||||
}
|
||||
}
|
||||
fn just_stake(stake: u64) -> Stake {
|
||||
Stake {
|
||||
delegation: Delegation {
|
||||
|
|
Loading…
Reference in New Issue