Add lamports overflow test for nonce withdraw (#15383)

This commit is contained in:
Tyera Eulberg 2021-02-17 18:37:13 -07:00 committed by GitHub
parent 170cb792eb
commit fcee227021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 0 deletions

View File

@ -732,6 +732,36 @@ mod test {
})
}
#[test]
fn withdraw_inx_overflow() {
let rent = Rent {
lamports_per_byte_year: 42,
..Rent::default()
};
let min_lamports = rent.minimum_balance(State::size());
with_test_keyed_account(min_lamports + 42, true, |nonce_keyed| {
let recent_blockhashes = create_test_recent_blockhashes(95);
let authorized = *nonce_keyed.unsigned_key();
nonce_keyed
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
.unwrap();
with_test_keyed_account(55, false, |to_keyed| {
let recent_blockhashes = create_test_recent_blockhashes(63);
let mut signers = HashSet::new();
signers.insert(*nonce_keyed.signer_key().unwrap());
let withdraw_lamports = u64::MAX - 54;
let result = nonce_keyed.withdraw_nonce_account(
withdraw_lamports,
&to_keyed,
&recent_blockhashes,
&rent,
&signers,
);
assert_eq!(result, Err(InstructionError::InsufficientFunds));
})
})
}
#[test]
fn initialize_inx_ok() {
let rent = Rent {