Skip to content

Commit 9069837

Browse files
committed
Add the ability to override the gas limit and other gas params in test steps
1 parent 97d0cf1 commit 9069837

File tree

3 files changed

+73
-10
lines changed

3 files changed

+73
-10
lines changed

crates/core/src/differential_tests/driver.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -482,15 +482,16 @@ where
482482
.context("Failed to find deployment receipt for constructor call"),
483483
Method::Fallback | Method::FunctionName(_) => {
484484
let resolver = self.platform_information.node.resolver().await?;
485-
let tx = match step
485+
let mut tx = step
486486
.as_transaction(resolver.as_ref(), self.default_resolution_context())
487-
.await
488-
{
489-
Ok(tx) => tx,
490-
Err(err) => {
491-
return Err(err);
492-
}
493-
};
487+
.await?;
488+
489+
let gas_overrides = step
490+
.gas_overrides
491+
.get(&self.platform_information.platform.platform_identifier())
492+
.copied()
493+
.unwrap_or_default();
494+
gas_overrides.apply_to::<Ethereum>(&mut tx);
494495

495496
self.platform_information.node.execute_transaction(tx).await
496497
}
@@ -911,7 +912,6 @@ where
911912
.get(contract_instance)
912913
{
913914
info!(
914-
915915
%address,
916916
"Contract instance already deployed."
917917
);

crates/format/src/steps.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{collections::HashMap, fmt::Display, str::FromStr};
22

33
use alloy::hex::ToHexExt;
4+
use alloy::network::Network;
45
use alloy::primitives::{FixedBytes, utils::parse_units};
56
use alloy::{
67
eips::BlockNumberOrTag,
@@ -11,6 +12,7 @@ use alloy::{
1112
};
1213
use anyhow::Context as _;
1314
use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt, stream};
15+
use revive_dt_common::types::PlatformIdentifier;
1416
use schemars::JsonSchema;
1517
use semver::VersionReq;
1618
use serde::{Deserialize, Serialize};
@@ -152,6 +154,11 @@ pub struct FunctionCallStep {
152154
/// during the execution.
153155
#[serde(skip_serializing_if = "Option::is_none")]
154156
pub variable_assignments: Option<VariableAssignments>,
157+
158+
/// Allows for the test to set a specific value for the various gas parameter for each one of
159+
/// the platforms we support. This is ignored for steps that perform contract deployments.
160+
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
161+
pub gas_overrides: HashMap<PlatformIdentifier, GasOverrides>,
155162
}
156163

157164
/// This represents a balance assertion step where the framework needs to query the balance of some
@@ -965,6 +972,62 @@ impl<'de> Deserialize<'de> for EtherValue {
965972
}
966973
}
967974

975+
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, Eq, PartialEq, JsonSchema)]
976+
pub struct GasOverrides {
977+
#[serde(skip_serializing_if = "Option::is_none")]
978+
pub gas_limit: Option<u64>,
979+
980+
#[serde(skip_serializing_if = "Option::is_none")]
981+
pub gas_price: Option<u128>,
982+
983+
#[serde(skip_serializing_if = "Option::is_none")]
984+
pub max_fee_per_gas: Option<u128>,
985+
986+
#[serde(skip_serializing_if = "Option::is_none")]
987+
pub max_priority_fee_per_gas: Option<u128>,
988+
}
989+
990+
impl GasOverrides {
991+
pub fn new() -> Self {
992+
Default::default()
993+
}
994+
995+
pub fn with_gas_limit(mut self, value: impl Into<Option<u64>>) -> Self {
996+
self.gas_limit = value.into();
997+
self
998+
}
999+
1000+
pub fn with_gas_price(mut self, value: impl Into<Option<u128>>) -> Self {
1001+
self.gas_price = value.into();
1002+
self
1003+
}
1004+
1005+
pub fn with_max_fee_per_gas(mut self, value: impl Into<Option<u128>>) -> Self {
1006+
self.max_fee_per_gas = value.into();
1007+
self
1008+
}
1009+
1010+
pub fn with_max_priority_fee_per_gas(mut self, value: impl Into<Option<u128>>) -> Self {
1011+
self.max_priority_fee_per_gas = value.into();
1012+
self
1013+
}
1014+
1015+
pub fn apply_to<N: Network>(&self, transaction_request: &mut N::TransactionRequest) {
1016+
if let Some(gas_limit) = self.gas_limit {
1017+
transaction_request.set_gas_limit(gas_limit);
1018+
}
1019+
if let Some(gas_price) = self.gas_price {
1020+
transaction_request.set_gas_price(gas_price);
1021+
}
1022+
if let Some(max_fee_per_gas) = self.max_fee_per_gas {
1023+
transaction_request.set_max_fee_per_gas(max_fee_per_gas);
1024+
}
1025+
if let Some(max_priority_fee_per_gas) = self.max_priority_fee_per_gas {
1026+
transaction_request.set_max_priority_fee_per_gas(max_priority_fee_per_gas)
1027+
}
1028+
}
1029+
}
1030+
9681031
#[cfg(test)]
9691032
mod tests {
9701033

0 commit comments

Comments
 (0)