This repository was archived by the owner on Nov 15, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed
Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -3019,7 +3019,10 @@ fn gas_estimation_call_runtime() {
30193019
30203020 // Call something trivial with a huge gas limit so that we can observe the effects
30213021 // of pre-charging. This should create a difference between consumed and required.
3022- let call = RuntimeCall :: Dummy ( pallet_dummy:: Call :: overestimate_pre_charge { } ) ;
3022+ let call = RuntimeCall :: Dummy ( pallet_dummy:: Call :: overestimate_pre_charge {
3023+ pre_charge : Weight :: from_parts ( 10_000_000 , 0 ) ,
3024+ actual_weight : Weight :: from_parts ( 100 , 0 ) ,
3025+ } ) ;
30233026 let result = Contracts :: bare_call (
30243027 ALICE ,
30253028 addr_caller. clone ( ) ,
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ pub use pallet::*;
44pub mod pallet {
55 use frame_support:: {
66 dispatch:: { Pays , PostDispatchInfo } ,
7+ ensure,
78 pallet_prelude:: DispatchResultWithPostInfo ,
89 weights:: Weight ,
910 } ;
@@ -21,13 +22,15 @@ pub mod pallet {
2122 /// values of [`ContractResult::gas_consumed`] and [`ContractResult::gas_required`] in
2223 /// tests.
2324 #[ pallet:: call_index( 1 ) ]
24- #[ pallet:: weight( Weight :: from_parts( 10_000_000 , 0 ) ) ]
25- pub fn overestimate_pre_charge ( origin : OriginFor < T > ) -> DispatchResultWithPostInfo {
25+ #[ pallet:: weight( * pre_charge) ]
26+ pub fn overestimate_pre_charge (
27+ origin : OriginFor < T > ,
28+ pre_charge : Weight ,
29+ actual_weight : Weight ,
30+ ) -> DispatchResultWithPostInfo {
2631 ensure_signed ( origin) ?;
27- Ok ( PostDispatchInfo {
28- actual_weight : Some ( Weight :: from_parts ( 100 , 0 ) ) ,
29- pays_fee : Pays :: Yes ,
30- } )
32+ ensure ! ( pre_charge. any_gt( actual_weight) , "pre_charge must be > actual_weight" ) ;
33+ Ok ( PostDispatchInfo { actual_weight : Some ( actual_weight) , pays_fee : Pays :: Yes } )
3134 }
3235 }
3336}
You can’t perform that action at this time.
0 commit comments