diff --git a/substrate/bin/node/runtime/src/impls.rs b/substrate/bin/node/runtime/src/impls.rs index 1d1488e2fa..d3d0541b6e 100644 --- a/substrate/bin/node/runtime/src/impls.rs +++ b/substrate/bin/node/runtime/src/impls.rs @@ -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![ diff --git a/substrate/client/consensus/aura/src/lib.rs b/substrate/client/consensus/aura/src/lib.rs index d08ce5dfee..72545eda07 100644 --- a/substrate/client/consensus/aura/src/lib.rs +++ b/substrate/client/consensus/aura/src/lib.rs @@ -97,7 +97,7 @@ fn slot_author(slot: Slot, authorities: &[AuthorityId

]) -> 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", ); diff --git a/substrate/client/finality-grandpa/src/communication/gossip.rs b/substrate/client/finality-grandpa/src/communication/gossip.rs index 8f46e45d63..1b3b5ea7c5 100644 --- a/substrate/client/finality-grandpa/src/communication/gossip.rs +++ b/substrate/client/finality-grandpa/src/communication/gossip.rs @@ -1468,7 +1468,7 @@ impl GossipValidator { "" => "", ); - 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()) } } diff --git a/substrate/client/informant/src/display.rs b/substrate/client/informant/src/display.rs index 00c2116fac..0b7f8bcfaf 100644 --- a/substrate/client/informant/src/display.rs +++ b/substrate/client/informant/src/display.rs @@ -179,7 +179,7 @@ fn speed( // algebraic approach and we stay within the realm of integers. let one_thousand = NumberFor::::from(1_000u32); let elapsed = NumberFor::::from( - >::try_from(elapsed_ms).unwrap_or(u32::max_value()) + >::try_from(elapsed_ms).unwrap_or(u32::MAX) ); let speed = diff.saturating_mul(one_thousand).checked_div(&elapsed) diff --git a/substrate/client/network/src/protocol/notifications/upgrade/notifications.rs b/substrate/client/network/src/protocol/notifications/upgrade/notifications.rs index e2ef26c81e..26bb92d776 100644 --- a/substrate/client/network/src/protocol/notifications/upgrade/notifications.rs +++ b/substrate/client/network/src/protocol/notifications/upgrade/notifications.rs @@ -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, diff --git a/substrate/client/network/src/request_responses.rs b/substrate/client/network/src/request_responses.rs index 3762cf70e7..20469e143d 100644 --- a/substrate/client/network/src/request_responses.rs +++ b/substrate/client/network/src/request_responses.rs @@ -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) diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 0bc2828850..fb30331209 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -300,20 +300,20 @@ impl NetworkWorker { 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) diff --git a/substrate/client/network/src/service/out_events.rs b/substrate/client/network/src/service/out_events.rs index 06c068e369..7ec6c608a8 100644 --- a/substrate/client/network/src/service/out_events.rs +++ b/substrate/client/network/src/service/out_events.rs @@ -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)); } }, } diff --git a/substrate/client/network/src/service/tests.rs b/substrate/client/network/src/service/tests.rs index c2e3844849..4a739e5062 100644 --- a/substrate/client/network/src/service/tests.rs +++ b/substrate/client/network/src/service/tests.rs @@ -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() }, } diff --git a/substrate/client/peerset/src/peersstate.rs b/substrate/client/peerset/src/peersstate.rs index 309c7e6b8f..9f54a7714f 100644 --- a/substrate/client/peerset/src/peersstate.rs +++ b/substrate/client/peerset/src/peersstate.rs @@ -97,8 +97,8 @@ struct Node { /// are indices into this `Vec`. sets: Vec, - /// 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, } diff --git a/substrate/client/peerset/tests/fuzz.rs b/substrate/client/peerset/tests/fuzz.rs index 8f64962943..d951b0cc56 100644 --- a/substrate/client/peerset/tests/fuzz.rs +++ b/substrate/client/peerset/tests/fuzz.rs @@ -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, "")); } diff --git a/substrate/client/rpc/src/chain/mod.rs b/substrate/client/rpc/src/chain/mod.rs index d3a28d5343..1380927bca 100644 --- a/substrate/client/rpc/src/chain/mod.rs +++ b/substrate/client/rpc/src/chain/mod.rs @@ -84,7 +84,7 @@ trait ChainBackend: 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 )) })?; diff --git a/substrate/client/service/src/chain_ops/import_blocks.rs b/substrate/client/service/src/chain_ops/import_blocks.rs index 90bcc94cb8..330aaea4f5 100644 --- a/substrate/client/service/src/chain_ops/import_blocks.rs +++ b/substrate/client/service/src/chain_ops/import_blocks.rs @@ -236,7 +236,7 @@ impl Speedometer { // algebraic approach and we stay within the realm of integers. let one_thousand = NumberFor::::from(1_000u32); let elapsed = NumberFor::::from( - >::try_from(elapsed_ms).unwrap_or(u32::max_value()) + >::try_from(elapsed_ms).unwrap_or(u32::MAX) ); let speed = diff.saturating_mul(one_thousand).checked_div(&elapsed) diff --git a/substrate/client/service/test/src/client/mod.rs b/substrate/client/service/test/src/client/mod.rs index bf4105377f..9cd0e193fc 100644 --- a/substrate/client/service/test/src/client/mod.rs +++ b/substrate/client/service/test/src/client/mod.rs @@ -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(); diff --git a/substrate/client/transaction-pool/graph/src/ready.rs b/substrate/client/transaction-pool/graph/src/ready.rs index 2c0575bf1e..ba6ca97dc6 100644 --- a/substrate/client/transaction-pool/graph/src/ready.rs +++ b/substrate/client/transaction-pool/graph/src/ready.rs @@ -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, diff --git a/substrate/frame/assets/src/tests.rs b/substrate/frame/assets/src/tests.rs index b561864c8e..b8eb2e40f8 100644 --- a/substrate/frame/assets/src/tests.rs +++ b/substrate/frame/assets/src/tests.rs @@ -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::::BalanceLow); assert_noop!(Assets::transfer(Origin::signed(2), 0, 1, 51), Error::::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); }); diff --git a/substrate/frame/babe/src/mock.rs b/substrate/frame/babe/src/mock.rs index a8d0bba963..6c1cc89cf1 100644 --- a/substrate/frame/babe/src/mock.rs +++ b/substrate/frame/babe/src/mock.rs @@ -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 { diff --git a/substrate/frame/balances/src/tests.rs b/substrate/frame/balances/src/tests.rs index 3598595c76..c98b0ecf02 100644 --- a/substrate/frame/balances/src/tests.rs +++ b/substrate/frame/balances/src/tests.rs @@ -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!(>::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!(>::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!(>::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); }); } diff --git a/substrate/frame/contracts/src/benchmarking/mod.rs b/substrate/frame/contracts/src/benchmarking/mod.rs index bb04e9b2cf..7b77569a1f 100644 --- a/substrate/frame/contracts/src/benchmarking/mod.rs +++ b/substrate/frame/contracts/src/benchmarking/mod.rs @@ -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 diff --git a/substrate/frame/contracts/src/chain_extension.rs b/substrate/frame/contracts/src/chain_extension.rs index d2839dfdbc..ac71eca27b 100644 --- a/substrate/frame/contracts/src/chain_extension.rs +++ b/substrate/frame/contracts/src/chain_extension.rs @@ -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( diff --git a/substrate/frame/contracts/src/wasm/runtime.rs b/substrate/frame/contracts/src/wasm/runtime.rs index 7ca6dfed15..8d1782e84d 100644 --- a/substrate/frame/contracts/src/wasm/runtime.rs +++ b/substrate/frame/contracts/src/wasm/runtime.rs @@ -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, ) -> 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, , // // 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, , // 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 diff --git a/substrate/frame/democracy/src/benchmarking.rs b/substrate/frame/democracy/src/benchmarking.rs index 6cf35553f5..d1d3b3e62b 100644 --- a/substrate/frame/democracy/src/benchmarking.rs +++ b/substrate/frame/democracy/src/benchmarking.rs @@ -118,13 +118,13 @@ benchmarks! { // Create s existing "seconds" for i in 0 .. s { let seconder = funded_account::("seconder", i); - Democracy::::second(RawOrigin::Signed(seconder).into(), 0, u32::max_value())?; + Democracy::::second(RawOrigin::Signed(seconder).into(), 0, u32::MAX)?; } let deposits = Democracy::::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::::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::("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::::contains_key(proposal_hash)); diff --git a/substrate/frame/democracy/src/tests/decoders.rs b/substrate/frame/democracy/src/tests/decoders.rs index 32e5e3ecf7..c3eb9ca7e3 100644 --- a/substrate/frame/democracy/src/tests/decoders.rs +++ b/substrate/frame/democracy/src/tests/decoders.rs @@ -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)); diff --git a/substrate/frame/democracy/src/tests/preimage.rs b/substrate/frame/democracy/src/tests/preimage.rs index 135b167520..a412343299 100644 --- a/substrate/frame/democracy/src/tests/preimage.rs +++ b/substrate/frame/democracy/src/tests/preimage.rs @@ -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::::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::::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::::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::::Imminent); + assert_noop!(Democracy::reap_preimage(Origin::signed(6), h, u32::MAX), Error::::Imminent); }); } diff --git a/substrate/frame/democracy/src/tests/public_proposals.rs b/substrate/frame/democracy/src/tests/public_proposals.rs index 4a4827ac7e..1d323d684d 100644 --- a/substrate/frame/democracy/src/tests/public_proposals.rs +++ b/substrate/frame/democracy/src/tests/public_proposals.rs @@ -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::::InsufficientBalance ); }); diff --git a/substrate/frame/example/src/tests.rs b/substrate/frame/example/src/tests.rs index a290ea0f65..c699a0bfad 100644 --- a/substrate/frame/example/src/tests.rs +++ b/substrate/frame/example/src/tests.rs @@ -166,7 +166,7 @@ fn signed_ext_watch_dummy_works() { WatchDummy::(PhantomData).validate(&1, &call, &info, 150) .unwrap() .priority, - u64::max_value(), + u64::MAX, ); assert_eq!( WatchDummy::(PhantomData).validate(&1, &call, &info, 250), diff --git a/substrate/frame/grandpa/src/mock.rs b/substrate/frame/grandpa/src/mock.rs index 9206b3ff2d..ebe5996c9d 100644 --- a/substrate/frame/grandpa/src/mock.rs +++ b/substrate/frame/grandpa/src/mock.rs @@ -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 { diff --git a/substrate/frame/staking/reward-curve/src/lib.rs b/substrate/frame/staking/reward-curve/src/lib.rs index 5ce6d0c3a8..de912eee99 100644 --- a/substrate/frame/staking/reward-curve/src/lib.rs +++ b/substrate/frame/staking/reward-curve/src/lib.rs @@ -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; diff --git a/substrate/frame/staking/reward-curve/src/log.rs b/substrate/frame/staking/reward-curve/src/log.rs index 28acd5deed..747011a73e 100644 --- a/substrate/frame/staking/reward-curve/src/log.rs +++ b/substrate/frame/staking/reward-curve/src/log.rs @@ -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); diff --git a/substrate/frame/staking/src/benchmarking.rs b/substrate/frame/staking/src/benchmarking.rs index 8adf797abe..f7545b07c9 100644 --- a/substrate/frame/staking/src/benchmarking.rs +++ b/substrate/frame/staking/src/benchmarking.rs @@ -79,9 +79,9 @@ pub fn create_validator_with_nominators( // 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::(u32::max_value() - i, 100, destination.clone())? + create_stash_controller::(u32::MAX - i, 100, destination.clone())? } else { - create_stash_and_dead_controller::(u32::max_value() - i, 100, destination.clone())? + create_stash_and_dead_controller::(u32::MAX - i, 100, destination.clone())? }; if i < n { Staking::::nominate(RawOrigin::Signed(n_controller.clone()).into(), vec![stash_lookup.clone()])?; @@ -456,7 +456,7 @@ benchmarks! { >::insert(i, BalanceOf::::one()); ErasStartSessionIndex::::insert(i, i); } - }: _(RawOrigin::Root, EraIndex::zero(), u32::max_value()) + }: _(RawOrigin::Root, EraIndex::zero(), u32::MAX) verify { assert_eq!(HistoryDepth::::get(), 0); } @@ -607,13 +607,13 @@ benchmarks! { RawOrigin::Root, BalanceOf::::max_value(), BalanceOf::::max_value(), - Some(u32::max_value()), - Some(u32::max_value()) + Some(u32::MAX), + Some(u32::MAX) ) verify { assert_eq!(MinNominatorBond::::get(), BalanceOf::::max_value()); assert_eq!(MinValidatorBond::::get(), BalanceOf::::max_value()); - assert_eq!(MaxNominatorsCount::::get(), Some(u32::max_value())); - assert_eq!(MaxValidatorsCount::::get(), Some(u32::max_value())); + assert_eq!(MaxNominatorsCount::::get(), Some(u32::MAX)); + assert_eq!(MaxValidatorsCount::::get(), Some(u32::MAX)); } chill_other { diff --git a/substrate/frame/staking/src/testing_utils.rs b/substrate/frame/staking/src/testing_utils.rs index c643cb2833..18b77d59b3 100644 --- a/substrate/frame/staking/src/testing_utils.rs +++ b/substrate/frame/staking/src/testing_utils.rs @@ -150,7 +150,7 @@ pub fn create_validators_with_nominators_for_era( 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::( - u32::max_value() - j, + u32::MAX - j, balance_factor, RewardDestination::Staked, )?; diff --git a/substrate/frame/staking/src/tests.rs b/substrate/frame/staking/src/tests.rs index 5d42d866b1..e314a70399 100644 --- a/substrate/frame/staking/src/tests.rs +++ b/substrate/frame/staking/src/tests.rs @@ -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); diff --git a/substrate/frame/support/src/traits/voting.rs b/substrate/frame/support/src/traits/voting.rs index b6913a182d..f5afbac129 100644 --- a/substrate/frame/support/src/traits/voting.rs +++ b/substrate/frame/support/src/traits/voting.rs @@ -42,20 +42,20 @@ pub trait CurrencyToVote { /// 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) } } diff --git a/substrate/frame/support/src/weights.rs b/substrate/frame/support/src/weights.rs index 9337ec330d..2b7cff8c61 100644 --- a/substrate/frame/support/src/weights.rs +++ b/substrate/frame/support/src/weights.rs @@ -278,7 +278,7 @@ impl<'a> OneOrMany 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. diff --git a/substrate/frame/support/test/tests/pallet_with_name_trait_is_valid.rs b/substrate/frame/support/test/tests/pallet_with_name_trait_is_valid.rs index e7f44c4b96..6f35b122f6 100644 --- a/substrate/frame/support/test/tests/pallet_with_name_trait_is_valid.rs +++ b/substrate/frame/support/test/tests/pallet_with_name_trait_is_valid.rs @@ -43,7 +43,7 @@ frame_support::decl_module! { pub struct Module for enum Call where origin: T::Origin { fn deposit_event() = default; type Error = Error; - const Foo: u32 = u32::max_value(); + const Foo: u32 = u32::MAX; #[weight = 0] fn accumulate_dummy(_origin, _increase_by: T::Balance) { diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 17ea3a71be..f96c43ee1c 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -778,7 +778,7 @@ fn hash69 + Default>() -> T { /// This type alias represents an index of an event. /// /// We use `u32` here because this index is used as index for `Events` -/// 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. diff --git a/substrate/frame/transaction-payment/src/lib.rs b/substrate/frame/transaction-payment/src/lib.rs index 1ce3f75d5a..17a4c8f81c 100644 --- a/substrate/frame/transaction-payment/src/lib.rs +++ b/substrate/frame/transaction-payment/src/lib.rs @@ -1142,11 +1142,11 @@ mod tests { }; assert_eq!( Module::::compute_fee( - ::max_value(), + u32::MAX, &dispatch_info, - ::max_value() + u64::MAX ), - ::max_value() + u64::MAX ); }); } diff --git a/substrate/frame/treasury/src/tests.rs b/substrate/frame/treasury/src/tests.rs index 408f99f29e..e4b6f2d664 100644 --- a/substrate/frame/treasury/src/tests.rs +++ b/substrate/frame/treasury/src/tests.rs @@ -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)); diff --git a/substrate/primitives/allocator/src/freeing_bump.rs b/substrate/primitives/allocator/src/freeing_bump.rs index e2a6b19e4a..36f5bb9c65 100644 --- a/substrate/primitives/allocator/src/freeing_bump.rs +++ b/substrate/primitives/allocator/src/freeing_bump.rs @@ -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)] diff --git a/substrate/primitives/arithmetic/fuzzer/src/multiply_by_rational.rs b/substrate/primitives/arithmetic/fuzzer/src/multiply_by_rational.rs index 40f315ce75..a1689716b5 100644 --- a/substrate/primitives/arithmetic/fuzzer/src/multiply_by_rational.rs +++ b/substrate/primitives/arithmetic/fuzzer/src/multiply_by_rational.rs @@ -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() diff --git a/substrate/primitives/arithmetic/src/biguint.rs b/substrate/primitives/arithmetic/src/biguint.rs index bfbd57f570..859cf82924 100644 --- a/substrate/primitives/arithmetic/src/biguint.rs +++ b/substrate/primitives/arithmetic/src/biguint.rs @@ -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 ); } diff --git a/substrate/primitives/arithmetic/src/fixed_point.rs b/substrate/primitives/arithmetic/src/fixed_point.rs index ec2c28f35f..4940c7751a 100644 --- a/substrate/primitives/arithmetic/src/fixed_point.rs +++ b/substrate/primitives/arithmetic/src/fixed_point.rs @@ -619,23 +619,23 @@ macro_rules! implement_fixed { assert_eq!(from_i129::(a), None); let a = I129 { - value: u128::max_value() - 1, + value: u128::MAX - 1, negative: false, }; // Max - 1 value fits. - assert_eq!(from_i129::(a), Some(u128::max_value() - 1)); + assert_eq!(from_i129::(a), Some(u128::MAX - 1)); let a = I129 { - value: u128::max_value(), + value: u128::MAX, negative: false, }; // Max value fits. - assert_eq!(from_i129::(a), Some(u128::max_value())); + assert_eq!(from_i129::(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::(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::(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::(a), Some(i128::max_value())); + assert_eq!(from_i129::(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] diff --git a/substrate/primitives/arithmetic/src/lib.rs b/substrate/primitives/arithmetic/src/lib.rs index d6069ad515..527530d63e 100644 --- a/substrate/primitives/arithmetic/src/lib.rs +++ b/substrate/primitives/arithmetic/src/lib.rs @@ -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); } } diff --git a/substrate/primitives/arithmetic/src/rational.rs b/substrate/primitives/arithmetic/src/rational.rs index 88eaca1efb..feb81eb572 100644 --- a/substrate/primitives/arithmetic/src/rational.rs +++ b/substrate/primitives/arithmetic/src/rational.rs @@ -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) diff --git a/substrate/primitives/core/src/hash.rs b/substrate/primitives/core/src/hash.rs index dcaafd2906..6ef1827a1b 100644 --- a/substrate/primitives/core/src/hash.rs +++ b/substrate/primitives/core/src/hash.rs @@ -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 { diff --git a/substrate/primitives/core/src/offchain/mod.rs b/substrate/primitives/core/src/offchain/mod.rs index 66fc85ec7b..d3d2356b6e 100644 --- a/substrate/primitives/core/src/offchain/mod.rs +++ b/substrate/primitives/core/src/offchain/mod.rs @@ -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. diff --git a/substrate/primitives/core/src/uint.rs b/substrate/primitives/core/src/uint.rs index f917f472d7..ff45ad6ecf 100644 --- a/substrate/primitives/core/src/uint.rs +++ b/substrate/primitives/core/src/uint.rs @@ -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 { diff --git a/substrate/primitives/npos-elections/src/phragmen.rs b/substrate/primitives/npos-elections/src/phragmen.rs index a1e632acf5..bbead91c93 100644 --- a/substrate/primitives/npos-elections/src/phragmen.rs +++ b/substrate/primitives/npos-elections/src/phragmen.rs @@ -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 diff --git a/substrate/primitives/npos-elections/src/phragmms.rs b/substrate/primitives/npos-elections/src/phragmms.rs index 644535d4c4..2a643d3673 100644 --- a/substrate/primitives/npos-elections/src/phragmms.rs +++ b/substrate/primitives/npos-elections/src/phragmms.rs @@ -181,7 +181,7 @@ pub(crate) fn apply_elected( ) { 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::>(); + let mut voters = (0..1000).map(|i| (10 + i, u64::MAX, vec![1, 2, 3])).collect::>(); // 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![1u32, 3]); diff --git a/substrate/primitives/npos-elections/src/tests.rs b/substrate/primitives/npos-elections/src/tests.rs index 06505721fd..8cadff949b 100644 --- a/substrate/primitives/npos-elections/src/tests.rs +++ b/substrate/primitives/npos-elections/src/tests.rs @@ -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>( diff --git a/substrate/primitives/runtime-interface/test-wasm/src/lib.rs b/substrate/primitives/runtime-interface/test-wasm/src/lib.rs index 4cdf59349d..39f1c8b3f5 100644 --- a/substrate/primitives/runtime-interface/test-wasm/src/lib.rs +++ b/substrate/primitives/runtime-interface/test-wasm/src/lib.rs @@ -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)); } } diff --git a/substrate/primitives/runtime/src/curve.rs b/substrate/primitives/runtime/src/curve.rs index 06f7f2c7e3..326ababcf5 100644 --- a/substrate/primitives/runtime/src/curve.rs +++ b/substrate/primitives/runtime/src/curve.rs @@ -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); diff --git a/substrate/primitives/runtime/src/generic/era.rs b/substrate/primitives/runtime/src/generic/era.rs index fbda688cc4..83a9f22afe 100644 --- a/substrate/primitives/runtime/src/generic/era.rs +++ b/substrate/primitives/runtime/src/generic/era.rs @@ -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]); diff --git a/substrate/primitives/runtime/src/generic/header.rs b/substrate/primitives/runtime/src/generic/header.rs index 69c5f50796..def761b201 100644 --- a/substrate/primitives/runtime/src/generic/header.rs +++ b/substrate/primitives/runtime/src/generic/header.rs @@ -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); } } diff --git a/substrate/primitives/runtime/src/random_number_generator.rs b/substrate/primitives/runtime/src/random_number_generator.rs index 41ca7c723e..0adf346579 100644 --- a/substrate/primitives/runtime/src/random_number_generator.rs +++ b/substrate/primitives/runtime/src/random_number_generator.rs @@ -76,7 +76,7 @@ impl RandomNumberGenerator { 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 diff --git a/substrate/primitives/trie/src/lib.rs b/substrate/primitives/trie/src/lib.rs index 4cfe362381..a496245637 100644 --- a/substrate/primitives/trie/src/lib.rs +++ b/substrate/primitives/trie/src/lib.rs @@ -438,7 +438,7 @@ impl<'a, DB, H, T> hash_db::AsHashDB 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;