Skip to content

Commit aa52fa1

Browse files
authored
chore(spl): update changes in #124, #134 for spl-token specs (#135)
1 parent 3d1d9bd commit aa52fa1

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

program/src/entrypoint-runtime-verification.rs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,11 @@ fn inner_test_validate_owner(
248248

249249
if expected_owner != owner_account_info.key {
250250
assert_eq!(result, Err(ProgramError::Custom(4)));
251-
result
252-
} else if maybe_multisig_is_initialised.is_some()
251+
return result;
252+
}
253+
// We add the `maybe_multisig_is_initialised.is_some()` to not branch vacuously in the
254+
// non-multisig cases
255+
else if maybe_multisig_is_initialised.is_some()
253256
&& owner_account_info.data_len() == Multisig::LEN
254257
&& owner_account_info.owner == &id()
255258
{
@@ -287,13 +290,15 @@ fn inner_test_validate_owner(
287290
return result;
288291
}
289292

290-
result
291-
} else if !owner_account_info.is_signer {
293+
return Ok(());
294+
}
295+
// Non-multisig case - check if owner_account_info.is_signer
296+
else if !owner_account_info.is_signer {
292297
assert_eq!(result, Err(ProgramError::MissingRequiredSignature));
293-
result
294-
} else {
295-
result
298+
return result;
296299
}
300+
301+
Ok(())
297302
}
298303

299304
// TODO: Not sure if these are needed since there is no UB like p-token
@@ -3235,16 +3240,21 @@ fn test_process_close_account(
32353240
} else if accounts[1].key != &INCINERATOR_ID {
32363241
assert_eq!(result, Err(ProgramError::InvalidAccountData));
32373242
return result;
3238-
} else if dst_init_lamports.checked_add(src_init_lamports).is_none() {
3243+
}
3244+
if dst_init_lamports.checked_add(src_init_lamports).is_none() {
32393245
assert_eq!(result, Err(ProgramError::Custom(14)));
32403246
return result;
32413247
}
3248+
assert!(result.is_ok());
32423249

32433250
// Validate owner falls through to here if no error
3244-
assert_eq!(accounts[1].lamports(), dst_init_lamports + src_init_lamports);
32453251
assert_eq!(accounts[0].lamports(), 0);
3246-
assert_eq!(accounts[0].data_len(), 0); // TODO: More sol_memset stuff?
3247-
assert!(result.is_ok());
3252+
assert_eq!(
3253+
accounts[1].lamports(),
3254+
dst_init_lamports + src_init_lamports
3255+
);
3256+
#[cfg(any(target_os = "solana", target_arch = "bpf"))]
3257+
assert_eq!(accounts[0].data_len(), 0); // Solana-RT only
32483258
}
32493259

32503260
// Ensure instruction_data was not mutated
@@ -3805,9 +3815,6 @@ fn test_process_transfer_checked(
38053815
assert_eq!(result, Err(ProgramError::IncorrectProgramId));
38063816
return result;
38073817
}
3808-
3809-
assert!(result.is_ok());
3810-
38113818
if accounts[0].key != accounts[2].key && amount != 0 {
38123819
if get_account(&accounts[0]).is_native() && src_initial_lamports < amount {
38133820
// Not sure how to fund native mint
@@ -3829,6 +3836,7 @@ fn test_process_transfer_checked(
38293836
assert_eq!(accounts[1].lamports(), dst_initial_lamports + amount);
38303837
}
38313838
}
3839+
assert!(result.is_ok());
38323840

38333841
// Delegate updates
38343842
if old_src_delgate == Some(*accounts[3].key) && accounts[0].key != accounts[2].key {
@@ -4990,16 +4998,18 @@ fn test_process_withdraw_excess_lamports_account(
49904998
.checked_add(src_init_lamports - minimum_balance)
49914999
.is_none()
49925000
{
4993-
assert_eq!(result, Err(ProgramError::Custom(0)));
5001+
assert_eq!(result, Err(ProgramError::Custom(14)));
49945002
return result;
49955003
}
49965004

5005+
assert!(result.is_ok());
49975006
assert_eq!(accounts[0].lamports(), minimum_balance);
49985007
assert_eq!(
49995008
accounts[1].lamports(),
5000-
dst_init_lamports + (src_init_lamports - minimum_balance)
5009+
dst_init_lamports
5010+
.checked_add(src_init_lamports - minimum_balance)
5011+
.unwrap()
50015012
);
5002-
assert!(result.is_ok())
50035013
}
50045014
}
50055015

@@ -5168,26 +5178,27 @@ fn test_process_withdraw_excess_lamports_mint(
51685178
return result;
51695179
}
51705180

5171-
else if src_init_lamports < minimum_balance {
5181+
if src_init_lamports < minimum_balance {
51725182
assert_eq!(result, Err(ProgramError::Custom(0)));
51735183
return result;
51745184
} else if dst_init_lamports
51755185
.checked_add(src_init_lamports - minimum_balance)
51765186
.is_none()
51775187
{
5178-
assert_eq!(result, Err(ProgramError::Custom(0)));
5188+
assert_eq!(result, Err(ProgramError::Custom(14)));
51795189
return result;
51805190
}
51815191

5192+
assert!(result.is_ok());
51825193
assert_eq!(accounts[0].lamports(), minimum_balance);
51835194
assert_eq!(
51845195
accounts[1].lamports(),
5185-
dst_init_lamports + (src_init_lamports - minimum_balance)
5196+
dst_init_lamports
5197+
.checked_add(src_init_lamports - minimum_balance)
5198+
.unwrap()
51865199
);
5187-
assert!(result.is_ok())
51885200
}
51895201
}
5190-
51915202
// Ensure instruction_data was not mutated
51925203
assert_eq!(*instruction_data, instruction_data_with_discriminator[1..]);
51935204

0 commit comments

Comments
 (0)