mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 21:01:05 +00:00
Use associated constant for max (#3375)
This commit is contained in:
@@ -250,7 +250,7 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
EthTransaction::parse(
|
EthTransaction::parse(
|
||||||
&prepare_ethereum_transaction(&ferdie(), |tx| {
|
&prepare_ethereum_transaction(&ferdie(), |tx| {
|
||||||
tx.value = sp_core::U256::from(u128::max_value()) + sp_core::U256::from(1);
|
tx.value = sp_core::U256::from(u128::MAX) + sp_core::U256::from(1);
|
||||||
})
|
})
|
||||||
.0
|
.0
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ const FINALIZED_HEADERS_TO_KEEP: u64 = 20_000;
|
|||||||
/// Aura engine configuration for Kovan chain.
|
/// Aura engine configuration for Kovan chain.
|
||||||
pub fn kovan_aura_configuration() -> AuraConfiguration {
|
pub fn kovan_aura_configuration() -> AuraConfiguration {
|
||||||
AuraConfiguration {
|
AuraConfiguration {
|
||||||
empty_steps_transition: u64::max_value(),
|
empty_steps_transition: u64::MAX,
|
||||||
strict_empty_steps_transition: 0,
|
strict_empty_steps_transition: 0,
|
||||||
validate_step_transition: 0x16e360,
|
validate_step_transition: 0x16e360,
|
||||||
validate_score_transition: 0x41a3c4,
|
validate_score_transition: 0x41a3c4,
|
||||||
two_thirds_majority_transition: u64::max_value(),
|
two_thirds_majority_transition: u64::MAX,
|
||||||
min_gas_limit: 0x1388.into(),
|
min_gas_limit: 0x1388.into(),
|
||||||
max_gas_limit: U256::max_value(),
|
max_gas_limit: U256::MAX,
|
||||||
maximum_extra_data_size: 0x20,
|
maximum_extra_data_size: 0x20,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,9 +46,9 @@ pub fn aura_configuration() -> AuraConfiguration {
|
|||||||
strict_empty_steps_transition: 0,
|
strict_empty_steps_transition: 0,
|
||||||
validate_step_transition: 0,
|
validate_step_transition: 0,
|
||||||
validate_score_transition: 0,
|
validate_score_transition: 0,
|
||||||
two_thirds_majority_transition: u64::max_value(),
|
two_thirds_majority_transition: u64::MAX,
|
||||||
min_gas_limit: 0x1388.into(),
|
min_gas_limit: 0x1388.into(),
|
||||||
max_gas_limit: U256::max_value(),
|
max_gas_limit: U256::MAX,
|
||||||
maximum_extra_data_size: 0x20,
|
maximum_extra_data_size: 0x20,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ mod tests {
|
|||||||
id1,
|
id1,
|
||||||
None,
|
None,
|
||||||
&header_to_import.header,
|
&header_to_import.header,
|
||||||
u64::max_value(),
|
u64::MAX,
|
||||||
)
|
)
|
||||||
.map(|eff| eff.finalized_headers),
|
.map(|eff| eff.finalized_headers),
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
@@ -353,7 +353,7 @@ mod tests {
|
|||||||
id2,
|
id2,
|
||||||
None,
|
None,
|
||||||
&header_to_import.header,
|
&header_to_import.header,
|
||||||
u64::max_value(),
|
u64::MAX,
|
||||||
)
|
)
|
||||||
.map(|eff| eff.finalized_headers),
|
.map(|eff| eff.finalized_headers),
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
@@ -372,7 +372,7 @@ mod tests {
|
|||||||
id3,
|
id3,
|
||||||
None,
|
None,
|
||||||
&header_to_import.header,
|
&header_to_import.header,
|
||||||
u64::max_value(),
|
u64::MAX,
|
||||||
)
|
)
|
||||||
.map(|eff| eff.finalized_headers),
|
.map(|eff| eff.finalized_headers),
|
||||||
Ok(vec![(id1, None)]),
|
Ok(vec![(id1, None)]),
|
||||||
|
|||||||
@@ -112,13 +112,13 @@ pub struct TestContext {
|
|||||||
/// Aura configuration that is used in tests by default.
|
/// Aura configuration that is used in tests by default.
|
||||||
pub fn test_aura_config() -> AuraConfiguration {
|
pub fn test_aura_config() -> AuraConfiguration {
|
||||||
AuraConfiguration {
|
AuraConfiguration {
|
||||||
empty_steps_transition: u64::max_value(),
|
empty_steps_transition: u64::MAX,
|
||||||
strict_empty_steps_transition: 0,
|
strict_empty_steps_transition: 0,
|
||||||
validate_step_transition: 0x16e360,
|
validate_step_transition: 0x16e360,
|
||||||
validate_score_transition: 0x41a3c4,
|
validate_score_transition: 0x41a3c4,
|
||||||
two_thirds_majority_transition: u64::max_value(),
|
two_thirds_majority_transition: u64::MAX,
|
||||||
min_gas_limit: 0x1388.into(),
|
min_gas_limit: 0x1388.into(),
|
||||||
max_gas_limit: U256::max_value(),
|
max_gas_limit: U256::MAX,
|
||||||
maximum_extra_data_size: 0x20,
|
maximum_extra_data_size: 0x20,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,7 +186,7 @@ pub struct ConstChainTime;
|
|||||||
|
|
||||||
impl ChainTime for ConstChainTime {
|
impl ChainTime for ConstChainTime {
|
||||||
fn is_timestamp_ahead(&self, timestamp: u64) -> bool {
|
fn is_timestamp_ahead(&self, timestamp: u64) -> bool {
|
||||||
let now = i32::max_value() as u64 / 2;
|
let now = i32::MAX as u64 / 2;
|
||||||
timestamp > now
|
timestamp > now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ pub(crate) mod tests {
|
|||||||
let config = ValidatorsConfiguration::Single(ValidatorsSource::Contract(Default::default(), Vec::new()));
|
let config = ValidatorsConfiguration::Single(ValidatorsSource::Contract(Default::default(), Vec::new()));
|
||||||
let validators = Validators::new(&config);
|
let validators = Validators::new(&config);
|
||||||
let mut header = AuraHeader {
|
let mut header = AuraHeader {
|
||||||
number: u64::max_value(),
|
number: u64::MAX,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
assert!(!validators.maybe_signals_validators_change(&header));
|
assert!(!validators.maybe_signals_validators_change(&header));
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ fn contextless_checks<CT: ChainTime>(
|
|||||||
if header.seal.len() != expected_seal_fields {
|
if header.seal.len() != expected_seal_fields {
|
||||||
return Err(Error::InvalidSealArity);
|
return Err(Error::InvalidSealArity);
|
||||||
}
|
}
|
||||||
if header.number >= u64::max_value() {
|
if header.number >= u64::MAX {
|
||||||
return Err(Error::RidiculousNumber);
|
return Err(Error::RidiculousNumber);
|
||||||
}
|
}
|
||||||
if header.gas_used > header.gas_limit {
|
if header.gas_used > header.gas_limit {
|
||||||
@@ -209,7 +209,7 @@ fn contextless_checks<CT: ChainTime>(
|
|||||||
|
|
||||||
// we can't detect if block is from future in runtime
|
// we can't detect if block is from future in runtime
|
||||||
// => let's only do an overflow check
|
// => let's only do an overflow check
|
||||||
if header.timestamp > i32::max_value() as u64 {
|
if header.timestamp > i32::MAX as u64 {
|
||||||
return Err(Error::TimestampOverflow);
|
return Err(Error::TimestampOverflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +309,7 @@ fn validator_checks(
|
|||||||
|
|
||||||
/// Returns expected number of seal fields in the header.
|
/// Returns expected number of seal fields in the header.
|
||||||
fn expected_header_seal_fields(config: &AuraConfiguration, header: &AuraHeader) -> usize {
|
fn expected_header_seal_fields(config: &AuraConfiguration, header: &AuraHeader) -> usize {
|
||||||
if header.number != u64::max_value() && header.number >= config.empty_steps_transition {
|
if header.number != u64::MAX && header.number >= config.empty_steps_transition {
|
||||||
3
|
3
|
||||||
} else {
|
} else {
|
||||||
2
|
2
|
||||||
@@ -323,9 +323,9 @@ fn verify_empty_step(parent_hash: &H256, step: &SealedEmptyStep, validators: &[A
|
|||||||
verify_signature(&expected_validator, &step.signature, &message)
|
verify_signature(&expected_validator, &step.signature, &message)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Chain scoring: total weight is sqrt(U256::max_value())*height - step
|
/// Chain scoring: total weight is sqrt(U256::MAX)*height - step
|
||||||
pub(crate) fn calculate_score(parent_step: u64, current_step: u64, current_empty_steps: usize) -> U256 {
|
pub(crate) fn calculate_score(parent_step: u64, current_step: u64, current_empty_steps: usize) -> U256 {
|
||||||
U256::from(U128::max_value()) + U256::from(parent_step) - U256::from(current_step) + U256::from(current_empty_steps)
|
U256::from(U128::MAX) + U256::from(parent_step) - U256::from(current_step) + U256::from(current_empty_steps)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verify that the signature over message has been produced by given validator.
|
/// Verify that the signature over message has been produced by given validator.
|
||||||
@@ -491,12 +491,12 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn verifies_header_number() {
|
fn verifies_header_number() {
|
||||||
// when number is u64::max_value()
|
// when number is u64::MAX
|
||||||
let header = HeaderBuilder::with_number(u64::max_value()).sign_by(&validator(0));
|
let header = HeaderBuilder::with_number(u64::MAX).sign_by(&validator(0));
|
||||||
assert_eq!(default_verify(&header), Err(Error::RidiculousNumber));
|
assert_eq!(default_verify(&header), Err(Error::RidiculousNumber));
|
||||||
|
|
||||||
// when header is < u64::max_value()
|
// when header is < u64::MAX
|
||||||
let header = HeaderBuilder::with_number(u64::max_value() - 1).sign_by(&validator(0));
|
let header = HeaderBuilder::with_number(u64::MAX - 1).sign_by(&validator(0));
|
||||||
assert_ne!(default_verify(&header), Err(Error::RidiculousNumber));
|
assert_ne!(default_verify(&header), Err(Error::RidiculousNumber));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -559,13 +559,13 @@ mod tests {
|
|||||||
fn verifies_timestamp() {
|
fn verifies_timestamp() {
|
||||||
// when timestamp overflows i32
|
// when timestamp overflows i32
|
||||||
let header = HeaderBuilder::with_number(1)
|
let header = HeaderBuilder::with_number(1)
|
||||||
.timestamp(i32::max_value() as u64 + 1)
|
.timestamp(i32::MAX as u64 + 1)
|
||||||
.sign_by(&validator(0));
|
.sign_by(&validator(0));
|
||||||
assert_eq!(default_verify(&header), Err(Error::TimestampOverflow));
|
assert_eq!(default_verify(&header), Err(Error::TimestampOverflow));
|
||||||
|
|
||||||
// when timestamp doesn't overflow i32
|
// when timestamp doesn't overflow i32
|
||||||
let header = HeaderBuilder::with_number(1)
|
let header = HeaderBuilder::with_number(1)
|
||||||
.timestamp(i32::max_value() as u64)
|
.timestamp(i32::MAX as u64)
|
||||||
.sign_by(&validator(0));
|
.sign_by(&validator(0));
|
||||||
assert_ne!(default_verify(&header), Err(Error::TimestampOverflow));
|
assert_ne!(default_verify(&header), Err(Error::TimestampOverflow));
|
||||||
}
|
}
|
||||||
@@ -597,19 +597,19 @@ mod tests {
|
|||||||
|
|
||||||
// header is behind
|
// header is behind
|
||||||
let header = HeaderBuilder::with_parent(&genesis())
|
let header = HeaderBuilder::with_parent(&genesis())
|
||||||
.timestamp(i32::max_value() as u64 / 2 - 100)
|
.timestamp(i32::MAX as u64 / 2 - 100)
|
||||||
.sign_by(&validator(1));
|
.sign_by(&validator(1));
|
||||||
assert_eq!(default_verify(&header).unwrap(), expect);
|
assert_eq!(default_verify(&header).unwrap(), expect);
|
||||||
|
|
||||||
// header is ahead
|
// header is ahead
|
||||||
let header = HeaderBuilder::with_parent(&genesis())
|
let header = HeaderBuilder::with_parent(&genesis())
|
||||||
.timestamp(i32::max_value() as u64 / 2 + 100)
|
.timestamp(i32::MAX as u64 / 2 + 100)
|
||||||
.sign_by(&validator(1));
|
.sign_by(&validator(1));
|
||||||
assert_eq!(default_verify(&header), Err(Error::HeaderTimestampIsAhead));
|
assert_eq!(default_verify(&header), Err(Error::HeaderTimestampIsAhead));
|
||||||
|
|
||||||
// header has same timestamp as ConstChainTime
|
// header has same timestamp as ConstChainTime
|
||||||
let header = HeaderBuilder::with_parent(&genesis())
|
let header = HeaderBuilder::with_parent(&genesis())
|
||||||
.timestamp(i32::max_value() as u64 / 2)
|
.timestamp(i32::MAX as u64 / 2)
|
||||||
.sign_by(&validator(1));
|
.sign_by(&validator(1));
|
||||||
assert_eq!(default_verify(&header).unwrap(), expect);
|
assert_eq!(default_verify(&header).unwrap(), expect);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ impl TableContextTrait for TableContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn requisite_votes(&self, group: &ParaId) -> usize {
|
fn requisite_votes(&self, group: &ParaId) -> usize {
|
||||||
self.groups.get(group).map_or(usize::max_value(), |g| group_quorum(g.len()))
|
self.groups.get(group).map_or(usize::MAX, |g| group_quorum(g.len()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ impl UnifiedReputationChange {
|
|||||||
Self::CostMajor(_) => -300_000,
|
Self::CostMajor(_) => -300_000,
|
||||||
Self::CostMinorRepeated(_) => -200_000,
|
Self::CostMinorRepeated(_) => -200_000,
|
||||||
Self::CostMajorRepeated(_) => -600_000,
|
Self::CostMajorRepeated(_) => -600_000,
|
||||||
Self::Malicious(_) => i32::min_value(),
|
Self::Malicious(_) => i32::MIN,
|
||||||
Self::BenefitMajorFirst(_) => 300_000,
|
Self::BenefitMajorFirst(_) => 300_000,
|
||||||
Self::BenefitMajor(_) => 200_000,
|
Self::BenefitMajor(_) => 200_000,
|
||||||
Self::BenefitMinorFirst(_) => 15_000,
|
Self::BenefitMinorFirst(_) => 15_000,
|
||||||
|
|||||||
@@ -647,7 +647,7 @@ impl GroupRotationInfo {
|
|||||||
if self.group_rotation_frequency == 0 { return GroupIndex(core_index.0) }
|
if self.group_rotation_frequency == 0 { return GroupIndex(core_index.0) }
|
||||||
if cores == 0 { return GroupIndex(0) }
|
if cores == 0 { return GroupIndex(0) }
|
||||||
|
|
||||||
let cores = sp_std::cmp::min(cores, u32::max_value() as usize);
|
let cores = sp_std::cmp::min(cores, u32::MAX as usize);
|
||||||
let blocks_since_start = self.now.saturating_sub(self.session_start_block);
|
let blocks_since_start = self.now.saturating_sub(self.session_start_block);
|
||||||
let rotations = blocks_since_start / self.group_rotation_frequency;
|
let rotations = blocks_since_start / self.group_rotation_frequency;
|
||||||
|
|
||||||
@@ -665,7 +665,7 @@ impl GroupRotationInfo {
|
|||||||
if self.group_rotation_frequency == 0 { return CoreIndex(group_index.0) }
|
if self.group_rotation_frequency == 0 { return CoreIndex(group_index.0) }
|
||||||
if cores == 0 { return CoreIndex(0) }
|
if cores == 0 { return CoreIndex(0) }
|
||||||
|
|
||||||
let cores = sp_std::cmp::min(cores, u32::max_value() as usize);
|
let cores = sp_std::cmp::min(cores, u32::MAX as usize);
|
||||||
let blocks_since_start = self.now.saturating_sub(self.session_start_block);
|
let blocks_since_start = self.now.saturating_sub(self.session_start_block);
|
||||||
let rotations = blocks_since_start / self.group_rotation_frequency;
|
let rotations = blocks_since_start / self.group_rotation_frequency;
|
||||||
let rotations = rotations % cores as u32;
|
let rotations = rotations % cores as u32;
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
# PoV Distribution
|
||||||
@@ -1224,7 +1224,7 @@ mod benchmarking {
|
|||||||
|
|
||||||
for i in 0 .. c / 2 {
|
for i in 0 .. c / 2 {
|
||||||
create_claim::<T>(c)?;
|
create_claim::<T>(c)?;
|
||||||
create_claim_attest::<T>(u32::max_value() - c)?;
|
create_claim_attest::<T>(u32::MAX - c)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let secret_key = secp256k1::SecretKey::parse(&keccak_256(&c.encode())).unwrap();
|
let secret_key = secp256k1::SecretKey::parse(&keccak_256(&c.encode())).unwrap();
|
||||||
@@ -1250,7 +1250,7 @@ mod benchmarking {
|
|||||||
|
|
||||||
for i in 0 .. c / 2 {
|
for i in 0 .. c / 2 {
|
||||||
create_claim::<T>(c)?;
|
create_claim::<T>(c)?;
|
||||||
create_claim_attest::<T>(u32::max_value() - c)?;
|
create_claim_attest::<T>(u32::MAX - c)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let eth_address = account("eth_address", 0, SEED);
|
let eth_address = account("eth_address", 0, SEED);
|
||||||
@@ -1267,11 +1267,11 @@ mod benchmarking {
|
|||||||
|
|
||||||
for i in 0 .. c / 2 {
|
for i in 0 .. c / 2 {
|
||||||
create_claim::<T>(c)?;
|
create_claim::<T>(c)?;
|
||||||
create_claim_attest::<T>(u32::max_value() - c)?;
|
create_claim_attest::<T>(u32::MAX - c)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crate signature
|
// Crate signature
|
||||||
let attest_c = u32::max_value() - c;
|
let attest_c = u32::MAX - c;
|
||||||
let secret_key = secp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap();
|
let secret_key = secp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap();
|
||||||
let eth_address = eth(&secret_key);
|
let eth_address = eth(&secret_key);
|
||||||
let account: T::AccountId = account("user", c, SEED);
|
let account: T::AccountId = account("user", c, SEED);
|
||||||
@@ -1296,10 +1296,10 @@ mod benchmarking {
|
|||||||
|
|
||||||
for i in 0 .. c / 2 {
|
for i in 0 .. c / 2 {
|
||||||
create_claim::<T>(c)?;
|
create_claim::<T>(c)?;
|
||||||
create_claim_attest::<T>(u32::max_value() - c)?;
|
create_claim_attest::<T>(u32::MAX - c)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let attest_c = u32::max_value() - c;
|
let attest_c = u32::MAX - c;
|
||||||
let secret_key = secp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap();
|
let secret_key = secp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap();
|
||||||
let eth_address = eth(&secret_key);
|
let eth_address = eth(&secret_key);
|
||||||
let account: T::AccountId = account("user", c, SEED);
|
let account: T::AccountId = account("user", c, SEED);
|
||||||
@@ -1334,14 +1334,14 @@ mod benchmarking {
|
|||||||
|
|
||||||
for i in 0 .. c / 2 {
|
for i in 0 .. c / 2 {
|
||||||
create_claim::<T>(c)?;
|
create_claim::<T>(c)?;
|
||||||
create_claim_attest::<T>(u32::max_value() - c)?;
|
create_claim_attest::<T>(u32::MAX - c)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let attest_c = u32::max_value() - c;
|
let attest_c = u32::MAX - c;
|
||||||
let secret_key = secp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap();
|
let secret_key = secp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap();
|
||||||
let eth_address = eth(&secret_key);
|
let eth_address = eth(&secret_key);
|
||||||
|
|
||||||
let new_secret_key = secp256k1::SecretKey::parse(&keccak_256(&(u32::max_value()/2).encode())).unwrap();
|
let new_secret_key = secp256k1::SecretKey::parse(&keccak_256(&(u32::MAX/2).encode())).unwrap();
|
||||||
let new_eth_address = eth(&new_secret_key);
|
let new_eth_address = eth(&new_secret_key);
|
||||||
|
|
||||||
let account: T::AccountId = account("user", c, SEED);
|
let account: T::AccountId = account("user", c, SEED);
|
||||||
|
|||||||
@@ -898,8 +898,8 @@ mod tests {
|
|||||||
assert_noop!(Purchase::update_balance(
|
assert_noop!(Purchase::update_balance(
|
||||||
Origin::signed(validity_origin()),
|
Origin::signed(validity_origin()),
|
||||||
alice(),
|
alice(),
|
||||||
u64::max_value(),
|
u64::MAX,
|
||||||
u64::max_value(),
|
u64::MAX,
|
||||||
Permill::zero(),
|
Permill::zero(),
|
||||||
), Error::<Test>::InvalidAccount);
|
), Error::<Test>::InvalidAccount);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user