From bc5f434e48cd4c5781be8a0d1c6f1f70be577cbe Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 18 Feb 2021 02:54:13 +0000 Subject: [PATCH] Add lamports overflow test for nonce withdraw (#15383) (#15385) (cherry picked from commit fcee22702161e3c315ad33e8070aa3fbf93ef74d) Co-authored-by: Tyera Eulberg --- sdk/src/nonce_keyed_account.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/sdk/src/nonce_keyed_account.rs b/sdk/src/nonce_keyed_account.rs index c271bbd8d8..08f702fa1c 100644 --- a/sdk/src/nonce_keyed_account.rs +++ b/sdk/src/nonce_keyed_account.rs @@ -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 {