Skip to content

Commit

Permalink
Fix tests that make assumptions about tx fee rate (#19538) (#19543)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4fb43bb)

Co-authored-by: Tyera Eulberg <[email protected]>
  • Loading branch information
mergify[bot] and CriesofCarrots authored Sep 1, 2021
1 parent 9a00585 commit 3606de5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9660,7 +9660,9 @@ pub(crate) mod tests {
assert_eq!(bank.process_transaction(&durable_tx), Ok(()));

/* Check balances */
assert_eq!(bank.get_balance(&custodian_pubkey), 4_640_000);
let mut expected_balance =
4_650_000 - bank.fee_calculator.calculate_fee(&durable_tx.message);
assert_eq!(bank.get_balance(&custodian_pubkey), expected_balance);
assert_eq!(bank.get_balance(&nonce_pubkey), 250_000);
assert_eq!(bank.get_balance(&alice_pubkey), 100_000);

Expand All @@ -9683,7 +9685,7 @@ pub(crate) mod tests {
Err(TransactionError::BlockhashNotFound)
);
/* Check fee not charged and nonce not advanced */
assert_eq!(bank.get_balance(&custodian_pubkey), 4_640_000);
assert_eq!(bank.get_balance(&custodian_pubkey), expected_balance);
assert_eq!(new_nonce, get_nonce_account(&bank, &nonce_pubkey).unwrap());

let nonce_hash = new_nonce;
Expand Down Expand Up @@ -9711,7 +9713,8 @@ pub(crate) mod tests {
))
);
/* Check fee charged and nonce has advanced */
assert_eq!(bank.get_balance(&custodian_pubkey), 4_630_000);
expected_balance -= bank.fee_calculator.calculate_fee(&durable_tx.message);
assert_eq!(bank.get_balance(&custodian_pubkey), expected_balance);
assert_ne!(nonce_hash, get_nonce_account(&bank, &nonce_pubkey).unwrap());
/* Confirm replaying a TX that failed with InstructionError::* now
* fails with TransactionError::BlockhashNotFound
Expand Down Expand Up @@ -9779,8 +9782,10 @@ pub(crate) mod tests {
#[test]
fn test_nonce_payer() {
solana_logger::setup();
let nonce_starting_balance = 250_000;
let (mut bank, _mint_keypair, custodian_keypair, nonce_keypair) =
setup_nonce_with_bank(10_000_000, |_| {}, 5_000_000, 250_000, None).unwrap();
setup_nonce_with_bank(10_000_000, |_| {}, 5_000_000, nonce_starting_balance, None)
.unwrap();
let alice_keypair = Keypair::new();
let alice_pubkey = alice_keypair.pubkey();
let custodian_pubkey = custodian_keypair.pubkey();
Expand Down Expand Up @@ -9816,7 +9821,10 @@ pub(crate) mod tests {
))
);
/* Check fee charged and nonce has advanced */
assert_eq!(bank.get_balance(&nonce_pubkey), 240_000);
assert_eq!(
bank.get_balance(&nonce_pubkey),
nonce_starting_balance - bank.fee_calculator.calculate_fee(&durable_tx.message)
);
assert_ne!(nonce_hash, get_nonce_account(&bank, &nonce_pubkey).unwrap());
}

Expand Down

0 comments on commit 3606de5

Please sign in to comment.