Skip to content

Commit

Permalink
[pallet-revive] fix hardcoded gas in tests (paritytech#6192)
Browse files Browse the repository at this point in the history
Fix hardcoded gas limits in tests

---------

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
2 people authored and mordamax committed Oct 25, 2024
1 parent 8c7d4e4 commit 88adf74
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
7 changes: 7 additions & 0 deletions prdoc/pr_6192.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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
30 changes: 22 additions & 8 deletions substrate/frame/revive/src/evm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
Expand Down Expand Up @@ -490,19 +485,38 @@ 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
}

/// Create a new builder with an instantiate call.
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
}

Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down

0 comments on commit 88adf74

Please sign in to comment.