11use std:: { collections:: HashMap , fmt:: Display , str:: FromStr } ;
22
33use alloy:: hex:: ToHexExt ;
4+ use alloy:: network:: Network ;
45use alloy:: primitives:: { FixedBytes , utils:: parse_units} ;
56use alloy:: {
67 eips:: BlockNumberOrTag ,
@@ -11,6 +12,7 @@ use alloy::{
1112} ;
1213use anyhow:: Context as _;
1314use futures:: { FutureExt , StreamExt , TryFutureExt , TryStreamExt , stream} ;
15+ use revive_dt_common:: types:: PlatformIdentifier ;
1416use schemars:: JsonSchema ;
1517use semver:: VersionReq ;
1618use 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) ]
9691032mod tests {
9701033
0 commit comments