system-program: Remove zero lamport check on transfers (#17726)

* system-program: Move lamports == 0 check on transfers

* Address feedback

* Update stake split to explicitly allocate + assign

* Update stake tests referring to split instruction

* Revert whitespace

* Update split instruction index in test

* Remove unnecessary `assign_with_seed` from `split_with_seed`

* Fix stake instruction parser

* Update test to allow splitting into account with lamports
This commit is contained in:
Jon Cinque
2021-06-06 01:45:45 +02:00
committed by GitHub
parent ae0bea1ad3
commit 8f5e773caf
6 changed files with 59 additions and 46 deletions

View File

@@ -261,13 +261,8 @@ pub fn split(
split_stake_pubkey: &Pubkey,
) -> Vec<Instruction> {
vec![
system_instruction::create_account(
authorized_pubkey, // Sending 0, so any signer will suffice
split_stake_pubkey,
0,
std::mem::size_of::<StakeState>() as u64,
&id(),
),
system_instruction::allocate(split_stake_pubkey, std::mem::size_of::<StakeState>() as u64),
system_instruction::assign(split_stake_pubkey, &id()),
_split(
stake_pubkey,
authorized_pubkey,
@@ -286,12 +281,10 @@ pub fn split_with_seed(
seed: &str, // seed
) -> Vec<Instruction> {
vec![
system_instruction::create_account_with_seed(
authorized_pubkey, // Sending 0, so any signer will suffice
system_instruction::allocate_with_seed(
split_stake_pubkey,
base,
seed,
0,
std::mem::size_of::<StakeState>() as u64,
&id(),
),
@@ -766,7 +759,7 @@ mod tests {
&Pubkey::default(),
100,
&invalid_stake_state_pubkey(),
)[1]
)[2]
),
Err(InstructionError::InvalidAccountData),
);
@@ -852,7 +845,7 @@ mod tests {
&Pubkey::default(),
100,
&Pubkey::default(),
)[1]
)[2]
),
Err(InstructionError::InvalidAccountOwner),
);
@@ -863,7 +856,7 @@ mod tests {
&Pubkey::default(),
100,
&spoofed_stake_state_pubkey(),
)[1]
)[2]
),
Err(InstructionError::IncorrectProgramId),
);