Uses checked math in EAH tests (#32483)
This commit is contained in:
parent
4bdd73a234
commit
1663a7091a
|
@ -1,4 +1,3 @@
|
|||
#![allow(clippy::integer_arithmetic)]
|
||||
use {
|
||||
crate::snapshot_utils::create_tmp_accounts_dir_for_tests,
|
||||
log::*,
|
||||
|
@ -90,13 +89,15 @@ impl TestEnvironment {
|
|||
|
||||
#[must_use]
|
||||
fn _new(snapshot_config: SnapshotConfig) -> TestEnvironment {
|
||||
const MINT_LAMPORTS: u64 = 100_000 * LAMPORTS_PER_SOL;
|
||||
const STAKE_LAMPORTS: u64 = 100 * LAMPORTS_PER_SOL;
|
||||
let bank_snapshots_dir = TempDir::new().unwrap();
|
||||
let full_snapshot_archives_dir = TempDir::new().unwrap();
|
||||
let incremental_snapshot_archives_dir = TempDir::new().unwrap();
|
||||
let mut genesis_config_info = genesis_utils::create_genesis_config_with_leader(
|
||||
100_000 * LAMPORTS_PER_SOL, // mint_lamports
|
||||
&Pubkey::new_unique(), // validator_pubkey
|
||||
100 * LAMPORTS_PER_SOL, // validator_stake_lamports
|
||||
MINT_LAMPORTS,
|
||||
&Pubkey::new_unique(),
|
||||
STAKE_LAMPORTS,
|
||||
);
|
||||
genesis_config_info.genesis_config.epoch_schedule =
|
||||
EpochSchedule::custom(Self::SLOTS_PER_EPOCH, Self::SLOTS_PER_EPOCH, false);
|
||||
|
@ -266,13 +267,13 @@ fn test_epoch_accounts_hash_basic(test_environment: TestEnvironment) {
|
|||
.genesis_config
|
||||
.epoch_schedule
|
||||
.slots_per_epoch;
|
||||
for _ in 0..slots_per_epoch * NUM_EPOCHS_TO_TEST {
|
||||
for _ in 0..slots_per_epoch.checked_mul(NUM_EPOCHS_TO_TEST).unwrap() {
|
||||
let bank = {
|
||||
let parent = bank_forks.read().unwrap().working_bank();
|
||||
let bank = bank_forks.write().unwrap().insert(Bank::new_from_parent(
|
||||
&parent,
|
||||
&Pubkey::default(),
|
||||
parent.slot() + 1,
|
||||
parent.slot().checked_add(1).unwrap(),
|
||||
));
|
||||
|
||||
let transaction = system_transaction::transfer(
|
||||
|
@ -289,7 +290,7 @@ fn test_epoch_accounts_hash_basic(test_environment: TestEnvironment) {
|
|||
trace!("new bank {}", bank.slot());
|
||||
|
||||
// Set roots so that ABS requests are sent (this is what requests EAH calculations)
|
||||
if bank.slot() % SET_ROOT_INTERVAL == 0 {
|
||||
if bank.slot().checked_rem(SET_ROOT_INTERVAL).unwrap() == 0 {
|
||||
trace!("rooting bank {}", bank.slot());
|
||||
bank_forks.write().unwrap().set_root(
|
||||
bank.slot(),
|
||||
|
@ -378,7 +379,7 @@ fn test_snapshots_have_expected_epoch_accounts_hash() {
|
|||
.genesis_config
|
||||
.epoch_schedule
|
||||
.slots_per_epoch;
|
||||
for _ in 0..slots_per_epoch * NUM_EPOCHS_TO_TEST {
|
||||
for _ in 0..slots_per_epoch.checked_mul(NUM_EPOCHS_TO_TEST).unwrap() {
|
||||
let bank = {
|
||||
let parent = bank_forks.read().unwrap().working_bank();
|
||||
let bank = bank_forks.write().unwrap().insert(Bank::new_from_parent(
|
||||
|
@ -494,7 +495,7 @@ fn test_background_services_request_handling_for_epoch_accounts_hash() {
|
|||
.genesis_config
|
||||
.epoch_schedule
|
||||
.slots_per_epoch;
|
||||
for _ in 0..slots_per_epoch * NUM_EPOCHS_TO_TEST {
|
||||
for _ in 0..slots_per_epoch.checked_mul(NUM_EPOCHS_TO_TEST).unwrap() {
|
||||
let bank = {
|
||||
let parent = bank_forks.read().unwrap().working_bank();
|
||||
let bank = bank_forks.write().unwrap().insert(Bank::new_from_parent(
|
||||
|
@ -656,6 +657,7 @@ fn test_epoch_accounts_hash_and_warping() {
|
|||
// https://github.com/rust-lang/rust/pull/88582
|
||||
// https://github.com/jhpratt/rust/blob/727a4fc7e3f836938dfeb4a2ab237cfca612222d/library/core/src/num/uint_macros.rs#L1811-L1837
|
||||
const fn next_multiple_of(lhs: u64, rhs: u64) -> u64 {
|
||||
#![allow(clippy::integer_arithmetic)]
|
||||
match lhs % rhs {
|
||||
0 => lhs,
|
||||
r => lhs + (rhs - r),
|
||||
|
|
Loading…
Reference in New Issue