mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 21:01:05 +00:00
Keep BlockWeight in Storage (#6046)
* keep block weight in storage * Update lib.rs * rename to `BlockWeight`, update tests * remove println * make test better * keep extrinsics length clean
This commit is contained in:
@@ -708,7 +708,7 @@ mod tests {
|
||||
header: Header {
|
||||
parent_hash: [69u8; 32].into(),
|
||||
number: 1,
|
||||
state_root: hex!("409fb5a14aeb8b8c59258b503396a56dee45a0ee28a78de3e622db957425e275").into(),
|
||||
state_root: hex!("05a38fa4a48ca80ffa8482304be7749a484dc8c9c31462a570d0fbadde6a3633").into(),
|
||||
extrinsics_root: hex!("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314").into(),
|
||||
digest: Digest { logs: vec![], },
|
||||
},
|
||||
@@ -789,7 +789,7 @@ mod tests {
|
||||
Digest::default(),
|
||||
));
|
||||
// Base block execution weight + `on_initialize` weight from the custom module.
|
||||
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight().total(), base_block_weight);
|
||||
assert_eq!(<frame_system::Module<Runtime>>::block_weight().total(), base_block_weight);
|
||||
|
||||
for nonce in 0..=num_to_exhaust_block {
|
||||
let xt = TestXt::new(
|
||||
@@ -799,7 +799,7 @@ mod tests {
|
||||
if nonce != num_to_exhaust_block {
|
||||
assert!(res.is_ok());
|
||||
assert_eq!(
|
||||
<frame_system::Module<Runtime>>::all_extrinsics_weight().total(),
|
||||
<frame_system::Module<Runtime>>::block_weight().total(),
|
||||
//--------------------- on_initialize + block_execution + extrinsic_base weight
|
||||
(encoded_len + 5) * (nonce + 1) + base_block_weight,
|
||||
);
|
||||
@@ -819,7 +819,18 @@ mod tests {
|
||||
let len = xt.clone().encode().len() as u32;
|
||||
let mut t = new_test_ext(1);
|
||||
t.execute_with(|| {
|
||||
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight().total(), 0);
|
||||
// Block execution weight + on_initialize weight from custom module
|
||||
let base_block_weight = 175 + <Runtime as frame_system::Trait>::BlockExecutionWeight::get();
|
||||
|
||||
Executive::initialize_block(&Header::new(
|
||||
1,
|
||||
H256::default(),
|
||||
H256::default(),
|
||||
[69u8; 32].into(),
|
||||
Digest::default(),
|
||||
));
|
||||
|
||||
assert_eq!(<frame_system::Module<Runtime>>::block_weight().total(), base_block_weight);
|
||||
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_len(), 0);
|
||||
|
||||
assert!(Executive::apply_extrinsic(xt.clone()).unwrap().is_ok());
|
||||
@@ -827,16 +838,28 @@ 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::Trait>::ExtrinsicBaseWeight::get();
|
||||
assert_eq!(
|
||||
<frame_system::Module<Runtime>>::all_extrinsics_weight().total(),
|
||||
3 * (len as Weight + <Runtime as frame_system::Trait>::ExtrinsicBaseWeight::get()),
|
||||
<frame_system::Module<Runtime>>::block_weight().total(),
|
||||
base_block_weight + 3 * extrinsic_weight,
|
||||
);
|
||||
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_len(), 3 * len);
|
||||
|
||||
let _ = <frame_system::Module<Runtime>>::finalize();
|
||||
|
||||
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_weight().total(), 0);
|
||||
// All extrinsics length cleaned on `System::finalize`
|
||||
assert_eq!(<frame_system::Module<Runtime>>::all_extrinsics_len(), 0);
|
||||
|
||||
// New Block
|
||||
Executive::initialize_block(&Header::new(
|
||||
2,
|
||||
H256::default(),
|
||||
H256::default(),
|
||||
[69u8; 32].into(),
|
||||
Digest::default(),
|
||||
));
|
||||
|
||||
// Block weight cleaned up on `System::initialize`
|
||||
assert_eq!(<frame_system::Module<Runtime>>::block_weight().total(), base_block_weight);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -908,7 +931,7 @@ mod tests {
|
||||
// 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::Module<Runtime>>::all_extrinsics_weight().total(), 175 + 10);
|
||||
assert_eq!(<frame_system::Module<Runtime>>::block_weight().total(), 175 + 10);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user