mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 10:01:17 +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:
@@ -20,8 +20,8 @@
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use super::*;
|
||||
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
|
||||
use frame_system::RawOrigin;
|
||||
use frame_benchmarking::{benchmarks, account, whitelisted_caller, impl_benchmark_test_suite};
|
||||
|
||||
const SEED: u32 = 0;
|
||||
|
||||
@@ -65,8 +65,4 @@ benchmarks! {
|
||||
}
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
Pallet,
|
||||
crate::tests::new_test_ext(),
|
||||
crate::tests::Test,
|
||||
);
|
||||
impl_benchmark_test_suite!(Pallet, crate::tests::new_test_ext(), crate::tests::Test,);
|
||||
|
||||
@@ -52,36 +52,35 @@
|
||||
// Ensure we're `no_std` when compiling for Wasm.
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
mod tests;
|
||||
mod benchmarking;
|
||||
mod tests;
|
||||
pub mod weights;
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use codec::{Encode, Decode};
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{
|
||||
dispatch::PostDispatchInfo,
|
||||
traits::{IsSubType, OriginTrait, UnfilteredDispatchable},
|
||||
transactional,
|
||||
weights::{extract_actual_weight, GetDispatchInfo},
|
||||
};
|
||||
use sp_core::TypeId;
|
||||
use sp_io::hashing::blake2_256;
|
||||
use frame_support::{
|
||||
transactional,
|
||||
traits::{OriginTrait, UnfilteredDispatchable, IsSubType},
|
||||
weights::{GetDispatchInfo, extract_actual_weight},
|
||||
dispatch::PostDispatchInfo,
|
||||
};
|
||||
use sp_runtime::traits::Dispatchable;
|
||||
use sp_std::prelude::*;
|
||||
pub use weights::WeightInfo;
|
||||
|
||||
pub use pallet::*;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
|
||||
/// Configuration trait.
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
@@ -89,9 +88,11 @@ pub mod pallet {
|
||||
type Event: From<Event> + IsType<<Self as frame_system::Config>::Event>;
|
||||
|
||||
/// The overarching call type.
|
||||
type Call: Parameter + Dispatchable<Origin=Self::Origin, PostInfo=PostDispatchInfo>
|
||||
+ GetDispatchInfo + From<frame_system::Call<Self>>
|
||||
+ UnfilteredDispatchable<Origin=Self::Origin>
|
||||
type Call: Parameter
|
||||
+ Dispatchable<Origin = Self::Origin, PostInfo = PostDispatchInfo>
|
||||
+ GetDispatchInfo
|
||||
+ From<frame_system::Call<Self>>
|
||||
+ UnfilteredDispatchable<Origin = Self::Origin>
|
||||
+ IsSubType<Call<Self>>
|
||||
+ IsType<<Self as frame_system::Config>::Call>;
|
||||
|
||||
@@ -170,7 +171,7 @@ pub mod pallet {
|
||||
// Take the weight of this function itself into account.
|
||||
let base_weight = T::WeightInfo::batch(index.saturating_add(1) as u32);
|
||||
// Return the actual used weight + base_weight of this call.
|
||||
return Ok(Some(base_weight + weight).into());
|
||||
return Ok(Some(base_weight + weight).into())
|
||||
}
|
||||
}
|
||||
Self::deposit_event(Event::BatchCompleted);
|
||||
@@ -213,13 +214,16 @@ pub mod pallet {
|
||||
let info = call.get_dispatch_info();
|
||||
let result = call.dispatch(origin);
|
||||
// Always take into account the base weight of this call.
|
||||
let mut weight = T::WeightInfo::as_derivative().saturating_add(T::DbWeight::get().reads_writes(1, 1));
|
||||
let mut weight = T::WeightInfo::as_derivative()
|
||||
.saturating_add(T::DbWeight::get().reads_writes(1, 1));
|
||||
// Add the real weight of the dispatch.
|
||||
weight = weight.saturating_add(extract_actual_weight(&result, &info));
|
||||
result.map_err(|mut err| {
|
||||
err.post_info = Some(weight).into();
|
||||
err
|
||||
}).map(|_| Some(weight).into())
|
||||
result
|
||||
.map_err(|mut err| {
|
||||
err.post_info = Some(weight).into();
|
||||
err
|
||||
})
|
||||
.map(|_| Some(weight).into())
|
||||
}
|
||||
|
||||
/// Send a batch of dispatch calls and atomically execute them.
|
||||
@@ -291,7 +295,6 @@ pub mod pallet {
|
||||
Ok(Some(base_weight + weight).into())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// A pallet identifier. These are per pallet and should be stored in a registry somewhere.
|
||||
|
||||
@@ -21,23 +21,26 @@
|
||||
|
||||
use super::*;
|
||||
|
||||
use crate as utility;
|
||||
use frame_support::{
|
||||
assert_ok, assert_noop, parameter_types, assert_err_ignore_postinfo, decl_module,
|
||||
weights::{Weight, Pays},
|
||||
assert_err_ignore_postinfo, assert_noop, assert_ok, decl_module,
|
||||
dispatch::{DispatchError, DispatchErrorWithPostInfo, Dispatchable},
|
||||
parameter_types, storage,
|
||||
traits::Filter,
|
||||
storage,
|
||||
weights::{Pays, Weight},
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
|
||||
use crate as utility;
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
};
|
||||
|
||||
// example module to test behaviors.
|
||||
pub mod example {
|
||||
use super::*;
|
||||
use frame_system::ensure_signed;
|
||||
use frame_support::dispatch::{DispatchResultWithPostInfo, WithPostDispatchInfo};
|
||||
pub trait Config: frame_system::Config { }
|
||||
use frame_system::ensure_signed;
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Config> for enum Call where origin: <T as frame_system::Config>::Origin {
|
||||
@@ -160,14 +163,15 @@ type ExampleCall = example::Call<Test>;
|
||||
type UtilityCall = crate::Call<Test>;
|
||||
|
||||
use frame_system::Call as SystemCall;
|
||||
use pallet_balances::Call as BalancesCall;
|
||||
use pallet_balances::Error as BalancesError;
|
||||
use pallet_balances::{Call as BalancesCall, Error as BalancesError};
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
pallet_balances::GenesisConfig::<Test> {
|
||||
balances: vec![(1, 10), (2, 10), (3, 10), (4, 10), (5, 2)],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
}
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
let mut ext = sp_io::TestExternalities::new(t);
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
@@ -178,11 +182,14 @@ fn as_derivative_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let sub_1_0 = Utility::derivative_account_id(1, 0);
|
||||
assert_ok!(Balances::transfer(Origin::signed(1), sub_1_0, 5));
|
||||
assert_err_ignore_postinfo!(Utility::as_derivative(
|
||||
Origin::signed(1),
|
||||
1,
|
||||
Box::new(Call::Balances(BalancesCall::transfer(6, 3))),
|
||||
), BalancesError::<Test, _>::InsufficientBalance);
|
||||
assert_err_ignore_postinfo!(
|
||||
Utility::as_derivative(
|
||||
Origin::signed(1),
|
||||
1,
|
||||
Box::new(Call::Balances(BalancesCall::transfer(6, 3))),
|
||||
),
|
||||
BalancesError::<Test, _>::InsufficientBalance
|
||||
);
|
||||
assert_ok!(Utility::as_derivative(
|
||||
Origin::signed(1),
|
||||
0,
|
||||
@@ -256,11 +263,14 @@ fn as_derivative_handles_weight_refund() {
|
||||
#[test]
|
||||
fn as_derivative_filters() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_err_ignore_postinfo!(Utility::as_derivative(
|
||||
Origin::signed(1),
|
||||
1,
|
||||
Box::new(Call::Balances(pallet_balances::Call::transfer_keep_alive(2, 1))),
|
||||
), DispatchError::BadOrigin);
|
||||
assert_err_ignore_postinfo!(
|
||||
Utility::as_derivative(
|
||||
Origin::signed(1),
|
||||
1,
|
||||
Box::new(Call::Balances(pallet_balances::Call::transfer_keep_alive(2, 1))),
|
||||
),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -272,11 +282,14 @@ fn batch_with_root_works() {
|
||||
assert!(!TestBaseCallFilter::filter(&call));
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
assert_eq!(Balances::free_balance(2), 10);
|
||||
assert_ok!(Utility::batch(Origin::root(), vec![
|
||||
Call::Balances(BalancesCall::force_transfer(1, 2, 5)),
|
||||
Call::Balances(BalancesCall::force_transfer(1, 2, 5)),
|
||||
call, // Check filters are correctly bypassed
|
||||
]));
|
||||
assert_ok!(Utility::batch(
|
||||
Origin::root(),
|
||||
vec![
|
||||
Call::Balances(BalancesCall::force_transfer(1, 2, 5)),
|
||||
Call::Balances(BalancesCall::force_transfer(1, 2, 5)),
|
||||
call, // Check filters are correctly bypassed
|
||||
]
|
||||
));
|
||||
assert_eq!(Balances::free_balance(1), 0);
|
||||
assert_eq!(Balances::free_balance(2), 20);
|
||||
assert_eq!(storage::unhashed::get_raw(&k), Some(k));
|
||||
@@ -288,12 +301,13 @@ fn batch_with_signed_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
assert_eq!(Balances::free_balance(2), 10);
|
||||
assert_ok!(
|
||||
Utility::batch(Origin::signed(1), vec![
|
||||
assert_ok!(Utility::batch(
|
||||
Origin::signed(1),
|
||||
vec![
|
||||
Call::Balances(BalancesCall::transfer(2, 5)),
|
||||
Call::Balances(BalancesCall::transfer(2, 5))
|
||||
]),
|
||||
);
|
||||
]
|
||||
),);
|
||||
assert_eq!(Balances::free_balance(1), 0);
|
||||
assert_eq!(Balances::free_balance(2), 20);
|
||||
});
|
||||
@@ -302,12 +316,13 @@ fn batch_with_signed_works() {
|
||||
#[test]
|
||||
fn batch_with_signed_filters() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(
|
||||
Utility::batch(Origin::signed(1), vec![
|
||||
Call::Balances(pallet_balances::Call::transfer_keep_alive(2, 1))
|
||||
]),
|
||||
assert_ok!(Utility::batch(
|
||||
Origin::signed(1),
|
||||
vec![Call::Balances(pallet_balances::Call::transfer_keep_alive(2, 1))]
|
||||
),);
|
||||
System::assert_last_event(
|
||||
utility::Event::BatchInterrupted(0, DispatchError::BadOrigin).into(),
|
||||
);
|
||||
System::assert_last_event(utility::Event::BatchInterrupted(0, DispatchError::BadOrigin).into());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -316,13 +331,14 @@ fn batch_early_exit_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
assert_eq!(Balances::free_balance(2), 10);
|
||||
assert_ok!(
|
||||
Utility::batch(Origin::signed(1), vec![
|
||||
assert_ok!(Utility::batch(
|
||||
Origin::signed(1),
|
||||
vec![
|
||||
Call::Balances(BalancesCall::transfer(2, 5)),
|
||||
Call::Balances(BalancesCall::transfer(2, 10)),
|
||||
Call::Balances(BalancesCall::transfer(2, 5)),
|
||||
]),
|
||||
);
|
||||
]
|
||||
),);
|
||||
assert_eq!(Balances::free_balance(1), 5);
|
||||
assert_eq!(Balances::free_balance(2), 15);
|
||||
});
|
||||
@@ -381,7 +397,9 @@ fn batch_handles_weight_refund() {
|
||||
let info = call.get_dispatch_info();
|
||||
let result = call.dispatch(Origin::signed(1));
|
||||
assert_ok!(result);
|
||||
System::assert_last_event(utility::Event::BatchInterrupted(1, DispatchError::Other("")).into());
|
||||
System::assert_last_event(
|
||||
utility::Event::BatchInterrupted(1, DispatchError::Other("")).into(),
|
||||
);
|
||||
// No weight is refunded
|
||||
assert_eq!(extract_actual_weight(&result, &info), info.weight);
|
||||
|
||||
@@ -394,7 +412,9 @@ fn batch_handles_weight_refund() {
|
||||
let info = call.get_dispatch_info();
|
||||
let result = call.dispatch(Origin::signed(1));
|
||||
assert_ok!(result);
|
||||
System::assert_last_event(utility::Event::BatchInterrupted(1, DispatchError::Other("")).into());
|
||||
System::assert_last_event(
|
||||
utility::Event::BatchInterrupted(1, DispatchError::Other("")).into(),
|
||||
);
|
||||
assert_eq!(extract_actual_weight(&result, &info), info.weight - diff * batch_len);
|
||||
|
||||
// Partial batch completion
|
||||
@@ -405,7 +425,9 @@ fn batch_handles_weight_refund() {
|
||||
let info = call.get_dispatch_info();
|
||||
let result = call.dispatch(Origin::signed(1));
|
||||
assert_ok!(result);
|
||||
System::assert_last_event(utility::Event::BatchInterrupted(1, DispatchError::Other("")).into());
|
||||
System::assert_last_event(
|
||||
utility::Event::BatchInterrupted(1, DispatchError::Other("")).into(),
|
||||
);
|
||||
assert_eq!(
|
||||
extract_actual_weight(&result, &info),
|
||||
// Real weight is 2 calls at end_weight
|
||||
@@ -419,12 +441,13 @@ fn batch_all_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
assert_eq!(Balances::free_balance(2), 10);
|
||||
assert_ok!(
|
||||
Utility::batch_all(Origin::signed(1), vec![
|
||||
assert_ok!(Utility::batch_all(
|
||||
Origin::signed(1),
|
||||
vec![
|
||||
Call::Balances(BalancesCall::transfer(2, 5)),
|
||||
Call::Balances(BalancesCall::transfer(2, 5))
|
||||
]),
|
||||
);
|
||||
]
|
||||
),);
|
||||
assert_eq!(Balances::free_balance(1), 0);
|
||||
assert_eq!(Balances::free_balance(2), 20);
|
||||
});
|
||||
@@ -439,14 +462,19 @@ fn batch_all_revert() {
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
assert_eq!(Balances::free_balance(2), 10);
|
||||
assert_noop!(
|
||||
Utility::batch_all(Origin::signed(1), vec![
|
||||
Call::Balances(BalancesCall::transfer(2, 5)),
|
||||
Call::Balances(BalancesCall::transfer(2, 10)),
|
||||
Call::Balances(BalancesCall::transfer(2, 5)),
|
||||
]),
|
||||
Utility::batch_all(
|
||||
Origin::signed(1),
|
||||
vec![
|
||||
Call::Balances(BalancesCall::transfer(2, 5)),
|
||||
Call::Balances(BalancesCall::transfer(2, 10)),
|
||||
Call::Balances(BalancesCall::transfer(2, 5)),
|
||||
]
|
||||
),
|
||||
DispatchErrorWithPostInfo {
|
||||
post_info: PostDispatchInfo {
|
||||
actual_weight: Some(<Test as Config>::WeightInfo::batch_all(2) + info.weight * 2),
|
||||
actual_weight: Some(
|
||||
<Test as Config>::WeightInfo::batch_all(2) + info.weight * 2
|
||||
),
|
||||
pays_fee: Pays::Yes
|
||||
},
|
||||
error: pallet_balances::Error::<Test, _>::InsufficientBalance.into()
|
||||
@@ -525,15 +553,11 @@ fn batch_all_handles_weight_refund() {
|
||||
#[test]
|
||||
fn batch_all_does_not_nest() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let batch_all = Call::Utility(
|
||||
UtilityCall::batch_all(
|
||||
vec![
|
||||
Call::Balances(BalancesCall::transfer(2, 1)),
|
||||
Call::Balances(BalancesCall::transfer(2, 1)),
|
||||
Call::Balances(BalancesCall::transfer(2, 1)),
|
||||
]
|
||||
)
|
||||
);
|
||||
let batch_all = Call::Utility(UtilityCall::batch_all(vec![
|
||||
Call::Balances(BalancesCall::transfer(2, 1)),
|
||||
Call::Balances(BalancesCall::transfer(2, 1)),
|
||||
Call::Balances(BalancesCall::transfer(2, 1)),
|
||||
]));
|
||||
|
||||
let info = batch_all.get_dispatch_info();
|
||||
|
||||
@@ -557,7 +581,9 @@ fn batch_all_does_not_nest() {
|
||||
// Batch will end with `Ok`, but does not actually execute as we can see from the event
|
||||
// and balances.
|
||||
assert_ok!(Utility::batch_all(Origin::signed(1), vec![batch_nested]));
|
||||
System::assert_has_event(utility::Event::BatchInterrupted(0, DispatchError::BadOrigin).into());
|
||||
System::assert_has_event(
|
||||
utility::Event::BatchInterrupted(0, DispatchError::BadOrigin).into(),
|
||||
);
|
||||
assert_eq!(Balances::free_balance(1), 10);
|
||||
assert_eq!(Balances::free_balance(2), 10);
|
||||
});
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
// --template=./.maintain/frame-weight-template.hbs
|
||||
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user