mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 23:21:02 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -21,23 +21,23 @@
|
||||
|
||||
use super::*;
|
||||
use crate::mock::*;
|
||||
use sp_core::OpaquePeerId;
|
||||
use sp_core::offchain::{
|
||||
OffchainDbExt,
|
||||
OffchainWorkerExt,
|
||||
TransactionPoolExt,
|
||||
testing::{TestOffchainExt, TestTransactionPoolExt},
|
||||
use frame_support::{assert_noop, dispatch};
|
||||
use sp_core::{
|
||||
offchain::{
|
||||
testing::{TestOffchainExt, TestTransactionPoolExt},
|
||||
OffchainDbExt, OffchainWorkerExt, TransactionPoolExt,
|
||||
},
|
||||
OpaquePeerId,
|
||||
};
|
||||
use sp_runtime::{
|
||||
testing::UintAuthorityId,
|
||||
transaction_validity::{InvalidTransaction, TransactionValidityError},
|
||||
};
|
||||
use frame_support::{dispatch, assert_noop};
|
||||
use sp_runtime::{testing::UintAuthorityId, transaction_validity::{TransactionValidityError, InvalidTransaction}};
|
||||
|
||||
#[test]
|
||||
fn test_unresponsiveness_slash_fraction() {
|
||||
// A single case of unresponsiveness is not slashed.
|
||||
assert_eq!(
|
||||
UnresponsivenessOffence::<()>::slash_fraction(1, 50),
|
||||
Perbill::zero(),
|
||||
);
|
||||
assert_eq!(UnresponsivenessOffence::<()>::slash_fraction(1, 50), Perbill::zero(),);
|
||||
|
||||
assert_eq!(
|
||||
UnresponsivenessOffence::<()>::slash_fraction(5, 50),
|
||||
@@ -75,17 +75,17 @@ fn should_report_offline_validators() {
|
||||
|
||||
// then
|
||||
let offences = OFFENCES.with(|l| l.replace(vec![]));
|
||||
assert_eq!(offences, vec![
|
||||
(vec![], UnresponsivenessOffence {
|
||||
session_index: 2,
|
||||
validator_set_count: 3,
|
||||
offenders: vec![
|
||||
(1, 1),
|
||||
(2, 2),
|
||||
(3, 3),
|
||||
],
|
||||
})
|
||||
]);
|
||||
assert_eq!(
|
||||
offences,
|
||||
vec![(
|
||||
vec![],
|
||||
UnresponsivenessOffence {
|
||||
session_index: 2,
|
||||
validator_set_count: 3,
|
||||
offenders: vec![(1, 1), (2, 2), (3, 3),],
|
||||
}
|
||||
)]
|
||||
);
|
||||
|
||||
// should not report when heartbeat is sent
|
||||
for (idx, v) in validators.into_iter().take(4).enumerate() {
|
||||
@@ -95,16 +95,17 @@ fn should_report_offline_validators() {
|
||||
|
||||
// then
|
||||
let offences = OFFENCES.with(|l| l.replace(vec![]));
|
||||
assert_eq!(offences, vec![
|
||||
(vec![], UnresponsivenessOffence {
|
||||
session_index: 3,
|
||||
validator_set_count: 6,
|
||||
offenders: vec![
|
||||
(5, 5),
|
||||
(6, 6),
|
||||
],
|
||||
})
|
||||
]);
|
||||
assert_eq!(
|
||||
offences,
|
||||
vec![(
|
||||
vec![],
|
||||
UnresponsivenessOffence {
|
||||
session_index: 3,
|
||||
validator_set_count: 6,
|
||||
offenders: vec![(5, 5), (6, 6),],
|
||||
}
|
||||
)]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -129,17 +130,15 @@ fn heartbeat(
|
||||
};
|
||||
let signature = id.sign(&heartbeat.encode()).unwrap();
|
||||
|
||||
ImOnline::pre_dispatch(&crate::Call::heartbeat(heartbeat.clone(), signature.clone()))
|
||||
.map_err(|e| match e {
|
||||
TransactionValidityError::Invalid(InvalidTransaction::Custom(INVALID_VALIDATORS_LEN)) =>
|
||||
"invalid validators len",
|
||||
ImOnline::pre_dispatch(&crate::Call::heartbeat(heartbeat.clone(), signature.clone())).map_err(
|
||||
|e| match e {
|
||||
TransactionValidityError::Invalid(InvalidTransaction::Custom(
|
||||
INVALID_VALIDATORS_LEN,
|
||||
)) => "invalid validators len",
|
||||
e @ _ => <&'static str>::from(e),
|
||||
})?;
|
||||
ImOnline::heartbeat(
|
||||
Origin::none(),
|
||||
heartbeat,
|
||||
signature,
|
||||
)
|
||||
},
|
||||
)?;
|
||||
ImOnline::heartbeat(Origin::none(), heartbeat, signature)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -191,8 +190,14 @@ fn late_heartbeat_and_invalid_keys_len_should_fail() {
|
||||
assert_eq!(Session::validators(), vec![1, 2, 3]);
|
||||
|
||||
// when
|
||||
assert_noop!(heartbeat(1, 3, 0, 1.into(), Session::validators()), "Transaction is outdated");
|
||||
assert_noop!(heartbeat(1, 1, 0, 1.into(), Session::validators()), "Transaction is outdated");
|
||||
assert_noop!(
|
||||
heartbeat(1, 3, 0, 1.into(), Session::validators()),
|
||||
"Transaction is outdated"
|
||||
);
|
||||
assert_noop!(
|
||||
heartbeat(1, 1, 0, 1.into(), Session::validators()),
|
||||
"Transaction is outdated"
|
||||
);
|
||||
|
||||
// invalid validators_len
|
||||
assert_noop!(heartbeat(1, 2, 0, 1.into(), vec![]), "invalid validators len");
|
||||
@@ -236,13 +241,16 @@ fn should_generate_heartbeats() {
|
||||
e => panic!("Unexpected call: {:?}", e),
|
||||
};
|
||||
|
||||
assert_eq!(heartbeat, Heartbeat {
|
||||
block_number: block,
|
||||
network_state: sp_io::offchain::network_state().unwrap(),
|
||||
session_index: 2,
|
||||
authority_index: 2,
|
||||
validators_len: 3,
|
||||
});
|
||||
assert_eq!(
|
||||
heartbeat,
|
||||
Heartbeat {
|
||||
block_number: block,
|
||||
network_state: sp_io::offchain::network_state().unwrap(),
|
||||
session_index: 2,
|
||||
authority_index: 2,
|
||||
validators_len: 3,
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -348,13 +356,16 @@ fn should_not_send_a_report_if_already_online() {
|
||||
e => panic!("Unexpected call: {:?}", e),
|
||||
};
|
||||
|
||||
assert_eq!(heartbeat, Heartbeat {
|
||||
block_number: 4,
|
||||
network_state: sp_io::offchain::network_state().unwrap(),
|
||||
session_index: 2,
|
||||
authority_index: 0,
|
||||
validators_len: 3,
|
||||
});
|
||||
assert_eq!(
|
||||
heartbeat,
|
||||
Heartbeat {
|
||||
block_number: 4,
|
||||
network_state: sp_io::offchain::network_state().unwrap(),
|
||||
session_index: 2,
|
||||
authority_index: 0,
|
||||
validators_len: 3,
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -424,10 +435,7 @@ fn should_handle_non_linear_session_progress() {
|
||||
// if we don't have valid results for the current session progres then
|
||||
// we'll fallback to `HeartbeatAfter` and only heartbeat on block 5.
|
||||
MOCK_CURRENT_SESSION_PROGRESS.with(|p| *p.borrow_mut() = Some(None));
|
||||
assert_eq!(
|
||||
ImOnline::send_heartbeats(2).err(),
|
||||
Some(OffchainErr::TooEarly),
|
||||
);
|
||||
assert_eq!(ImOnline::send_heartbeats(2).err(), Some(OffchainErr::TooEarly),);
|
||||
|
||||
MOCK_CURRENT_SESSION_PROGRESS.with(|p| *p.borrow_mut() = Some(None));
|
||||
assert!(ImOnline::send_heartbeats(5).ok().is_some());
|
||||
@@ -453,11 +461,9 @@ fn test_does_not_heartbeat_early_in_the_session() {
|
||||
ext.execute_with(|| {
|
||||
// mock current session progress as being 5%. we only randomly start
|
||||
// heartbeating after 10% of the session has elapsed.
|
||||
MOCK_CURRENT_SESSION_PROGRESS.with(|p| *p.borrow_mut() = Some(Some(Permill::from_float(0.05))));
|
||||
assert_eq!(
|
||||
ImOnline::send_heartbeats(2).err(),
|
||||
Some(OffchainErr::TooEarly),
|
||||
);
|
||||
MOCK_CURRENT_SESSION_PROGRESS
|
||||
.with(|p| *p.borrow_mut() = Some(Some(Permill::from_float(0.05))));
|
||||
assert_eq!(ImOnline::send_heartbeats(2).err(), Some(OffchainErr::TooEarly),);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -475,8 +481,8 @@ fn test_probability_of_heartbeating_increases_with_session_progress() {
|
||||
// the average session length is 100 blocks, therefore the residual
|
||||
// probability of sending a heartbeat is 1%
|
||||
MOCK_AVERAGE_SESSION_LENGTH.with(|p| *p.borrow_mut() = Some(100));
|
||||
MOCK_CURRENT_SESSION_PROGRESS.with(|p| *p.borrow_mut() =
|
||||
Some(Some(Permill::from_float(progress))));
|
||||
MOCK_CURRENT_SESSION_PROGRESS
|
||||
.with(|p| *p.borrow_mut() = Some(Some(Permill::from_float(progress))));
|
||||
|
||||
let mut seed = [0u8; 32];
|
||||
let encoded = ((random * Permill::ACCURACY as f64) as u32).encode();
|
||||
@@ -486,10 +492,7 @@ fn test_probability_of_heartbeating_increases_with_session_progress() {
|
||||
|
||||
let assert_too_early = |progress, random| {
|
||||
set_test(progress, random);
|
||||
assert_eq!(
|
||||
ImOnline::send_heartbeats(2).err(),
|
||||
Some(OffchainErr::TooEarly),
|
||||
);
|
||||
assert_eq!(ImOnline::send_heartbeats(2).err(), Some(OffchainErr::TooEarly),);
|
||||
};
|
||||
|
||||
let assert_heartbeat_ok = |progress, random| {
|
||||
|
||||
Reference in New Issue
Block a user