Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3019,7 +3019,10 @@ fn gas_estimation_call_runtime() {

// Call something trivial with a huge gas limit so that we can observe the effects
// of pre-charging. This should create a difference between consumed and required.
let call = RuntimeCall::Dummy(pallet_dummy::Call::overestimate_pre_charge {});
let call = RuntimeCall::Dummy(pallet_dummy::Call::overestimate_pre_charge {
pre_charge: Weight::from_parts(10_000_000, 0),
actual_weight: Weight::from_parts(100, 0),
});
let result = Contracts::bare_call(
ALICE,
addr_caller.clone(),
Expand Down
15 changes: 9 additions & 6 deletions frame/contracts/src/tests/pallet_dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub use pallet::*;
pub mod pallet {
use frame_support::{
dispatch::{Pays, PostDispatchInfo},
ensure,
pallet_prelude::DispatchResultWithPostInfo,
weights::Weight,
};
Expand All @@ -21,13 +22,15 @@ pub mod pallet {
/// values of [`ContractResult::gas_consumed`] and [`ContractResult::gas_required`] in
/// tests.
#[pallet::call_index(1)]
#[pallet::weight(Weight::from_parts(10_000_000, 0))]
pub fn overestimate_pre_charge(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
#[pallet::weight(*pre_charge)]
pub fn overestimate_pre_charge(
origin: OriginFor<T>,
pre_charge: Weight,
actual_weight: Weight,
) -> DispatchResultWithPostInfo {
ensure_signed(origin)?;
Ok(PostDispatchInfo {
actual_weight: Some(Weight::from_parts(100, 0)),
pays_fee: Pays::Yes,
})
ensure!(pre_charge.any_gt(actual_weight), "pre_charge must be > actual_weight");
Ok(PostDispatchInfo { actual_weight: Some(actual_weight), pays_fee: Pays::Yes })
}
}
}