Skip to content
Snippets Groups Projects
Unverified Commit d4b01add authored by PG Herveou's avatar PG Herveou Committed by GitHub
Browse files

[pallet-revive] fix hardcoded gas in tests (#6192)


Fix hardcoded gas limits in tests

---------

Co-authored-by: default avatarGitHub Action <action@github.com>
parent 2324bd7b
Branches
No related merge requests found
Pipeline #502682 waiting for manual action with stages
in 49 minutes and 48 seconds
title: '[pallet-revive] fix hardcoded gas in tests'
doc:
- audience: Runtime Dev
description: Fix hardcoded gas limits in tests
crates:
- name: pallet-revive
bump: patch
......@@ -356,12 +356,7 @@ pub trait EthExtra {
Default::default(),
)
.into();
log::debug!(target: LOG_TARGET, "Checking Ethereum transaction fees:
dispatch_info: {info:?}
encoded_len: {encoded_len:?}
fees: {actual_fee:?}
");
log::debug!(target: LOG_TARGET, "try_into_checked_extrinsic: encoded_len: {encoded_len:?} actual_fee: {actual_fee:?} eth_fee: {eth_fee:?}");
if eth_fee < actual_fee {
log::debug!(target: LOG_TARGET, "fees {eth_fee:?} too low for the extrinsic {actual_fee:?}");
......@@ -490,11 +485,30 @@ mod test {
}
}
fn estimate_gas(&mut self) {
let dry_run = crate::Pallet::<Test>::bare_eth_transact(
Account::default().account_id(),
self.tx.to,
self.tx.value.try_into().unwrap(),
self.tx.input.clone().0,
Weight::MAX,
u64::MAX,
|call| {
let call = RuntimeCall::Contracts(call);
let uxt: Ex = sp_runtime::generic::UncheckedExtrinsic::new_bare(call).into();
uxt.encoded_size() as u32
},
crate::DebugInfo::Skip,
crate::CollectEvents::Skip,
);
self.tx.gas = ((dry_run.fee + GAS_PRICE as u64) / (GAS_PRICE as u64)).into();
}
/// Create a new builder with a call to the given address.
fn call_with(dest: H160) -> Self {
let mut builder = Self::new();
builder.tx.to = Some(dest);
builder.tx.gas = U256::from(516_708u128);
builder.estimate_gas();
builder
}
......@@ -502,7 +516,7 @@ mod test {
fn instantiate_with(code: Vec<u8>, data: Vec<u8>) -> Self {
let mut builder = Self::new();
builder.tx.input = Bytes(code.into_iter().chain(data.into_iter()).collect());
builder.tx.gas = U256::from(1_035_070u128);
builder.estimate_gas();
builder
}
......
......@@ -1212,6 +1212,7 @@ where
to: Some(dest),
..Default::default()
};
let eth_dispatch_call = crate::Call::<T>::eth_transact {
payload: tx.dummy_signed_payload(),
gas_limit: result.gas_required,
......@@ -1238,7 +1239,7 @@ where
)
.into();
log::debug!(target: LOG_TARGET, "Call dry run Result: dispatch_info: {dispatch_info:?} len: {encoded_len:?} fee: {fee:?}");
log::debug!(target: LOG_TARGET, "bare_eth_call: len: {encoded_len:?} fee: {fee:?}");
EthContractResult {
gas_required: result.gas_required,
storage_deposit: result.storage_deposit.charge_or_zero(),
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment