Skip to content

Commit 88adf74

Browse files
pgherveouactions-user
authored andcommitted
[pallet-revive] fix hardcoded gas in tests (paritytech#6192)
Fix hardcoded gas limits in tests --------- Co-authored-by: GitHub Action <action@github.com>
1 parent 8c7d4e4 commit 88adf74

3 files changed

Lines changed: 31 additions & 9 deletions

File tree

prdoc/pr_6192.prdoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
title: '[pallet-revive] fix hardcoded gas in tests'
2+
doc:
3+
- audience: Runtime Dev
4+
description: Fix hardcoded gas limits in tests
5+
crates:
6+
- name: pallet-revive
7+
bump: patch

substrate/frame/revive/src/evm/runtime.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,7 @@ pub trait EthExtra {
356356
Default::default(),
357357
)
358358
.into();
359-
360-
log::debug!(target: LOG_TARGET, "Checking Ethereum transaction fees:
361-
dispatch_info: {info:?}
362-
encoded_len: {encoded_len:?}
363-
fees: {actual_fee:?}
364-
");
359+
log::debug!(target: LOG_TARGET, "try_into_checked_extrinsic: encoded_len: {encoded_len:?} actual_fee: {actual_fee:?} eth_fee: {eth_fee:?}");
365360

366361
if eth_fee < actual_fee {
367362
log::debug!(target: LOG_TARGET, "fees {eth_fee:?} too low for the extrinsic {actual_fee:?}");
@@ -490,19 +485,38 @@ mod test {
490485
}
491486
}
492487

488+
fn estimate_gas(&mut self) {
489+
let dry_run = crate::Pallet::<Test>::bare_eth_transact(
490+
Account::default().account_id(),
491+
self.tx.to,
492+
self.tx.value.try_into().unwrap(),
493+
self.tx.input.clone().0,
494+
Weight::MAX,
495+
u64::MAX,
496+
|call| {
497+
let call = RuntimeCall::Contracts(call);
498+
let uxt: Ex = sp_runtime::generic::UncheckedExtrinsic::new_bare(call).into();
499+
uxt.encoded_size() as u32
500+
},
501+
crate::DebugInfo::Skip,
502+
crate::CollectEvents::Skip,
503+
);
504+
self.tx.gas = ((dry_run.fee + GAS_PRICE as u64) / (GAS_PRICE as u64)).into();
505+
}
506+
493507
/// Create a new builder with a call to the given address.
494508
fn call_with(dest: H160) -> Self {
495509
let mut builder = Self::new();
496510
builder.tx.to = Some(dest);
497-
builder.tx.gas = U256::from(516_708u128);
511+
builder.estimate_gas();
498512
builder
499513
}
500514

501515
/// Create a new builder with an instantiate call.
502516
fn instantiate_with(code: Vec<u8>, data: Vec<u8>) -> Self {
503517
let mut builder = Self::new();
504518
builder.tx.input = Bytes(code.into_iter().chain(data.into_iter()).collect());
505-
builder.tx.gas = U256::from(1_035_070u128);
519+
builder.estimate_gas();
506520
builder
507521
}
508522

substrate/frame/revive/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ where
12121212
to: Some(dest),
12131213
..Default::default()
12141214
};
1215+
12151216
let eth_dispatch_call = crate::Call::<T>::eth_transact {
12161217
payload: tx.dummy_signed_payload(),
12171218
gas_limit: result.gas_required,
@@ -1238,7 +1239,7 @@ where
12381239
)
12391240
.into();
12401241

1241-
log::debug!(target: LOG_TARGET, "Call dry run Result: dispatch_info: {dispatch_info:?} len: {encoded_len:?} fee: {fee:?}");
1242+
log::debug!(target: LOG_TARGET, "bare_eth_call: len: {encoded_len:?} fee: {fee:?}");
12421243
EthContractResult {
12431244
gas_required: result.gas_required,
12441245
storage_deposit: result.storage_deposit.charge_or_zero(),

0 commit comments

Comments
 (0)