mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 02:21:14 +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:
@@ -116,25 +116,26 @@
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use sp_std::{prelude::*, marker::PhantomData};
|
||||
use frame_support::{
|
||||
weights::{GetDispatchInfo, DispatchInfo, DispatchClass},
|
||||
traits::{
|
||||
OnInitialize, OnIdle, OnFinalize, OnRuntimeUpgrade, OffchainWorker, ExecuteBlock,
|
||||
EnsureInherentsAreFirst,
|
||||
},
|
||||
dispatch::PostDispatchInfo,
|
||||
};
|
||||
use sp_runtime::{
|
||||
generic::Digest, ApplyExtrinsicResult,
|
||||
traits::{
|
||||
self, Header, Zero, One, Checkable, Applyable, CheckEqual, ValidateUnsigned, NumberFor,
|
||||
Dispatchable, Saturating,
|
||||
},
|
||||
transaction_validity::{TransactionValidity, TransactionSource},
|
||||
};
|
||||
use codec::{Codec, Encode};
|
||||
use frame_support::{
|
||||
dispatch::PostDispatchInfo,
|
||||
traits::{
|
||||
EnsureInherentsAreFirst, ExecuteBlock, OffchainWorker, OnFinalize, OnIdle, OnInitialize,
|
||||
OnRuntimeUpgrade,
|
||||
},
|
||||
weights::{DispatchClass, DispatchInfo, GetDispatchInfo},
|
||||
};
|
||||
use frame_system::DigestOf;
|
||||
use sp_runtime::{
|
||||
generic::Digest,
|
||||
traits::{
|
||||
self, Applyable, CheckEqual, Checkable, Dispatchable, Header, NumberFor, One, Saturating,
|
||||
ValidateUnsigned, Zero,
|
||||
},
|
||||
transaction_validity::{TransactionSource, TransactionValidity},
|
||||
ApplyExtrinsicResult,
|
||||
};
|
||||
use sp_std::{marker::PhantomData, prelude::*};
|
||||
|
||||
pub type CheckedOf<E, C> = <E as Checkable<C>>::Checked;
|
||||
pub type CallOf<E, C> = <CheckedOf<E, C> as Applyable>::Call;
|
||||
@@ -152,31 +153,29 @@ pub type OriginOf<E, C> = <CallOf<E, C> as Dispatchable>::Origin;
|
||||
/// already called by `AllPallets`. It will be called before all modules will
|
||||
/// be called.
|
||||
pub struct Executive<System, Block, Context, UnsignedValidator, AllPallets, OnRuntimeUpgrade = ()>(
|
||||
PhantomData<(System, Block, Context, UnsignedValidator, AllPallets, OnRuntimeUpgrade)>
|
||||
PhantomData<(System, Block, Context, UnsignedValidator, AllPallets, OnRuntimeUpgrade)>,
|
||||
);
|
||||
|
||||
impl<
|
||||
System: frame_system::Config + EnsureInherentsAreFirst<Block>,
|
||||
Block: traits::Block<Header=System::Header, Hash=System::Hash>,
|
||||
Context: Default,
|
||||
UnsignedValidator,
|
||||
AllPallets:
|
||||
OnRuntimeUpgrade +
|
||||
OnInitialize<System::BlockNumber> +
|
||||
OnIdle<System::BlockNumber> +
|
||||
OnFinalize<System::BlockNumber> +
|
||||
OffchainWorker<System::BlockNumber>,
|
||||
COnRuntimeUpgrade: OnRuntimeUpgrade,
|
||||
> ExecuteBlock<Block> for
|
||||
Executive<System, Block, Context, UnsignedValidator, AllPallets, COnRuntimeUpgrade>
|
||||
System: frame_system::Config + EnsureInherentsAreFirst<Block>,
|
||||
Block: traits::Block<Header = System::Header, Hash = System::Hash>,
|
||||
Context: Default,
|
||||
UnsignedValidator,
|
||||
AllPallets: OnRuntimeUpgrade
|
||||
+ OnInitialize<System::BlockNumber>
|
||||
+ OnIdle<System::BlockNumber>
|
||||
+ OnFinalize<System::BlockNumber>
|
||||
+ OffchainWorker<System::BlockNumber>,
|
||||
COnRuntimeUpgrade: OnRuntimeUpgrade,
|
||||
> ExecuteBlock<Block>
|
||||
for Executive<System, Block, Context, UnsignedValidator, AllPallets, COnRuntimeUpgrade>
|
||||
where
|
||||
Block::Extrinsic: Checkable<Context> + Codec,
|
||||
CheckedOf<Block::Extrinsic, Context>:
|
||||
Applyable +
|
||||
GetDispatchInfo,
|
||||
CallOf<Block::Extrinsic, Context>: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo>,
|
||||
CheckedOf<Block::Extrinsic, Context>: Applyable + GetDispatchInfo,
|
||||
CallOf<Block::Extrinsic, Context>:
|
||||
Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
|
||||
OriginOf<Block::Extrinsic, Context>: From<Option<System::AccountId>>,
|
||||
UnsignedValidator: ValidateUnsigned<Call=CallOf<Block::Extrinsic, Context>>,
|
||||
UnsignedValidator: ValidateUnsigned<Call = CallOf<Block::Extrinsic, Context>>,
|
||||
{
|
||||
fn execute_block(block: Block) {
|
||||
Executive::<
|
||||
@@ -249,20 +248,16 @@ where
|
||||
sp_io::init_tracing();
|
||||
sp_tracing::enter_span!(sp_tracing::Level::TRACE, "init_block");
|
||||
let digests = Self::extract_pre_digest(&header);
|
||||
Self::initialize_block_impl(
|
||||
header.number(),
|
||||
header.parent_hash(),
|
||||
&digests
|
||||
);
|
||||
Self::initialize_block_impl(header.number(), header.parent_hash(), &digests);
|
||||
}
|
||||
|
||||
fn extract_pre_digest(header: &System::Header) -> DigestOf<System> {
|
||||
let mut digest = <DigestOf<System>>::default();
|
||||
header.digest().logs()
|
||||
.iter()
|
||||
.for_each(|d| if d.as_pre_runtime().is_some() {
|
||||
header.digest().logs().iter().for_each(|d| {
|
||||
if d.as_pre_runtime().is_some() {
|
||||
digest.push(d.clone())
|
||||
});
|
||||
}
|
||||
});
|
||||
digest
|
||||
}
|
||||
|
||||
@@ -281,16 +276,19 @@ where
|
||||
digest,
|
||||
frame_system::InitKind::Full,
|
||||
);
|
||||
weight = weight.saturating_add(<frame_system::Pallet<System> as OnInitialize<
|
||||
System::BlockNumber,
|
||||
>>::on_initialize(*block_number));
|
||||
weight = weight.saturating_add(
|
||||
<frame_system::Pallet<System> as OnInitialize<System::BlockNumber>>::on_initialize(*block_number)
|
||||
<AllPallets as OnInitialize<System::BlockNumber>>::on_initialize(*block_number),
|
||||
);
|
||||
weight = weight.saturating_add(
|
||||
<AllPallets as OnInitialize<System::BlockNumber>>::on_initialize(*block_number)
|
||||
<System::BlockWeights as frame_support::traits::Get<_>>::get().base_block,
|
||||
);
|
||||
weight = weight.saturating_add(
|
||||
<System::BlockWeights as frame_support::traits::Get<_>>::get().base_block
|
||||
<frame_system::Pallet<System>>::register_extra_weight_unchecked(
|
||||
weight,
|
||||
DispatchClass::Mandatory,
|
||||
);
|
||||
<frame_system::Pallet::<System>>::register_extra_weight_unchecked(weight, DispatchClass::Mandatory);
|
||||
|
||||
frame_system::Pallet::<System>::note_finished_initialize();
|
||||
}
|
||||
@@ -317,8 +315,9 @@ where
|
||||
// Check that `parent_hash` is correct.
|
||||
let n = header.number().clone();
|
||||
assert!(
|
||||
n > System::BlockNumber::zero()
|
||||
&& <frame_system::Pallet<System>>::block_hash(n - System::BlockNumber::one()) == *header.parent_hash(),
|
||||
n > System::BlockNumber::zero() &&
|
||||
<frame_system::Pallet<System>>::block_hash(n - System::BlockNumber::one()) ==
|
||||
*header.parent_hash(),
|
||||
"Parent hash should be valid.",
|
||||
);
|
||||
|
||||
@@ -358,9 +357,11 @@ where
|
||||
extrinsics: Vec<Block::Extrinsic>,
|
||||
block_number: NumberFor<Block>,
|
||||
) {
|
||||
extrinsics.into_iter().for_each(|e| if let Err(e) = Self::apply_extrinsic(e) {
|
||||
let err: &'static str = e.into();
|
||||
panic!("{}", err)
|
||||
extrinsics.into_iter().for_each(|e| {
|
||||
if let Err(e) = Self::apply_extrinsic(e) {
|
||||
let err: &'static str = e.into();
|
||||
panic!("{}", err)
|
||||
}
|
||||
});
|
||||
|
||||
// post-extrinsics book-keeping
|
||||
@@ -373,7 +374,7 @@ where
|
||||
/// except state-root.
|
||||
pub fn finalize_block() -> System::Header {
|
||||
sp_io::init_tracing();
|
||||
sp_tracing::enter_span!( sp_tracing::Level::TRACE, "finalize_block" );
|
||||
sp_tracing::enter_span!(sp_tracing::Level::TRACE, "finalize_block");
|
||||
<frame_system::Pallet<System>>::note_finished_extrinsics();
|
||||
let block_number = <frame_system::Pallet<System>>::block_number();
|
||||
|
||||
@@ -383,26 +384,31 @@ where
|
||||
}
|
||||
|
||||
fn idle_and_finalize_hook(block_number: NumberFor<Block>) {
|
||||
let weight = <frame_system::Pallet<System>>::block_weight();
|
||||
let max_weight = <System::BlockWeights as frame_support::traits::Get<_>>::get().max_block;
|
||||
let weight = <frame_system::Pallet<System>>::block_weight();
|
||||
let max_weight = <System::BlockWeights as frame_support::traits::Get<_>>::get().max_block;
|
||||
let mut remaining_weight = max_weight.saturating_sub(weight.total());
|
||||
|
||||
if remaining_weight > 0 {
|
||||
let mut used_weight =
|
||||
<frame_system::Pallet<System> as OnIdle<System::BlockNumber>>::on_idle(
|
||||
block_number,
|
||||
remaining_weight
|
||||
remaining_weight,
|
||||
);
|
||||
remaining_weight = remaining_weight.saturating_sub(used_weight);
|
||||
used_weight = <AllPallets as OnIdle<System::BlockNumber>>::on_idle(
|
||||
block_number,
|
||||
remaining_weight
|
||||
remaining_weight,
|
||||
)
|
||||
.saturating_add(used_weight);
|
||||
<frame_system::Pallet::<System>>::register_extra_weight_unchecked(used_weight, DispatchClass::Mandatory);
|
||||
<frame_system::Pallet<System>>::register_extra_weight_unchecked(
|
||||
used_weight,
|
||||
DispatchClass::Mandatory,
|
||||
);
|
||||
}
|
||||
|
||||
<frame_system::Pallet<System> as OnFinalize<System::BlockNumber>>::on_finalize(block_number);
|
||||
<frame_system::Pallet<System> as OnFinalize<System::BlockNumber>>::on_finalize(
|
||||
block_number,
|
||||
);
|
||||
<AllPallets as OnFinalize<System::BlockNumber>>::on_finalize(block_number);
|
||||
}
|
||||
|
||||
@@ -423,10 +429,8 @@ where
|
||||
encoded_len: usize,
|
||||
to_note: Vec<u8>,
|
||||
) -> ApplyExtrinsicResult {
|
||||
sp_tracing::enter_span!(
|
||||
sp_tracing::info_span!("apply_extrinsic",
|
||||
ext=?sp_core::hexdisplay::HexDisplay::from(&uxt.encode()))
|
||||
);
|
||||
sp_tracing::enter_span!(sp_tracing::info_span!("apply_extrinsic",
|
||||
ext=?sp_core::hexdisplay::HexDisplay::from(&uxt.encode())));
|
||||
// Verify that the signature is good.
|
||||
let xt = uxt.check(&Default::default())?;
|
||||
|
||||
@@ -493,17 +497,17 @@ where
|
||||
frame_system::InitKind::Inspection,
|
||||
);
|
||||
|
||||
enter_span!{ sp_tracing::Level::TRACE, "validate_transaction" };
|
||||
enter_span! { sp_tracing::Level::TRACE, "validate_transaction" };
|
||||
|
||||
let encoded_len = within_span!{ sp_tracing::Level::TRACE, "using_encoded";
|
||||
let encoded_len = within_span! { sp_tracing::Level::TRACE, "using_encoded";
|
||||
uxt.using_encoded(|d| d.len())
|
||||
};
|
||||
|
||||
let xt = within_span!{ sp_tracing::Level::TRACE, "check";
|
||||
let xt = within_span! { sp_tracing::Level::TRACE, "check";
|
||||
uxt.check(&Default::default())
|
||||
}?;
|
||||
|
||||
let dispatch_info = within_span!{ sp_tracing::Level::TRACE, "dispatch_info";
|
||||
let dispatch_info = within_span! { sp_tracing::Level::TRACE, "dispatch_info";
|
||||
xt.get_dispatch_info()
|
||||
};
|
||||
|
||||
@@ -537,35 +541,34 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
generic::{Era, DigestItem}, DispatchError, testing::{Digest, Header, Block},
|
||||
traits::{Header as HeaderT, BlakeTwo256, IdentityLookup, Block as BlockT},
|
||||
transaction_validity::{
|
||||
InvalidTransaction, ValidTransaction, TransactionValidityError, UnknownTransaction
|
||||
},
|
||||
};
|
||||
use frame_support::{
|
||||
assert_err, parameter_types,
|
||||
weights::{Weight, RuntimeDbWeight, IdentityFee, WeightToFeePolynomial},
|
||||
traits::{Currency, LockIdentifier, LockableCurrency, WithdrawReasons},
|
||||
weights::{IdentityFee, RuntimeDbWeight, Weight, WeightToFeePolynomial},
|
||||
};
|
||||
use frame_system::{
|
||||
Call as SystemCall, ChainContext, LastRuntimeUpgradeInfo,
|
||||
};
|
||||
use pallet_transaction_payment::CurrencyAdapter;
|
||||
use pallet_balances::Call as BalancesCall;
|
||||
use frame_system::{Call as SystemCall, ChainContext, LastRuntimeUpgradeInfo};
|
||||
use hex_literal::hex;
|
||||
use pallet_balances::Call as BalancesCall;
|
||||
use pallet_transaction_payment::CurrencyAdapter;
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
generic::{DigestItem, Era},
|
||||
testing::{Block, Digest, Header},
|
||||
traits::{BlakeTwo256, Block as BlockT, Header as HeaderT, IdentityLookup},
|
||||
transaction_validity::{
|
||||
InvalidTransaction, TransactionValidityError, UnknownTransaction, ValidTransaction,
|
||||
},
|
||||
DispatchError,
|
||||
};
|
||||
const TEST_KEY: &[u8] = &*b":test:key:";
|
||||
|
||||
mod custom {
|
||||
use frame_support::weights::{Weight, DispatchClass};
|
||||
use frame_support::weights::{DispatchClass, Weight};
|
||||
use sp_runtime::transaction_validity::{
|
||||
UnknownTransaction, TransactionSource, TransactionValidity, TransactionValidityError,
|
||||
TransactionSource, TransactionValidity, TransactionValidityError, UnknownTransaction,
|
||||
};
|
||||
|
||||
pub trait Config: frame_system::Config {}
|
||||
@@ -658,13 +661,10 @@ mod tests {
|
||||
Call::allowed_unsigned(..) => Ok(Default::default()),
|
||||
_ => UnknownTransaction::NoUnsignedValidator.into(),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Inherent call is accepted for being dispatched
|
||||
fn pre_dispatch(
|
||||
call: &Self::Call,
|
||||
) -> Result<(), TransactionValidityError> {
|
||||
fn pre_dispatch(call: &Self::Call) -> Result<(), TransactionValidityError> {
|
||||
match call {
|
||||
Call::allowed_unsigned(..) => Ok(()),
|
||||
Call::inherent_call(..) => Ok(()),
|
||||
@@ -793,7 +793,7 @@ mod tests {
|
||||
ChainContext<Runtime>,
|
||||
Runtime,
|
||||
AllPallets,
|
||||
CustomOnRuntimeUpgrade
|
||||
CustomOnRuntimeUpgrade,
|
||||
>;
|
||||
|
||||
fn extra(nonce: u64, fee: Balance) -> SignedExtra {
|
||||
@@ -801,7 +801,7 @@ mod tests {
|
||||
frame_system::CheckEra::from(Era::Immortal),
|
||||
frame_system::CheckNonce::from(nonce),
|
||||
frame_system::CheckWeight::new(),
|
||||
pallet_transaction_payment::ChargeTransactionPayment::from(fee)
|
||||
pallet_transaction_payment::ChargeTransactionPayment::from(fee),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -812,14 +812,16 @@ mod tests {
|
||||
#[test]
|
||||
fn balance_transfer_dispatch_works() {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
|
||||
pallet_balances::GenesisConfig::<Runtime> {
|
||||
balances: vec![(1, 211)],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
pallet_balances::GenesisConfig::<Runtime> { balances: vec![(1, 211)] }
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
let xt = TestXt::new(Call::Balances(BalancesCall::transfer(2, 69)), sign_extra(1, 0, 0));
|
||||
let weight = xt.get_dispatch_info().weight +
|
||||
<Runtime as frame_system::Config>::BlockWeights::get().get(DispatchClass::Normal).base_extrinsic;
|
||||
let fee: Balance
|
||||
= <Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(&weight);
|
||||
<Runtime as frame_system::Config>::BlockWeights::get()
|
||||
.get(DispatchClass::Normal)
|
||||
.base_extrinsic;
|
||||
let fee: Balance =
|
||||
<Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(&weight);
|
||||
let mut t = sp_io::TestExternalities::new(t);
|
||||
t.execute_with(|| {
|
||||
Executive::initialize_block(&Header::new(
|
||||
@@ -838,9 +840,9 @@ mod tests {
|
||||
|
||||
fn new_test_ext(balance_factor: Balance) -> sp_io::TestExternalities {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
|
||||
pallet_balances::GenesisConfig::<Runtime> {
|
||||
balances: vec![(1, 111 * balance_factor)],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
pallet_balances::GenesisConfig::<Runtime> { balances: vec![(1, 111 * balance_factor)] }
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
t.into()
|
||||
}
|
||||
|
||||
@@ -851,9 +853,15 @@ mod tests {
|
||||
header: Header {
|
||||
parent_hash: [69u8; 32].into(),
|
||||
number: 1,
|
||||
state_root: hex!("1039e1a4bd0cf5deefe65f313577e70169c41c7773d6acf31ca8d671397559f5").into(),
|
||||
extrinsics_root: hex!("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314").into(),
|
||||
digest: Digest { logs: vec![], },
|
||||
state_root: hex!(
|
||||
"1039e1a4bd0cf5deefe65f313577e70169c41c7773d6acf31ca8d671397559f5"
|
||||
)
|
||||
.into(),
|
||||
extrinsics_root: hex!(
|
||||
"03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314"
|
||||
)
|
||||
.into(),
|
||||
digest: Digest { logs: vec![] },
|
||||
},
|
||||
extrinsics: vec![],
|
||||
});
|
||||
@@ -869,8 +877,11 @@ mod tests {
|
||||
parent_hash: [69u8; 32].into(),
|
||||
number: 1,
|
||||
state_root: [0u8; 32].into(),
|
||||
extrinsics_root: hex!("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314").into(),
|
||||
digest: Digest { logs: vec![], },
|
||||
extrinsics_root: hex!(
|
||||
"03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314"
|
||||
)
|
||||
.into(),
|
||||
digest: Digest { logs: vec![] },
|
||||
},
|
||||
extrinsics: vec![],
|
||||
});
|
||||
@@ -885,9 +896,12 @@ mod tests {
|
||||
header: Header {
|
||||
parent_hash: [69u8; 32].into(),
|
||||
number: 1,
|
||||
state_root: hex!("49cd58a254ccf6abc4a023d9a22dcfc421e385527a250faec69f8ad0d8ed3e48").into(),
|
||||
state_root: hex!(
|
||||
"49cd58a254ccf6abc4a023d9a22dcfc421e385527a250faec69f8ad0d8ed3e48"
|
||||
)
|
||||
.into(),
|
||||
extrinsics_root: [0u8; 32].into(),
|
||||
digest: Digest { logs: vec![], },
|
||||
digest: Digest { logs: vec![] },
|
||||
},
|
||||
extrinsics: vec![],
|
||||
});
|
||||
@@ -907,7 +921,8 @@ mod tests {
|
||||
[69u8; 32].into(),
|
||||
Digest::default(),
|
||||
));
|
||||
assert_err!(Executive::apply_extrinsic(xt),
|
||||
assert_err!(
|
||||
Executive::apply_extrinsic(xt),
|
||||
TransactionValidityError::Invalid(InvalidTransaction::Future)
|
||||
);
|
||||
assert_eq!(<frame_system::Pallet<Runtime>>::extrinsic_index(), Some(0));
|
||||
@@ -924,8 +939,7 @@ mod tests {
|
||||
// on_initialize weight + base block execution weight
|
||||
let block_weights = <Runtime as frame_system::Config>::BlockWeights::get();
|
||||
let base_block_weight = 175 + block_weights.base_block;
|
||||
let limit = block_weights.get(DispatchClass::Normal).max_total.unwrap()
|
||||
- base_block_weight;
|
||||
let limit = block_weights.get(DispatchClass::Normal).max_total.unwrap() - base_block_weight;
|
||||
let num_to_exhaust_block = limit / (encoded_len + 5);
|
||||
t.execute_with(|| {
|
||||
Executive::initialize_block(&Header::new(
|
||||
@@ -940,7 +954,8 @@ mod tests {
|
||||
|
||||
for nonce in 0..=num_to_exhaust_block {
|
||||
let xt = TestXt::new(
|
||||
Call::Balances(BalancesCall::transfer(33, 0)), sign_extra(1, nonce.into(), 0),
|
||||
Call::Balances(BalancesCall::transfer(33, 0)),
|
||||
sign_extra(1, nonce.into(), 0),
|
||||
);
|
||||
let res = Executive::apply_extrinsic(xt);
|
||||
if nonce != num_to_exhaust_block {
|
||||
@@ -950,7 +965,10 @@ mod tests {
|
||||
//--------------------- on_initialize + block_execution + extrinsic_base weight
|
||||
(encoded_len + 5) * (nonce + 1) + base_block_weight,
|
||||
);
|
||||
assert_eq!(<frame_system::Pallet<Runtime>>::extrinsic_index(), Some(nonce as u32 + 1));
|
||||
assert_eq!(
|
||||
<frame_system::Pallet<Runtime>>::extrinsic_index(),
|
||||
Some(nonce as u32 + 1)
|
||||
);
|
||||
} else {
|
||||
assert_eq!(res, Err(InvalidTransaction::ExhaustsResources.into()));
|
||||
}
|
||||
@@ -967,7 +985,8 @@ mod tests {
|
||||
let mut t = new_test_ext(1);
|
||||
t.execute_with(|| {
|
||||
// Block execution weight + on_initialize weight from custom module
|
||||
let base_block_weight = 175 + <Runtime as frame_system::Config>::BlockWeights::get().base_block;
|
||||
let base_block_weight =
|
||||
175 + <Runtime as frame_system::Config>::BlockWeights::get().base_block;
|
||||
|
||||
Executive::initialize_block(&Header::new(
|
||||
1,
|
||||
@@ -985,8 +1004,10 @@ mod tests {
|
||||
assert!(Executive::apply_extrinsic(x2.clone()).unwrap().is_ok());
|
||||
|
||||
// default weight for `TestXt` == encoded length.
|
||||
let extrinsic_weight = len as Weight + <Runtime as frame_system::Config>::BlockWeights
|
||||
::get().get(DispatchClass::Normal).base_extrinsic;
|
||||
let extrinsic_weight = len as Weight +
|
||||
<Runtime as frame_system::Config>::BlockWeights::get()
|
||||
.get(DispatchClass::Normal)
|
||||
.base_extrinsic;
|
||||
assert_eq!(
|
||||
<frame_system::Pallet<Runtime>>::block_weight().total(),
|
||||
base_block_weight + 3 * extrinsic_weight,
|
||||
@@ -1051,20 +1072,14 @@ mod tests {
|
||||
let mut t = new_test_ext(1);
|
||||
t.execute_with(|| {
|
||||
<pallet_balances::Pallet<Runtime> as LockableCurrency<Balance>>::set_lock(
|
||||
id,
|
||||
&1,
|
||||
110,
|
||||
lock,
|
||||
id, &1, 110, lock,
|
||||
);
|
||||
let xt = TestXt::new(
|
||||
Call::System(SystemCall::remark(vec![1u8])),
|
||||
sign_extra(1, 0, 0),
|
||||
);
|
||||
let weight = xt.get_dispatch_info().weight + <Runtime as frame_system::Config>
|
||||
::BlockWeights
|
||||
::get()
|
||||
.get(DispatchClass::Normal)
|
||||
.base_extrinsic;
|
||||
let xt =
|
||||
TestXt::new(Call::System(SystemCall::remark(vec![1u8])), sign_extra(1, 0, 0));
|
||||
let weight = xt.get_dispatch_info().weight +
|
||||
<Runtime as frame_system::Config>::BlockWeights::get()
|
||||
.get(DispatchClass::Normal)
|
||||
.base_extrinsic;
|
||||
let fee: Balance =
|
||||
<Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(&weight);
|
||||
Executive::initialize_block(&Header::new(
|
||||
@@ -1096,13 +1111,12 @@ mod tests {
|
||||
#[test]
|
||||
fn block_hooks_weight_is_stored() {
|
||||
new_test_ext(1).execute_with(|| {
|
||||
|
||||
Executive::initialize_block(&Header::new_from_number(1));
|
||||
Executive::finalize_block();
|
||||
// NOTE: might need updates over time if new weights are introduced.
|
||||
// For now it only accounts for the base block execution weight and
|
||||
// the `on_initialize` weight defined in the custom test module.
|
||||
assert_eq!(<frame_system::Pallet<Runtime>>::block_weight().total(), 175 + 175 + 10);
|
||||
assert_eq!(<frame_system::Pallet<Runtime>>::block_weight().total(), 175 + 175 + 10);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1114,9 +1128,9 @@ mod tests {
|
||||
assert!(frame_system::LastRuntimeUpgrade::<Runtime>::exists());
|
||||
assert!(!Executive::runtime_upgraded());
|
||||
|
||||
RUNTIME_VERSION.with(|v| *v.borrow_mut() = sp_version::RuntimeVersion {
|
||||
spec_version: 1,
|
||||
..Default::default()
|
||||
RUNTIME_VERSION.with(|v| {
|
||||
*v.borrow_mut() =
|
||||
sp_version::RuntimeVersion { spec_version: 1, ..Default::default() }
|
||||
});
|
||||
assert!(Executive::runtime_upgraded());
|
||||
assert_eq!(
|
||||
@@ -1124,10 +1138,12 @@ mod tests {
|
||||
frame_system::LastRuntimeUpgrade::<Runtime>::get(),
|
||||
);
|
||||
|
||||
RUNTIME_VERSION.with(|v| *v.borrow_mut() = sp_version::RuntimeVersion {
|
||||
spec_version: 1,
|
||||
spec_name: "test".into(),
|
||||
..Default::default()
|
||||
RUNTIME_VERSION.with(|v| {
|
||||
*v.borrow_mut() = sp_version::RuntimeVersion {
|
||||
spec_version: 1,
|
||||
spec_name: "test".into(),
|
||||
..Default::default()
|
||||
}
|
||||
});
|
||||
assert!(Executive::runtime_upgraded());
|
||||
assert_eq!(
|
||||
@@ -1135,11 +1151,13 @@ mod tests {
|
||||
frame_system::LastRuntimeUpgrade::<Runtime>::get(),
|
||||
);
|
||||
|
||||
RUNTIME_VERSION.with(|v| *v.borrow_mut() = sp_version::RuntimeVersion {
|
||||
spec_version: 1,
|
||||
spec_name: "test".into(),
|
||||
impl_version: 2,
|
||||
..Default::default()
|
||||
RUNTIME_VERSION.with(|v| {
|
||||
*v.borrow_mut() = sp_version::RuntimeVersion {
|
||||
spec_version: 1,
|
||||
spec_name: "test".into(),
|
||||
impl_version: 2,
|
||||
..Default::default()
|
||||
}
|
||||
});
|
||||
assert!(!Executive::runtime_upgraded());
|
||||
|
||||
@@ -1182,9 +1200,9 @@ mod tests {
|
||||
fn custom_runtime_upgrade_is_called_before_modules() {
|
||||
new_test_ext(1).execute_with(|| {
|
||||
// Make sure `on_runtime_upgrade` is called.
|
||||
RUNTIME_VERSION.with(|v| *v.borrow_mut() = sp_version::RuntimeVersion {
|
||||
spec_version: 1,
|
||||
..Default::default()
|
||||
RUNTIME_VERSION.with(|v| {
|
||||
*v.borrow_mut() =
|
||||
sp_version::RuntimeVersion { spec_version: 1, ..Default::default() }
|
||||
});
|
||||
|
||||
Executive::initialize_block(&Header::new(
|
||||
@@ -1251,9 +1269,9 @@ mod tests {
|
||||
fn all_weights_are_recorded_correctly() {
|
||||
new_test_ext(1).execute_with(|| {
|
||||
// Make sure `on_runtime_upgrade` is called for maximum complexity
|
||||
RUNTIME_VERSION.with(|v| *v.borrow_mut() = sp_version::RuntimeVersion {
|
||||
spec_version: 1,
|
||||
..Default::default()
|
||||
RUNTIME_VERSION.with(|v| {
|
||||
*v.borrow_mut() =
|
||||
sp_version::RuntimeVersion { spec_version: 1, ..Default::default() }
|
||||
});
|
||||
|
||||
let block_number = 1;
|
||||
@@ -1270,19 +1288,21 @@ mod tests {
|
||||
let frame_system_upgrade_weight = frame_system::Pallet::<Runtime>::on_runtime_upgrade();
|
||||
let custom_runtime_upgrade_weight = CustomOnRuntimeUpgrade::on_runtime_upgrade();
|
||||
let runtime_upgrade_weight = <AllPallets as OnRuntimeUpgrade>::on_runtime_upgrade();
|
||||
let frame_system_on_initialize_weight = frame_system::Pallet::<Runtime>::on_initialize(block_number);
|
||||
let on_initialize_weight = <AllPallets as OnInitialize<u64>>::on_initialize(block_number);
|
||||
let base_block_weight = <Runtime as frame_system::Config>::BlockWeights::get().base_block;
|
||||
let frame_system_on_initialize_weight =
|
||||
frame_system::Pallet::<Runtime>::on_initialize(block_number);
|
||||
let on_initialize_weight =
|
||||
<AllPallets as OnInitialize<u64>>::on_initialize(block_number);
|
||||
let base_block_weight =
|
||||
<Runtime as frame_system::Config>::BlockWeights::get().base_block;
|
||||
|
||||
// Weights are recorded correctly
|
||||
assert_eq!(
|
||||
frame_system::Pallet::<Runtime>::block_weight().total(),
|
||||
frame_system_upgrade_weight +
|
||||
custom_runtime_upgrade_weight +
|
||||
runtime_upgrade_weight +
|
||||
frame_system_on_initialize_weight +
|
||||
on_initialize_weight +
|
||||
base_block_weight,
|
||||
custom_runtime_upgrade_weight +
|
||||
runtime_upgrade_weight +
|
||||
frame_system_on_initialize_weight +
|
||||
on_initialize_weight + base_block_weight,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -1294,13 +1314,8 @@ mod tests {
|
||||
let mut digest = Digest::default();
|
||||
digest.push(DigestItem::Seal([1, 2, 3, 4], vec![5, 6, 7, 8]));
|
||||
|
||||
let header = Header::new(
|
||||
1,
|
||||
H256::default(),
|
||||
H256::default(),
|
||||
parent_hash,
|
||||
digest.clone(),
|
||||
);
|
||||
let header =
|
||||
Header::new(1, H256::default(), H256::default(), parent_hash, digest.clone());
|
||||
|
||||
Executive::offchain_worker(&header);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user