mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 20:48:02 +00:00
Weight annotation for block hooks. (#4058)
* Initial version that works with proper tests. * get rid of todos and grumbles and such. * Cleanup and fix line-width * fix test runtime test
This commit is contained in:
@@ -697,6 +697,7 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -717,4 +718,36 @@ mod tests {
|
||||
let x = SubmitTransaction::default();
|
||||
is_submit_signed_transaction(x);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_hooks_weight_should_not_exceed_limits() {
|
||||
use sr_primitives::weights::WeighBlock;
|
||||
let check_for_block = |b| {
|
||||
let block_hooks_weight =
|
||||
<AllModules as WeighBlock<BlockNumber>>::on_initialize(b) +
|
||||
<AllModules as WeighBlock<BlockNumber>>::on_finalize(b);
|
||||
|
||||
assert_eq!(
|
||||
block_hooks_weight,
|
||||
0,
|
||||
"This test might fail simply because the value being compared to has increased to a \
|
||||
module declaring a new weight for a hook or call. In this case update the test and \
|
||||
happily move on.",
|
||||
);
|
||||
|
||||
// Invariant. Always must be like this to have a sane chain.
|
||||
assert!(block_hooks_weight < MaximumBlockWeight::get());
|
||||
|
||||
// Warning.
|
||||
if block_hooks_weight > MaximumBlockWeight::get() / 2 {
|
||||
println!(
|
||||
"block hooks weight is consuming more than a block's capacity. You probably want \
|
||||
to re-think this. This test will fail now."
|
||||
);
|
||||
assert!(false);
|
||||
}
|
||||
};
|
||||
|
||||
let _ = (0..100_000).for_each(check_for_block);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user