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:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
+44 -35
View File
@@ -17,8 +17,8 @@
//! Some configurable implementations as associated type for the substrate runtime.
use frame_support::traits::{OnUnbalanced, Currency};
use crate::{Balances, Authorship, NegativeImbalance};
use crate::{Authorship, Balances, NegativeImbalance};
use frame_support::traits::{Currency, OnUnbalanced};
pub struct Author;
impl OnUnbalanced<NegativeImbalance> for Author {
@@ -29,19 +29,24 @@ impl OnUnbalanced<NegativeImbalance> for Author {
#[cfg(test)]
mod multiplier_tests {
use sp_runtime::{assert_eq_error_rate, FixedPointNumber, traits::{Convert, One, Zero}};
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use sp_runtime::{
assert_eq_error_rate,
traits::{Convert, One, Zero},
FixedPointNumber,
};
use crate::{
constants::{currency::*, time::*},
TransactionPayment, Runtime, TargetBlockFullness,
AdjustmentVariable, System, MinimumMultiplier,
RuntimeBlockWeights as BlockWeights,
AdjustmentVariable, MinimumMultiplier, Runtime, RuntimeBlockWeights as BlockWeights,
System, TargetBlockFullness, TransactionPayment,
};
use frame_support::weights::{Weight, WeightToFeePolynomial, DispatchClass};
use frame_support::weights::{DispatchClass, Weight, WeightToFeePolynomial};
fn max_normal() -> Weight {
BlockWeights::get().get(DispatchClass::Normal).max_total
BlockWeights::get()
.get(DispatchClass::Normal)
.max_total
.unwrap_or_else(|| BlockWeights::get().max_block)
}
@@ -64,7 +69,7 @@ mod multiplier_tests {
}
// update based on reference impl.
fn truth_value_update(block_weight: Weight, previous: Multiplier) -> Multiplier {
fn truth_value_update(block_weight: Weight, previous: Multiplier) -> Multiplier {
let accuracy = Multiplier::accuracy() as f64;
let previous_float = previous.into_inner() as f64 / accuracy;
// bump if it is zero.
@@ -81,15 +86,20 @@ mod multiplier_tests {
// Current saturation in terms of weight
let s = block_weight;
let t1 = v * (s/m - ss/m);
let t2 = v.powi(2) * (s/m - ss/m).powi(2) / 2.0;
let t1 = v * (s / m - ss / m);
let t2 = v.powi(2) * (s / m - ss / m).powi(2) / 2.0;
let next_float = previous_float * (1.0 + t1 + t2);
Multiplier::from_float(next_float)
}
fn run_with_system_weight<F>(w: Weight, assertions: F) where F: Fn() -> () {
let mut t: sp_io::TestExternalities =
frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap().into();
fn run_with_system_weight<F>(w: Weight, assertions: F)
where
F: Fn() -> (),
{
let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
.unwrap()
.into();
t.execute_with(|| {
System::set_block_consumed_resources(w, 0);
assertions()
@@ -157,7 +167,9 @@ mod multiplier_tests {
loop {
let next = runtime_multiplier_update(fm);
fm = next;
if fm == min_multiplier() { break; }
if fm == min_multiplier() {
break
}
iterations += 1;
}
assert!(iterations > 533_333);
@@ -198,7 +210,9 @@ mod multiplier_tests {
loop {
let next = runtime_multiplier_update(fm);
// if no change, panic. This should never happen in this case.
if fm == next { panic!("The fee should ever increase"); }
if fm == next {
panic!("The fee should ever increase");
}
fm = next;
iterations += 1;
let fee =
@@ -225,7 +239,7 @@ mod multiplier_tests {
let next = runtime_multiplier_update(fm);
assert_eq_error_rate!(
next,
truth_value_update(target() / 4 , fm),
truth_value_update(target() / 4, fm),
Multiplier::from_inner(100),
);
@@ -237,12 +251,11 @@ mod multiplier_tests {
let next = runtime_multiplier_update(fm);
assert_eq_error_rate!(
next,
truth_value_update(target() / 2 , fm),
truth_value_update(target() / 2, fm),
Multiplier::from_inner(100),
);
// Light block. Multiplier is reduced a little.
assert!(next < fm);
});
run_with_system_weight(target(), || {
let next = runtime_multiplier_update(fm);
@@ -259,7 +272,7 @@ mod multiplier_tests {
let next = runtime_multiplier_update(fm);
assert_eq_error_rate!(
next,
truth_value_update(target() * 2 , fm),
truth_value_update(target() * 2, fm),
Multiplier::from_inner(100),
);
@@ -326,28 +339,24 @@ mod multiplier_tests {
BlockWeights::get().max_block,
Weight::max_value() / 2,
Weight::max_value(),
].into_iter().for_each(|i| {
]
.into_iter()
.for_each(|i| {
run_with_system_weight(i, || {
let next = runtime_multiplier_update(Multiplier::one());
let truth = truth_value_update(i, Multiplier::one());
assert_eq_error_rate!(
truth,
next,
Multiplier::from_inner(50_000_000)
);
assert_eq_error_rate!(truth, next, Multiplier::from_inner(50_000_000));
});
});
// Some values that are all above the target and will cause an increase.
let t = target();
vec![t + 100, t * 2, t * 4]
.into_iter()
.for_each(|i| {
run_with_system_weight(i, || {
let fm = runtime_multiplier_update(max_fm);
// won't grow. The convert saturates everything.
assert_eq!(fm, max_fm);
})
});
vec![t + 100, t * 2, t * 4].into_iter().for_each(|i| {
run_with_system_weight(i, || {
let fm = runtime_multiplier_update(max_fm);
// won't grow. The convert saturates everything.
assert_eq!(fm, max_fm);
})
});
}
}