Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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: minor
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
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