Use MAX associated const (#9196)

* Use MAX associated const
This commit is contained in:
Squirrel
2021-06-24 11:53:49 +01:00
committed by GitHub
parent 09d9c2c9f6
commit ea1f21a904
56 changed files with 178 additions and 178 deletions
+1 -1
View File
@@ -307,7 +307,7 @@ mod multiplier_tests {
fn weight_to_fee_should_not_overflow_on_large_weights() {
let kb = 1024 as Weight;
let mb = kb * kb;
let max_fm = Multiplier::saturating_from_integer(i128::max_value());
let max_fm = Multiplier::saturating_from_integer(i128::MAX);
// check that for all values it can compute, correctly.
vec![
+1 -1
View File
@@ -97,7 +97,7 @@ fn slot_author<P: Pair>(slot: Slot, authorities: &[AuthorityId<P>]) -> Option<&A
let idx = *slot % (authorities.len() as u64);
assert!(
idx <= usize::max_value() as u64,
idx <= usize::MAX as u64,
"It is impossible to have a vector with length beyond the address space; qed",
);
@@ -1468,7 +1468,7 @@ impl<Block: BlockT> GossipValidator<Block> {
"" => "",
);
let len = std::cmp::min(i32::max_value() as usize, data.len()) as i32;
let len = std::cmp::min(i32::MAX as usize, data.len()) as i32;
Action::Discard(Misbehavior::UndecodablePacket(len).cost())
}
}
+1 -1
View File
@@ -179,7 +179,7 @@ fn speed<B: BlockT>(
// algebraic approach and we stay within the realm of integers.
let one_thousand = NumberFor::<B>::from(1_000u32);
let elapsed = NumberFor::<B>::from(
<u32 as TryFrom<_>>::try_from(elapsed_ms).unwrap_or(u32::max_value())
<u32 as TryFrom<_>>::try_from(elapsed_ms).unwrap_or(u32::MAX)
);
let speed = diff.saturating_mul(one_thousand).checked_div(&elapsed)
@@ -159,7 +159,7 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
}
let mut codec = UviBytes::default();
codec.set_max_len(usize::try_from(self.max_notification_size).unwrap_or(usize::max_value()));
codec.set_max_len(usize::try_from(self.max_notification_size).unwrap_or(usize::MAX));
let substream = NotificationsInSubstream {
socket: Framed::new(socket, codec),
@@ -390,7 +390,7 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
}
let mut codec = UviBytes::default();
codec.set_max_len(usize::try_from(self.max_notification_size).unwrap_or(usize::max_value()));
codec.set_max_len(usize::try_from(self.max_notification_size).unwrap_or(usize::MAX));
Ok(NotificationsOutOpen {
handshake,
@@ -809,7 +809,7 @@ impl RequestResponseCodec for GenericCodec {
// Read the length.
let length = unsigned_varint::aio::read_usize(&mut io).await
.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?;
if length > usize::try_from(self.max_request_size).unwrap_or(usize::max_value()) {
if length > usize::try_from(self.max_request_size).unwrap_or(usize::MAX) {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("Request size exceeds limit: {} > {}", length, self.max_request_size)
@@ -846,7 +846,7 @@ impl RequestResponseCodec for GenericCodec {
Err(err) => return Err(io::Error::new(io::ErrorKind::InvalidInput, err)),
};
if length > usize::try_from(self.max_response_size).unwrap_or(usize::max_value()) {
if length > usize::try_from(self.max_response_size).unwrap_or(usize::MAX) {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("Response size exceeds limit: {} > {}", length, self.max_response_size)
+4 -4
View File
@@ -300,20 +300,20 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
let yamux_maximum_buffer_size = {
let requests_max = params.network_config
.request_response_protocols.iter()
.map(|cfg| usize::try_from(cfg.max_request_size).unwrap_or(usize::max_value()));
.map(|cfg| usize::try_from(cfg.max_request_size).unwrap_or(usize::MAX));
let responses_max = params.network_config
.request_response_protocols.iter()
.map(|cfg| usize::try_from(cfg.max_response_size).unwrap_or(usize::max_value()));
.map(|cfg| usize::try_from(cfg.max_response_size).unwrap_or(usize::MAX));
let notifs_max = params.network_config
.extra_sets.iter()
.map(|cfg| usize::try_from(cfg.max_notification_size).unwrap_or(usize::max_value()));
.map(|cfg| usize::try_from(cfg.max_notification_size).unwrap_or(usize::MAX));
// A "default" max is added to cover all the other protocols: ping, identify,
// kademlia, block announces, and transactions.
let default_max = cmp::max(
1024 * 1024,
usize::try_from(protocol::BLOCK_ANNOUNCES_TRANSACTIONS_SUBSTREAM_SIZE)
.unwrap_or(usize::max_value())
.unwrap_or(usize::MAX)
);
iter::once(default_max)
@@ -254,7 +254,7 @@ impl Metrics {
.inc_by(num);
self.notifications_sizes
.with_label_values(&[protocol, "sent", name])
.inc_by(num.saturating_mul(u64::try_from(message.len()).unwrap_or(u64::max_value())));
.inc_by(num.saturating_mul(u64::try_from(message.len()).unwrap_or(u64::MAX)));
}
},
}
@@ -294,7 +294,7 @@ impl Metrics {
.inc();
self.notifications_sizes
.with_label_values(&[&protocol, "received", name])
.inc_by(u64::try_from(message.len()).unwrap_or(u64::max_value()));
.inc_by(u64::try_from(message.len()).unwrap_or(u64::MAX));
}
},
}
@@ -345,7 +345,7 @@ fn lots_of_incoming_peers_works() {
fallback_names: Vec::new(),
max_notification_size: 1024 * 1024,
set_config: config::SetConfig {
in_peers: u32::max_value(),
in_peers: u32::MAX,
.. Default::default()
},
}
+2 -2
View File
@@ -97,8 +97,8 @@ struct Node {
/// are indices into this `Vec`.
sets: Vec<MembershipState>,
/// Reputation value of the node, between `i32::min_value` (we hate that node) and
/// `i32::max_value` (we love that node).
/// Reputation value of the node, between `i32::MIN` (we hate that node) and
/// `i32::MAX` (we love that node).
reputation: i32,
}
+1 -1
View File
@@ -120,7 +120,7 @@ fn test_once() {
// If we generate 2, adjust a random reputation.
2 => {
if let Some(id) = known_nodes.iter().choose(&mut rng) {
let val = Uniform::new_inclusive(i32::min_value(), i32::max_value())
let val = Uniform::new_inclusive(i32::min_value(), i32::MAX)
.sample(&mut rng);
peerset_handle.report_peer(id.clone(), ReputationChange::new(val, ""));
}
+1 -1
View File
@@ -84,7 +84,7 @@ trait ChainBackend<Client, Block: BlockT>: Send + Sync + 'static
// FIXME <2329>: Database seems to limit the block number to u32 for no reason
let block_num: u32 = num_or_hex.try_into().map_err(|_| {
Error::from(format!(
"`{:?}` > u32::max_value(), the max block number is u32.",
"`{:?}` > u32::MAX, the max block number is u32.",
num_or_hex
))
})?;
@@ -236,7 +236,7 @@ impl<B: BlockT> Speedometer<B> {
// algebraic approach and we stay within the realm of integers.
let one_thousand = NumberFor::<B>::from(1_000u32);
let elapsed = NumberFor::<B>::from(
<u32 as TryFrom<_>>::try_from(elapsed_ms).unwrap_or(u32::max_value())
<u32 as TryFrom<_>>::try_from(elapsed_ms).unwrap_or(u32::MAX)
);
let speed = diff.saturating_mul(one_thousand).checked_div(&elapsed)
@@ -1547,7 +1547,7 @@ fn doesnt_import_blocks_that_revert_finality() {
cache_size: 1024,
},
},
u64::max_value(),
u64::MAX,
).unwrap());
let mut client = TestClientBuilder::with_backend(backend).build();
@@ -1751,7 +1751,7 @@ fn returns_status_for_pruned_blocks() {
cache_size: 1024,
},
},
u64::max_value(),
u64::MAX,
).unwrap());
let mut client = TestClientBuilder::with_backend(backend).build();
@@ -659,7 +659,7 @@ mod tests {
bytes: 1,
hash: 5,
priority: 1,
valid_till: u64::max_value(), // use the max_value() here for testing.
valid_till: u64::MAX, // use the max here for testing.
requires: vec![tx1.provides[0].clone()],
provides: vec![],
propagate: true,
@@ -692,7 +692,7 @@ mod tests {
bytes: 1,
hash: 5,
priority: 1,
valid_till: u64::max_value(), // use the max_value() here for testing.
valid_till: u64::MAX, // use the max here for testing.
requires: vec![],
provides: vec![],
propagate: true,
+4 -4
View File
@@ -310,7 +310,7 @@ fn querying_total_supply_should_work() {
assert_eq!(Assets::balance(0, 1), 50);
assert_eq!(Assets::balance(0, 2), 19);
assert_eq!(Assets::balance(0, 3), 31);
assert_ok!(Assets::burn(Origin::signed(1), 0, 3, u64::max_value()));
assert_ok!(Assets::burn(Origin::signed(1), 0, 3, u64::MAX));
assert_eq!(Assets::total_supply(0), 69);
});
}
@@ -457,7 +457,7 @@ fn transferring_amount_more_than_available_balance_should_not_work() {
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 50));
assert_eq!(Assets::balance(0, 1), 50);
assert_eq!(Assets::balance(0, 2), 50);
assert_ok!(Assets::burn(Origin::signed(1), 0, 1, u64::max_value()));
assert_ok!(Assets::burn(Origin::signed(1), 0, 1, u64::MAX));
assert_eq!(Assets::balance(0, 1), 0);
assert_noop!(Assets::transfer(Origin::signed(1), 0, 1, 50), Error::<Test>::BalanceLow);
assert_noop!(Assets::transfer(Origin::signed(2), 0, 1, 51), Error::<Test>::BalanceLow);
@@ -491,7 +491,7 @@ fn burning_asset_balance_with_positive_balance_should_work() {
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
assert_eq!(Assets::balance(0, 1), 100);
assert_ok!(Assets::burn(Origin::signed(1), 0, 1, u64::max_value()));
assert_ok!(Assets::burn(Origin::signed(1), 0, 1, u64::MAX));
assert_eq!(Assets::balance(0, 1), 0);
});
}
@@ -502,7 +502,7 @@ fn burning_asset_balance_with_zero_balance_does_nothing() {
assert_ok!(Assets::force_create(Origin::root(), 0, 1, true, 1));
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
assert_eq!(Assets::balance(0, 2), 0);
assert_ok!(Assets::burn(Origin::signed(1), 0, 2, u64::max_value()));
assert_ok!(Assets::burn(Origin::signed(1), 0, 2, u64::MAX));
assert_eq!(Assets::balance(0, 2), 0);
assert_eq!(Assets::total_supply(0), 100);
});
+1 -1
View File
@@ -184,7 +184,7 @@ parameter_types! {
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 64;
pub const ElectionLookahead: u64 = 0;
pub const StakingUnsignedPriority: u64 = u64::max_value() / 2;
pub const StakingUnsignedPriority: u64 = u64::MAX / 2;
}
impl onchain::Config for Test {
+6 -6
View File
@@ -87,7 +87,7 @@ macro_rules! decl_tests {
#[test]
fn lock_removal_should_work() {
<$ext_builder>::default().existential_deposit(1).monied(true).build().execute_with(|| {
Balances::set_lock(ID_1, &1, u64::max_value(), WithdrawReasons::all());
Balances::set_lock(ID_1, &1, u64::MAX, WithdrawReasons::all());
Balances::remove_lock(ID_1, &1);
assert_ok!(<Balances as Currency<_>>::transfer(&1, &2, 1, AllowDeath));
});
@@ -96,7 +96,7 @@ macro_rules! decl_tests {
#[test]
fn lock_replacement_should_work() {
<$ext_builder>::default().existential_deposit(1).monied(true).build().execute_with(|| {
Balances::set_lock(ID_1, &1, u64::max_value(), WithdrawReasons::all());
Balances::set_lock(ID_1, &1, u64::MAX, WithdrawReasons::all());
Balances::set_lock(ID_1, &1, 5, WithdrawReasons::all());
assert_ok!(<Balances as Currency<_>>::transfer(&1, &2, 1, AllowDeath));
});
@@ -114,7 +114,7 @@ macro_rules! decl_tests {
#[test]
fn combination_locking_should_work() {
<$ext_builder>::default().existential_deposit(1).monied(true).build().execute_with(|| {
Balances::set_lock(ID_1, &1, u64::max_value(), WithdrawReasons::empty());
Balances::set_lock(ID_1, &1, u64::MAX, WithdrawReasons::empty());
Balances::set_lock(ID_2, &1, 0, WithdrawReasons::all());
assert_ok!(<Balances as Currency<_>>::transfer(&1, &2, 1, AllowDeath));
});
@@ -513,15 +513,15 @@ macro_rules! decl_tests {
#[test]
fn transferring_too_high_value_should_not_panic() {
<$ext_builder>::default().build().execute_with(|| {
Balances::make_free_balance_be(&1, u64::max_value());
Balances::make_free_balance_be(&1, u64::MAX);
Balances::make_free_balance_be(&2, 1);
assert_err!(
Balances::transfer(Some(1).into(), 2, u64::max_value()),
Balances::transfer(Some(1).into(), 2, u64::MAX),
ArithmeticError::Overflow,
);
assert_eq!(Balances::free_balance(1), u64::max_value());
assert_eq!(Balances::free_balance(1), u64::MAX);
assert_eq!(Balances::free_balance(2), 1);
});
}
@@ -116,7 +116,7 @@ where
// storage_size cannot be zero because otherwise a contract that is just above
// the subsistence threshold does not pay rent given a large enough subsistence
// threshold. But we need rent payments to occur in order to benchmark for worst cases.
let storage_size = u32::max_value() / 10;
let storage_size = u32::MAX / 10;
// Endowment should be large but not as large to inhibit rent payments.
// Balance will only cover half the storage
@@ -334,7 +334,7 @@ where
///
/// If the contract supplied buffer is smaller than the passed `buffer` an `Err` is returned.
/// If `allow_skip` is set to true the contract is allowed to skip the copying of the buffer
/// by supplying the guard value of `u32::max_value()` as `out_ptr`. The
/// by supplying the guard value of `u32::MAX` as `out_ptr`. The
/// `weight_per_byte` is only charged when the write actually happens and is not skipped or
/// failed due to a too small output buffer.
pub fn write(
@@ -550,7 +550,7 @@ where
/// length of the buffer located at `out_ptr`. If that buffer is large enough the actual
/// `buf.len()` is written to this location.
///
/// If `out_ptr` is set to the sentinel value of `u32::max_value()` and `allow_skip` is true the
/// If `out_ptr` is set to the sentinel value of `u32::MAX` and `allow_skip` is true the
/// operation is skipped and `Ok` is returned. This is supposed to help callers to make copying
/// output optional. For example to skip copying back the output buffer of an `seal_call`
/// when the caller is not interested in the result.
@@ -570,7 +570,7 @@ where
create_token: impl FnOnce(u32) -> Option<RuntimeCosts>,
) -> Result<(), DispatchError>
{
if allow_skip && out_ptr == u32::max_value() {
if allow_skip && out_ptr == u32::MAX {
return Ok(());
}
@@ -892,7 +892,7 @@ define_env!(Env, <E: Ext>,
//
// The callees output buffer is copied to `output_ptr` and its length to `output_len_ptr`.
// The copy of the output buffer can be skipped by supplying the sentinel value
// of `u32::max_value()` to `output_ptr`.
// of `u32::MAX` to `output_ptr`.
//
// # Parameters
//
@@ -953,7 +953,7 @@ define_env!(Env, <E: Ext>,
// by the code hash. The address of this new account is copied to `address_ptr` and its length
// to `address_len_ptr`. The constructors output buffer is copied to `output_ptr` and its
// length to `output_len_ptr`. The copy of the output buffer and address can be skipped by
// supplying the sentinel value of `u32::max_value()` to `output_ptr` or `address_ptr`.
// supplying the sentinel value of `u32::MAX` to `output_ptr` or `address_ptr`.
//
// After running the constructor it is verified that the contract account holds at
// least the subsistence threshold. If that is not the case the instantiation fails and
@@ -118,13 +118,13 @@ benchmarks! {
// Create s existing "seconds"
for i in 0 .. s {
let seconder = funded_account::<T>("seconder", i);
Democracy::<T>::second(RawOrigin::Signed(seconder).into(), 0, u32::max_value())?;
Democracy::<T>::second(RawOrigin::Signed(seconder).into(), 0, u32::MAX)?;
}
let deposits = Democracy::<T>::deposit_of(0).ok_or("Proposal not created")?;
assert_eq!(deposits.0.len(), (s + 1) as usize, "Seconds not recorded");
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller), 0, u32::max_value())
}: _(RawOrigin::Signed(caller), 0, u32::MAX)
verify {
let deposits = Democracy::<T>::deposit_of(0).ok_or("Proposal not created")?;
assert_eq!(deposits.0.len(), (s + 2) as usize, "`second` benchmark did not work");
@@ -609,7 +609,7 @@ benchmarks! {
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller), proposal_hash.clone(), u32::max_value())
}: _(RawOrigin::Signed(caller), proposal_hash.clone(), u32::MAX)
verify {
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
assert!(!Preimages::<T>::contains_key(proposal_hash));
@@ -23,11 +23,11 @@ use frame_support::storage::{migration, unhashed};
#[test]
fn test_decode_compact_u32_at() {
new_test_ext().execute_with(|| {
let v = codec::Compact(u64::max_value());
let v = codec::Compact(u64::MAX);
migration::put_storage_value(b"test", b"", &[], v);
assert_eq!(decode_compact_u32_at(b"test"), None);
for v in vec![0, 10, u32::max_value()] {
for v in vec![0, 10, u32::MAX] {
let compact_v = codec::Compact(v);
unhashed::put(b"test", &compact_v);
assert_eq!(decode_compact_u32_at(b"test"), Some(v));
@@ -81,11 +81,11 @@ fn preimage_deposit_should_be_reapable_earlier_by_owner() {
next_block();
assert_noop!(
Democracy::reap_preimage(Origin::signed(6), set_balance_proposal_hash(2), u32::max_value()),
Democracy::reap_preimage(Origin::signed(6), set_balance_proposal_hash(2), u32::MAX),
Error::<Test>::TooEarly
);
next_block();
assert_ok!(Democracy::reap_preimage(Origin::signed(6), set_balance_proposal_hash(2), u32::max_value()));
assert_ok!(Democracy::reap_preimage(Origin::signed(6), set_balance_proposal_hash(2), u32::MAX));
assert_eq!(Balances::free_balance(6), 60);
assert_eq!(Balances::reserved_balance(6), 0);
@@ -96,7 +96,7 @@ fn preimage_deposit_should_be_reapable_earlier_by_owner() {
fn preimage_deposit_should_be_reapable() {
new_test_ext_execute_with_cond(|operational| {
assert_noop!(
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::max_value()),
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::MAX),
Error::<Test>::PreimageMissing
);
@@ -111,12 +111,12 @@ fn preimage_deposit_should_be_reapable() {
next_block();
next_block();
assert_noop!(
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::max_value()),
Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::MAX),
Error::<Test>::TooEarly
);
next_block();
assert_ok!(Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::max_value()));
assert_ok!(Democracy::reap_preimage(Origin::signed(5), set_balance_proposal_hash(2), u32::MAX));
assert_eq!(Balances::reserved_balance(6), 0);
assert_eq!(Balances::free_balance(6), 48);
assert_eq!(Balances::free_balance(5), 62);
@@ -161,7 +161,7 @@ fn reaping_imminent_preimage_should_fail() {
assert_ok!(Democracy::vote(Origin::signed(1), r, aye(1)));
next_block();
next_block();
assert_noop!(Democracy::reap_preimage(Origin::signed(6), h, u32::max_value()), Error::<Test>::Imminent);
assert_noop!(Democracy::reap_preimage(Origin::signed(6), h, u32::MAX), Error::<Test>::Imminent);
});
}
@@ -35,10 +35,10 @@ fn backing_for_should_work() {
fn deposit_for_proposals_should_be_taken() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance_and_note(1, 2, 5));
assert_ok!(Democracy::second(Origin::signed(2), 0, u32::max_value()));
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::max_value()));
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::max_value()));
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::max_value()));
assert_ok!(Democracy::second(Origin::signed(2), 0, u32::MAX));
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::MAX));
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::MAX));
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::MAX));
assert_eq!(Balances::free_balance(1), 5);
assert_eq!(Balances::free_balance(2), 15);
assert_eq!(Balances::free_balance(5), 35);
@@ -49,10 +49,10 @@ fn deposit_for_proposals_should_be_taken() {
fn deposit_for_proposals_should_be_returned() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance_and_note(1, 2, 5));
assert_ok!(Democracy::second(Origin::signed(2), 0, u32::max_value()));
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::max_value()));
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::max_value()));
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::max_value()));
assert_ok!(Democracy::second(Origin::signed(2), 0, u32::MAX));
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::MAX));
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::MAX));
assert_ok!(Democracy::second(Origin::signed(5), 0, u32::MAX));
fast_forward_to(3);
assert_eq!(Balances::free_balance(1), 10);
assert_eq!(Balances::free_balance(2), 20);
@@ -79,7 +79,7 @@ fn poor_seconder_should_not_work() {
new_test_ext().execute_with(|| {
assert_ok!(propose_set_balance_and_note(2, 2, 11));
assert_noop!(
Democracy::second(Origin::signed(1), 0, u32::max_value()),
Democracy::second(Origin::signed(1), 0, u32::MAX),
BalancesError::<Test, _>::InsufficientBalance
);
});
+1 -1
View File
@@ -166,7 +166,7 @@ fn signed_ext_watch_dummy_works() {
WatchDummy::<Test>(PhantomData).validate(&1, &call, &info, 150)
.unwrap()
.priority,
u64::max_value(),
u64::MAX,
);
assert_eq!(
WatchDummy::<Test>(PhantomData).validate(&1, &call, &info, 250),
+1 -1
View File
@@ -190,7 +190,7 @@ parameter_types! {
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 64;
pub const ElectionLookahead: u64 = 0;
pub const StakingUnsignedPriority: u64 = u64::max_value() / 2;
pub const StakingUnsignedPriority: u64 = u64::MAX / 2;
}
impl onchain::Config for Test {
@@ -275,7 +275,7 @@ impl INPoS {
// See web3 docs for the details
fn compute_opposite_after_x_ideal(&self, y: u32) -> u32 {
if y == self.i_0 {
return u32::max_value();
return u32::MAX;
}
// Note: the log term calculated here represents a per_million value
let log = log2(self.i_ideal_times_x_ideal - self.i_0, y - self.i_0);
@@ -408,7 +408,7 @@ fn generate_test_module(input: &INposInput) -> TokenStream2 {
#[test]
fn reward_curve_precision() {
for &base in [MILLION, u32::max_value()].iter() {
for &base in [MILLION, u32::MAX].iter() {
let number_of_check = 100_000.min(base);
for check_index in 0..=number_of_check {
let i = (check_index as u64 * base as u64 / number_of_check as u64) as u32;
@@ -33,7 +33,7 @@ fn taylor_term(k: u32, y_num: u128, y_den: u128) -> u32 {
/// * result represents a per-million output of log2
pub fn log2(p: u32, q: u32) -> u32 {
assert!(p >= q); // keep p/q bound to [1, inf)
assert!(p <= u32::max_value()/2);
assert!(p <= u32::MAX/2);
// This restriction should not be mandatory. But function is only tested and used for this.
assert!(p <= 1_000_000);
+7 -7
View File
@@ -79,9 +79,9 @@ pub fn create_validator_with_nominators<T: Config>(
// Give the validator n nominators, but keep total users in the system the same.
for i in 0 .. upper_bound {
let (n_stash, n_controller) = if !dead {
create_stash_controller::<T>(u32::max_value() - i, 100, destination.clone())?
create_stash_controller::<T>(u32::MAX - i, 100, destination.clone())?
} else {
create_stash_and_dead_controller::<T>(u32::max_value() - i, 100, destination.clone())?
create_stash_and_dead_controller::<T>(u32::MAX - i, 100, destination.clone())?
};
if i < n {
Staking::<T>::nominate(RawOrigin::Signed(n_controller.clone()).into(), vec![stash_lookup.clone()])?;
@@ -456,7 +456,7 @@ benchmarks! {
<ErasTotalStake<T>>::insert(i, BalanceOf::<T>::one());
ErasStartSessionIndex::<T>::insert(i, i);
}
}: _(RawOrigin::Root, EraIndex::zero(), u32::max_value())
}: _(RawOrigin::Root, EraIndex::zero(), u32::MAX)
verify {
assert_eq!(HistoryDepth::<T>::get(), 0);
}
@@ -607,13 +607,13 @@ benchmarks! {
RawOrigin::Root,
BalanceOf::<T>::max_value(),
BalanceOf::<T>::max_value(),
Some(u32::max_value()),
Some(u32::max_value())
Some(u32::MAX),
Some(u32::MAX)
) verify {
assert_eq!(MinNominatorBond::<T>::get(), BalanceOf::<T>::max_value());
assert_eq!(MinValidatorBond::<T>::get(), BalanceOf::<T>::max_value());
assert_eq!(MaxNominatorsCount::<T>::get(), Some(u32::max_value()));
assert_eq!(MaxValidatorsCount::<T>::get(), Some(u32::max_value()));
assert_eq!(MaxNominatorsCount::<T>::get(), Some(u32::MAX));
assert_eq!(MaxValidatorsCount::<T>::get(), Some(u32::MAX));
}
chill_other {
+1 -1
View File
@@ -150,7 +150,7 @@ pub fn create_validators_with_nominators_for_era<T: Config>(
for j in 0 .. nominators {
let balance_factor = if randomize_stake { rng.next_u32() % 255 + 10 } else { 100u32 };
let (_n_stash, n_controller) = create_stash_controller::<T>(
u32::max_value() - j,
u32::MAX - j,
balance_factor,
RewardDestination::Staked,
)?;
+3 -3
View File
@@ -1960,8 +1960,8 @@ fn phragmen_should_not_overflow() {
#[test]
fn reward_validator_slashing_validator_does_not_overflow() {
ExtBuilder::default().build_and_execute(|| {
let stake = u64::max_value() as Balance * 2;
let reward_slash = u64::max_value() as Balance * 2;
let stake = u64::MAX as Balance * 2;
let reward_slash = u64::MAX as Balance * 2;
// Assert multiplication overflows in balance arithmetic.
assert!(stake.checked_mul(reward_slash).is_none());
@@ -3995,7 +3995,7 @@ mod election_data_provider {
);
Staking::force_no_eras(Origin::root()).unwrap();
assert_eq!(Staking::next_election_prediction(System::block_number()), u64::max_value());
assert_eq!(Staking::next_election_prediction(System::block_number()), u64::MAX);
Staking::force_new_era_always(Origin::root()).unwrap();
assert_eq!(Staking::next_election_prediction(System::block_number()), 45 + 5);
+4 -4
View File
@@ -42,20 +42,20 @@ pub trait CurrencyToVote<B> {
/// An implementation of `CurrencyToVote` tailored for chain's that have a balance type of u128.
///
/// The factor is the `(total_issuance / u64::max()).max(1)`, represented as u64. Let's look at the
/// The factor is the `(total_issuance / u64::MAX).max(1)`, represented as u64. Let's look at the
/// important cases:
///
/// If the chain's total issuance is less than u64::max(), this will always be 1, which means that
/// If the chain's total issuance is less than u64::MAX, this will always be 1, which means that
/// the factor will not have any effect. In this case, any account's balance is also less. Thus,
/// both of the conversions are basically an `as`; Any balance can fit in u64.
///
/// If the chain's total issuance is more than 2*u64::max(), then a factor might be multiplied and
/// If the chain's total issuance is more than 2*u64::MAX, then a factor might be multiplied and
/// divided upon conversion.
pub struct U128CurrencyToVote;
impl U128CurrencyToVote {
fn factor(issuance: u128) -> u128 {
(issuance / u64::max_value() as u128).max(1)
(issuance / u64::MAX as u128).max(1)
}
}
+1 -1
View File
@@ -278,7 +278,7 @@ impl<'a> OneOrMany<DispatchClass> for &'a [DispatchClass] {
/// Primitives related to priority management of Frame.
pub mod priority {
/// The starting point of all Operational transactions. 3/4 of u64::max_value().
/// The starting point of all Operational transactions. 3/4 of u64::MAX.
pub const LIMIT: u64 = 13_835_058_055_282_163_711_u64;
/// Wrapper for priority of different dispatch classes.
@@ -43,7 +43,7 @@ frame_support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event() = default;
type Error = Error<T>;
const Foo: u32 = u32::max_value();
const Foo: u32 = u32::MAX;
#[weight = 0]
fn accumulate_dummy(_origin, _increase_by: T::Balance) {
+1 -1
View File
@@ -778,7 +778,7 @@ fn hash69<T: AsMut<[u8]> + Default>() -> T {
/// This type alias represents an index of an event.
///
/// We use `u32` here because this index is used as index for `Events<T>`
/// which can't contain more than `u32::max_value()` items.
/// which can't contain more than `u32::MAX` items.
type EventIndex = u32;
/// Type used to encode the number of references an account has.
@@ -1142,11 +1142,11 @@ mod tests {
};
assert_eq!(
Module::<Runtime>::compute_fee(
<u32>::max_value(),
u32::MAX,
&dispatch_info,
<u64>::max_value()
u64::MAX
),
<u64>::max_value()
u64::MAX
);
});
}
+2 -2
View File
@@ -367,8 +367,8 @@ fn genesis_funding_works() {
#[test]
fn max_approvals_limited() {
new_test_ext().execute_with(|| {
Balances::make_free_balance_be(&Treasury::account_id(), u64::max_value());
Balances::make_free_balance_be(&0, u64::max_value());
Balances::make_free_balance_be(&Treasury::account_id(), u64::MAX);
Balances::make_free_balance_be(&0, u64::MAX);
for _ in 0 .. MaxApprovals::get() {
assert_ok!(Treasury::propose_spend(Origin::signed(0), 100, 3));
@@ -179,7 +179,7 @@ impl Order {
}
/// A special magic value for a pointer in a link that denotes the end of the linked list.
const NIL_MARKER: u32 = u32::max_value();
const NIL_MARKER: u32 = u32::MAX;
/// A link between headers in the free list.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -70,7 +70,7 @@ fn mul_div(a: u128, b: u128, c: u128) -> u128 {
let ce: U256 = c.into();
let r = ae * be / ce;
if r > u128::max_value().into() {
if r > u128::MAX.into() {
a
} else {
r.as_u128()
@@ -342,7 +342,7 @@ impl BigUint {
// step D3.0 Find an estimate of q[j], named qhat.
let (qhat, rhat) = {
// PROOF: this always fits into `Double`. In the context of Single = u8, and
// Double = u16, think of 255 * 256 + 255 which is just u16::max_value().
// Double = u16, think of 255 * 256 + 255 which is just u16::MAX.
let dividend =
Double::from(self_norm.get(j + n))
* B
@@ -668,14 +668,14 @@ pub mod tests {
fn can_try_build_numbers_from_types() {
use sp_std::convert::TryFrom;
assert_eq!(u64::try_from(with_limbs(1)).unwrap(), 1);
assert_eq!(u64::try_from(with_limbs(2)).unwrap(), u32::max_value() as u64 + 2);
assert_eq!(u64::try_from(with_limbs(2)).unwrap(), u32::MAX as u64 + 2);
assert_eq!(
u64::try_from(with_limbs(3)).unwrap_err(),
"cannot fit a number into u64",
);
assert_eq!(
u128::try_from(with_limbs(3)).unwrap(),
u32::max_value() as u128 + u64::max_value() as u128 + 3
u32::MAX as u128 + u64::MAX as u128 + 3
);
}
@@ -619,23 +619,23 @@ macro_rules! implement_fixed {
assert_eq!(from_i129::<u128>(a), None);
let a = I129 {
value: u128::max_value() - 1,
value: u128::MAX - 1,
negative: false,
};
// Max - 1 value fits.
assert_eq!(from_i129::<u128>(a), Some(u128::max_value() - 1));
assert_eq!(from_i129::<u128>(a), Some(u128::MAX - 1));
let a = I129 {
value: u128::max_value(),
value: u128::MAX,
negative: false,
};
// Max value fits.
assert_eq!(from_i129::<u128>(a), Some(u128::max_value()));
assert_eq!(from_i129::<u128>(a), Some(u128::MAX));
let a = I129 {
value: i128::max_value() as u128 + 1,
value: i128::MAX as u128 + 1,
negative: true,
};
@@ -643,7 +643,7 @@ macro_rules! implement_fixed {
assert_eq!(from_i129::<i128>(a), Some(i128::min_value()));
let a = I129 {
value: i128::max_value() as u128 + 1,
value: i128::MAX as u128 + 1,
negative: false,
};
@@ -651,12 +651,12 @@ macro_rules! implement_fixed {
assert_eq!(from_i129::<i128>(a), None);
let a = I129 {
value: i128::max_value() as u128,
value: i128::MAX as u128,
negative: false,
};
// Max value fits.
assert_eq!(from_i129::<i128>(a), Some(i128::max_value()));
assert_eq!(from_i129::<i128>(a), Some(i128::MAX));
}
#[test]
@@ -665,13 +665,13 @@ macro_rules! implement_fixed {
let b = 1i32;
// Pos + Pos => Max.
assert_eq!(to_bound::<_, _, i32>(a, b), i32::max_value());
assert_eq!(to_bound::<_, _, i32>(a, b), i32::MAX);
let a = -1i32;
let b = -1i32;
// Neg + Neg => Max.
assert_eq!(to_bound::<_, _, i32>(a, b), i32::max_value());
assert_eq!(to_bound::<_, _, i32>(a, b), i32::MAX);
let a = 1i32;
let b = -1i32;
@@ -1084,11 +1084,11 @@ macro_rules! implement_fixed {
fn checked_mul_int_works() {
let a = $name::saturating_from_integer(2);
// Max - 1.
assert_eq!(a.checked_mul_int((i128::max_value() - 1) / 2), Some(i128::max_value() - 1));
assert_eq!(a.checked_mul_int((i128::MAX - 1) / 2), Some(i128::MAX - 1));
// Max.
assert_eq!(a.checked_mul_int(i128::max_value() / 2), Some(i128::max_value() - 1));
assert_eq!(a.checked_mul_int(i128::MAX / 2), Some(i128::MAX - 1));
// Max + 1 => None.
assert_eq!(a.checked_mul_int(i128::max_value() / 2 + 1), None);
assert_eq!(a.checked_mul_int(i128::MAX / 2 + 1), None);
if $name::SIGNED {
// Min - 1.
@@ -1100,20 +1100,20 @@ macro_rules! implement_fixed {
let b = $name::saturating_from_rational(1, -2);
assert_eq!(b.checked_mul_int(42i128), Some(-21));
assert_eq!(b.checked_mul_int(u128::max_value()), None);
assert_eq!(b.checked_mul_int(i128::max_value()), Some(i128::max_value() / -2));
assert_eq!(b.checked_mul_int(u128::MAX), None);
assert_eq!(b.checked_mul_int(i128::MAX), Some(i128::MAX / -2));
assert_eq!(b.checked_mul_int(i128::min_value()), Some(i128::min_value() / -2));
}
let a = $name::saturating_from_rational(1, 2);
assert_eq!(a.checked_mul_int(42i128), Some(21));
assert_eq!(a.checked_mul_int(i128::max_value()), Some(i128::max_value() / 2));
assert_eq!(a.checked_mul_int(i128::MAX), Some(i128::MAX / 2));
assert_eq!(a.checked_mul_int(i128::min_value()), Some(i128::min_value() / 2));
let c = $name::saturating_from_integer(255);
assert_eq!(c.checked_mul_int(2i8), None);
assert_eq!(c.checked_mul_int(2i128), Some(510));
assert_eq!(c.checked_mul_int(i128::max_value()), None);
assert_eq!(c.checked_mul_int(i128::MAX), None);
assert_eq!(c.checked_mul_int(i128::min_value()), None);
}
@@ -1121,11 +1121,11 @@ macro_rules! implement_fixed {
fn saturating_mul_int_works() {
let a = $name::saturating_from_integer(2);
// Max - 1.
assert_eq!(a.saturating_mul_int((i128::max_value() - 1) / 2), i128::max_value() - 1);
assert_eq!(a.saturating_mul_int((i128::MAX - 1) / 2), i128::MAX - 1);
// Max.
assert_eq!(a.saturating_mul_int(i128::max_value() / 2), i128::max_value() - 1);
assert_eq!(a.saturating_mul_int(i128::MAX / 2), i128::MAX - 1);
// Max + 1 => saturates to max.
assert_eq!(a.saturating_mul_int(i128::max_value() / 2 + 1), i128::max_value());
assert_eq!(a.saturating_mul_int(i128::MAX / 2 + 1), i128::MAX);
// Min - 1.
assert_eq!(a.saturating_mul_int((i128::min_value() + 1) / 2), i128::min_value() + 2);
@@ -1137,20 +1137,20 @@ macro_rules! implement_fixed {
if $name::SIGNED {
let b = $name::saturating_from_rational(1, -2);
assert_eq!(b.saturating_mul_int(42i32), -21);
assert_eq!(b.saturating_mul_int(i128::max_value()), i128::max_value() / -2);
assert_eq!(b.saturating_mul_int(i128::MAX), i128::MAX / -2);
assert_eq!(b.saturating_mul_int(i128::min_value()), i128::min_value() / -2);
assert_eq!(b.saturating_mul_int(u128::max_value()), u128::min_value());
assert_eq!(b.saturating_mul_int(u128::MAX), u128::min_value());
}
let a = $name::saturating_from_rational(1, 2);
assert_eq!(a.saturating_mul_int(42i32), 21);
assert_eq!(a.saturating_mul_int(i128::max_value()), i128::max_value() / 2);
assert_eq!(a.saturating_mul_int(i128::MAX), i128::MAX / 2);
assert_eq!(a.saturating_mul_int(i128::min_value()), i128::min_value() / 2);
let c = $name::saturating_from_integer(255);
assert_eq!(c.saturating_mul_int(2i8), i8::max_value());
assert_eq!(c.saturating_mul_int(2i8), i8::MAX);
assert_eq!(c.saturating_mul_int(-2i8), i8::min_value());
assert_eq!(c.saturating_mul_int(i128::max_value()), i128::max_value());
assert_eq!(c.saturating_mul_int(i128::MAX), i128::MAX);
assert_eq!(c.saturating_mul_int(i128::min_value()), i128::min_value());
}
@@ -1223,7 +1223,7 @@ macro_rules! implement_fixed {
assert_eq!(e.checked_div_int(2.into()), Some(3));
assert_eq!(f.checked_div_int(2.into()), Some(2));
assert_eq!(a.checked_div_int(i128::max_value()), Some(0));
assert_eq!(a.checked_div_int(i128::MAX), Some(0));
assert_eq!(a.checked_div_int(2), Some(inner_max / (2 * accuracy)));
assert_eq!(a.checked_div_int(inner_max / accuracy), Some(1));
assert_eq!(a.checked_div_int(1i8), None);
@@ -1244,11 +1244,11 @@ macro_rules! implement_fixed {
assert_eq!(b.checked_div_int(2), Some(inner_min / (2 * accuracy)));
assert_eq!(c.checked_div_int(1), Some(0));
assert_eq!(c.checked_div_int(i128::max_value()), Some(0));
assert_eq!(c.checked_div_int(i128::MAX), Some(0));
assert_eq!(c.checked_div_int(1i8), Some(0));
assert_eq!(d.checked_div_int(1), Some(1));
assert_eq!(d.checked_div_int(i32::max_value()), Some(0));
assert_eq!(d.checked_div_int(i32::MAX), Some(0));
assert_eq!(d.checked_div_int(1i8), Some(1));
assert_eq!(a.checked_div_int(0), None);
@@ -1303,17 +1303,17 @@ macro_rules! implement_fixed {
assert_eq!($name::zero().saturating_mul_acc_int(42i8), 42i8);
assert_eq!($name::one().saturating_mul_acc_int(42i8), 2 * 42i8);
assert_eq!($name::one().saturating_mul_acc_int(i128::max_value()), i128::max_value());
assert_eq!($name::one().saturating_mul_acc_int(i128::MAX), i128::MAX);
assert_eq!($name::one().saturating_mul_acc_int(i128::min_value()), i128::min_value());
assert_eq!($name::one().saturating_mul_acc_int(u128::max_value() / 2), u128::max_value() - 1);
assert_eq!($name::one().saturating_mul_acc_int(u128::MAX / 2), u128::MAX - 1);
assert_eq!($name::one().saturating_mul_acc_int(u128::min_value()), u128::min_value());
if $name::SIGNED {
let a = $name::saturating_from_rational(-1, 2);
assert_eq!(a.saturating_mul_acc_int(42i8), 21i8);
assert_eq!(a.saturating_mul_acc_int(42u8), 21u8);
assert_eq!(a.saturating_mul_acc_int(u128::max_value() - 1), u128::max_value() / 2);
assert_eq!(a.saturating_mul_acc_int(u128::MAX - 1), u128::MAX / 2);
}
}
@@ -1327,7 +1327,7 @@ macro_rules! implement_fixed {
$name::saturating_from_integer(1125899906842624i64));
assert_eq!($name::saturating_from_integer(1).saturating_pow(1000), (1).into());
assert_eq!($name::saturating_from_integer(1).saturating_pow(usize::max_value()), (1).into());
assert_eq!($name::saturating_from_integer(1).saturating_pow(usize::MAX), (1).into());
if $name::SIGNED {
// Saturating.
@@ -1335,15 +1335,15 @@ macro_rules! implement_fixed {
assert_eq!($name::saturating_from_integer(-1).saturating_pow(1000), (1).into());
assert_eq!($name::saturating_from_integer(-1).saturating_pow(1001), 0.saturating_sub(1).into());
assert_eq!($name::saturating_from_integer(-1).saturating_pow(usize::max_value()), 0.saturating_sub(1).into());
assert_eq!($name::saturating_from_integer(-1).saturating_pow(usize::max_value() - 1), (1).into());
assert_eq!($name::saturating_from_integer(-1).saturating_pow(usize::MAX), 0.saturating_sub(1).into());
assert_eq!($name::saturating_from_integer(-1).saturating_pow(usize::MAX - 1), (1).into());
}
assert_eq!($name::saturating_from_integer(114209).saturating_pow(5), $name::max_value());
assert_eq!($name::saturating_from_integer(1).saturating_pow(usize::max_value()), (1).into());
assert_eq!($name::saturating_from_integer(0).saturating_pow(usize::max_value()), (0).into());
assert_eq!($name::saturating_from_integer(2).saturating_pow(usize::max_value()), $name::max_value());
assert_eq!($name::saturating_from_integer(1).saturating_pow(usize::MAX), (1).into());
assert_eq!($name::saturating_from_integer(0).saturating_pow(usize::MAX), (0).into());
assert_eq!($name::saturating_from_integer(2).saturating_pow(usize::MAX), $name::max_value());
}
#[test]
+4 -4
View File
@@ -500,15 +500,15 @@ mod threshold_compare_tests {
#[test]
fn saturating_mul_works() {
assert_eq!(Saturating::saturating_mul(2, i32::min_value()), i32::min_value());
assert_eq!(Saturating::saturating_mul(2, i32::max_value()), i32::max_value());
assert_eq!(Saturating::saturating_mul(2, i32::MAX), i32::MAX);
}
#[test]
fn saturating_pow_works() {
assert_eq!(Saturating::saturating_pow(i32::min_value(), 0), 1);
assert_eq!(Saturating::saturating_pow(i32::max_value(), 0), 1);
assert_eq!(Saturating::saturating_pow(i32::MAX, 0), 1);
assert_eq!(Saturating::saturating_pow(i32::min_value(), 3), i32::min_value());
assert_eq!(Saturating::saturating_pow(i32::min_value(), 2), i32::max_value());
assert_eq!(Saturating::saturating_pow(i32::max_value(), 2), i32::max_value());
assert_eq!(Saturating::saturating_pow(i32::min_value(), 2), i32::MAX);
assert_eq!(Saturating::saturating_pow(i32::MAX, 2), i32::MAX);
}
}
@@ -267,9 +267,9 @@ mod tests {
use super::*;
use super::helpers_128bit::*;
const MAX128: u128 = u128::max_value();
const MAX64: u128 = u64::max_value() as u128;
const MAX64_2: u128 = 2 * u64::max_value() as u128;
const MAX128: u128 = u128::MAX;
const MAX64: u128 = u64::MAX as u128;
const MAX64_2: u128 = 2 * u64::MAX as u128;
fn r(p: u128, q: u128) -> Rational128 {
Rational128(p, q)
+2 -2
View File
@@ -43,7 +43,7 @@ mod tests {
(H160::from_low_u64_be(16), "0x0000000000000000000000000000000000000010"),
(H160::from_low_u64_be(1_000), "0x00000000000000000000000000000000000003e8"),
(H160::from_low_u64_be(100_000), "0x00000000000000000000000000000000000186a0"),
(H160::from_low_u64_be(u64::max_value()), "0x000000000000000000000000ffffffffffffffff"),
(H160::from_low_u64_be(u64::MAX), "0x000000000000000000000000ffffffffffffffff"),
];
for (number, expected) in tests {
@@ -61,7 +61,7 @@ mod tests {
(H256::from_low_u64_be(16), "0x0000000000000000000000000000000000000000000000000000000000000010"),
(H256::from_low_u64_be(1_000), "0x00000000000000000000000000000000000000000000000000000000000003e8"),
(H256::from_low_u64_be(100_000), "0x00000000000000000000000000000000000000000000000000000000000186a0"),
(H256::from_low_u64_be(u64::max_value()), "0x000000000000000000000000000000000000000000000000ffffffffffffffff"),
(H256::from_low_u64_be(u64::MAX), "0x000000000000000000000000000000000000000000000000ffffffffffffffff"),
];
for (number, expected) in tests {
@@ -282,7 +282,7 @@ impl Capabilities {
/// Return an object representing all capabilities enabled.
pub fn all() -> Self {
Self(u8::max_value())
Self(u8::MAX)
}
/// Return capabilities for rich offchain calls.
+2 -2
View File
@@ -39,8 +39,8 @@ mod tests {
($name::from(16), "0x10"),
($name::from(1_000), "0x3e8"),
($name::from(100_000), "0x186a0"),
($name::from(u64::max_value()), "0xffffffffffffffff"),
($name::from(u64::max_value()) + $name::from(1), "0x10000000000000000"),
($name::from(u64::MAX), "0xffffffffffffffff"),
($name::from(u64::MAX) + $name::from(1), "0x10000000000000000"),
];
for (number, expected) in tests {
@@ -33,7 +33,7 @@ use sp_std::prelude::*;
/// The denominator used for loads. Since votes are collected as u64, the smallest ratio that we
/// might collect is `1/approval_stake` where approval stake is the sum of votes. Hence, some number
/// bigger than u64::max_value() is needed. For maximum accuracy we simply use u128;
/// bigger than u64::MAX is needed. For maximum accuracy we simply use u128;
const DEN: ExtendedBalance = ExtendedBalance::max_value();
/// Execute sequential phragmen with potentially some rounds of `balancing`. The return type is list
@@ -181,7 +181,7 @@ pub(crate) fn apply_elected<AccountId: IdentifierT>(
) {
let elected_who = elected_ptr.borrow().who.clone();
let cutoff = elected_ptr.borrow().score.to_den(1)
.expect("(n / d) < u128::max() and (n' / 1) == (n / d), thus n' < u128::max()'; qed.")
.expect("(n / d) < u128::MAX and (n' / 1) == (n / d), thus n' < u128::MAX'; qed.")
.n();
let mut elected_backed_stake = elected_ptr.borrow().backed_stake;
@@ -386,10 +386,10 @@ mod tests {
#[test]
fn large_balance_wont_overflow() {
let candidates = vec![1u32, 2, 3];
let mut voters = (0..1000).map(|i| (10 + i, u64::max_value(), vec![1, 2, 3])).collect::<Vec<_>>();
let mut voters = (0..1000).map(|i| (10 + i, u64::MAX, vec![1, 2, 3])).collect::<Vec<_>>();
// give a bit more to 1 and 3.
voters.push((2, u64::max_value(), vec![1, 3]));
voters.push((2, u64::MAX, vec![1, 3]));
let ElectionResult { winners, assignments: _ } = phragmms::<_, Perbill>(2, candidates, voters, Some((2, 0))).unwrap();
assert_eq!(winners.into_iter().map(|(w, _)| w).collect::<Vec<_>>(), vec![1u32, 3]);
@@ -458,11 +458,11 @@ fn phragmen_accuracy_on_large_scale_only_candidates() {
// candidate can have the maximum amount of tokens, and also supported by the maximum.
let candidates = vec![1, 2, 3, 4, 5];
let stake_of = create_stake_of(&[
(1, (u64::max_value() - 1).into()),
(2, (u64::max_value() - 4).into()),
(3, (u64::max_value() - 5).into()),
(4, (u64::max_value() - 3).into()),
(5, (u64::max_value() - 2).into()),
(1, (u64::MAX - 1).into()),
(2, (u64::MAX - 4).into()),
(3, (u64::MAX - 5).into()),
(4, (u64::MAX - 3).into()),
(5, (u64::MAX - 2).into()),
]);
let ElectionResult { winners, assignments } = seq_phragmen::<_, Perbill>(
@@ -489,13 +489,13 @@ fn phragmen_accuracy_on_large_scale_voters_and_candidates() {
];
voters.extend(auto_generate_self_voters(&candidates));
let stake_of = create_stake_of(&[
(1, (u64::max_value() - 1).into()),
(2, (u64::max_value() - 4).into()),
(3, (u64::max_value() - 5).into()),
(4, (u64::max_value() - 3).into()),
(5, (u64::max_value() - 2).into()),
(13, (u64::max_value() - 10).into()),
(14, u64::max_value().into()),
(1, (u64::MAX - 1).into()),
(2, (u64::MAX - 4).into()),
(3, (u64::MAX - 5).into()),
(4, (u64::MAX - 3).into()),
(5, (u64::MAX - 2).into()),
(13, (u64::MAX - 10).into()),
(14, u64::MAX.into()),
]);
let ElectionResult { winners, assignments } = seq_phragmen::<_, Perbill>(
@@ -226,11 +226,11 @@ wasm_export_functions! {
}
fn test_u128_i128_as_parameter_and_return_value() {
for val in &[u128::max_value(), 1u128, 5000u128, u64::max_value() as u128] {
for val in &[u128::MAX, 1u128, 5000u128, u64::MAX as u128] {
assert_eq!(*val, test_api::get_and_return_u128(*val));
}
for val in &[i128::max_value(), i128::min_value(), 1i128, 5000i128, u64::max_value() as i128] {
for val in &[i128::MAX, i128::min_value(), 1i128, 5000i128, u64::MAX as i128] {
assert_eq!(*val, test_api::get_and_return_i128(*val));
}
}
+6 -6
View File
@@ -112,17 +112,17 @@ fn test_multiply_by_rational_saturating() {
for value in 0..=div {
for p in 0..=div {
for q in 1..=div {
let value: u64 = (value as u128 * u64::max_value() as u128 / div as u128)
let value: u64 = (value as u128 * u64::MAX as u128 / div as u128)
.try_into().unwrap();
let p = (p as u64 * u32::max_value() as u64 / div as u64)
let p = (p as u64 * u32::MAX as u64 / div as u64)
.try_into().unwrap();
let q = (q as u64 * u32::max_value() as u64 / div as u64)
let q = (q as u64 * u32::MAX as u64 / div as u64)
.try_into().unwrap();
assert_eq!(
multiply_by_rational_saturating(value, p, q),
(value as u128 * p as u128 / q as u128)
.try_into().unwrap_or(u64::max_value())
.try_into().unwrap_or(u64::MAX)
);
}
}
@@ -153,9 +153,9 @@ fn test_calculate_for_fraction_times_denominator() {
let div = 100u32;
for d in 0..=div {
for n in 0..=d {
let d: u64 = (d as u128 * u64::max_value() as u128 / div as u128)
let d: u64 = (d as u128 * u64::MAX as u128 / div as u128)
.try_into().unwrap();
let n: u64 = (n as u128 * u64::max_value() as u128 / div as u128)
let n: u64 = (n as u128 * u64::MAX as u128 / div as u128)
.try_into().unwrap();
let res = curve.calculate_for_fraction_times_denominator(n, d);
@@ -97,7 +97,7 @@ impl Era {
/// Get the block number of the first block at which the era has ended.
pub fn death(self, current: u64) -> u64 {
match self {
Self::Immortal => u64::max_value(),
Self::Immortal => u64::MAX,
Self::Mortal(period, _) => self.birth(current) + period,
}
}
@@ -145,11 +145,11 @@ mod tests {
fn immortal_works() {
let e = Era::immortal();
assert_eq!(e.birth(0), 0);
assert_eq!(e.death(0), u64::max_value());
assert_eq!(e.death(0), u64::MAX);
assert_eq!(e.birth(1), 0);
assert_eq!(e.death(1), u64::max_value());
assert_eq!(e.birth(u64::max_value()), 0);
assert_eq!(e.death(u64::max_value()), u64::max_value());
assert_eq!(e.death(1), u64::MAX);
assert_eq!(e.birth(u64::MAX), 0);
assert_eq!(e.death(u64::MAX), u64::MAX);
assert!(e.is_immortal());
assert_eq!(e.encode(), vec![0u8]);
@@ -200,8 +200,8 @@ mod tests {
assert_eq!(serialize(0), "\"0x0\"".to_owned());
assert_eq!(serialize(1), "\"0x1\"".to_owned());
assert_eq!(serialize(u64::max_value() as u128), "\"0xffffffffffffffff\"".to_owned());
assert_eq!(serialize(u64::max_value() as u128 + 1), "\"0x10000000000000000\"".to_owned());
assert_eq!(serialize(u64::MAX as u128), "\"0xffffffffffffffff\"".to_owned());
assert_eq!(serialize(u64::MAX as u128 + 1), "\"0x10000000000000000\"".to_owned());
}
#[test]
@@ -213,7 +213,7 @@ mod tests {
assert_eq!(deserialize("\"0x0\""), 0);
assert_eq!(deserialize("\"0x1\""), 1);
assert_eq!(deserialize("\"0xffffffffffffffff\""), u64::max_value() as u128);
assert_eq!(deserialize("\"0x10000000000000000\""), u64::max_value() as u128 + 1);
assert_eq!(deserialize("\"0xffffffffffffffff\""), u64::MAX as u128);
assert_eq!(deserialize("\"0x10000000000000000\""), u64::MAX as u128 + 1);
}
}
@@ -76,7 +76,7 @@ impl<Hashing: Hash> RandomNumberGenerator<Hashing> {
self.offset += needed as u32;
let raw = u32::decode(&mut TrailingZeroInput::new(data)).unwrap_or(0);
if raw <= top {
break if max < u32::max_value() {
break if max < u32::MAX {
raw % (max + 1)
} else {
raw
+1 -1
View File
@@ -438,7 +438,7 @@ impl<'a, DB, H, T> hash_db::AsHashDB<H, T> for KeySpacedDBMut<'a, DB, H> where
/// Constants used into trie simplification codec.
mod trie_constants {
pub const EMPTY_TRIE: u8 = 0;
pub const NIBBLE_SIZE_BOUND: usize = u16::max_value() as usize;
pub const NIBBLE_SIZE_BOUND: usize = u16::MAX as usize;
pub const LEAF_PREFIX_MASK: u8 = 0b_01 << 6;
pub const BRANCH_WITHOUT_MASK: u8 = 0b_10 << 6;
pub const BRANCH_WITH_MASK: u8 = 0b_11 << 6;