Compare commits

..

2 Commits

Author SHA1 Message Date
Omar Abdulla 8ff9568f4d Update the CI action fixing incorrect matrix usage 2026-01-06 16:06:20 +03:00
Omar Abdulla cf0c28b468 Add a CI action for running tests 2026-01-06 15:43:40 +03:00
6 changed files with 159 additions and 167 deletions
+65 -14
View File
@@ -4,6 +4,7 @@ mod helpers;
use anyhow::{Context as _, bail}; use anyhow::{Context as _, bail};
use clap::Parser; use clap::Parser;
use revive_dt_common::types::ParsedTestSpecifier;
use revive_dt_report::{ReportAggregator, TestCaseStatus}; use revive_dt_report::{ReportAggregator, TestCaseStatus};
use schemars::schema_for; use schemars::schema_for;
use tracing::{info, level_filters::LevelFilter}; use tracing::{info, level_filters::LevelFilter};
@@ -63,15 +64,40 @@ fn main() -> anyhow::Result<()> {
) )
.await?; .await?;
let contains_failure = report // Error out if there are any failing tests.
let failures = report
.execution_information .execution_information
.values() .into_iter()
.flat_map(|values| values.case_reports.values()) .flat_map(|(metadata_file_path, metadata_file_report)| {
.flat_map(|values| values.mode_execution_reports.values()) metadata_file_report.case_reports.into_iter().flat_map(
.any(|report| matches!(report.status, Some(TestCaseStatus::Failed { .. }))); move |(case_idx, case_report)| {
let metadata_file_path = metadata_file_path.clone();
case_report.mode_execution_reports.into_iter().filter_map(
move |(mode, execution_report)| {
if let Some(TestCaseStatus::Failed { reason }) =
execution_report.status
{
let parsed_test_specifier =
ParsedTestSpecifier::CaseWithMode {
metadata_file_path: metadata_file_path
.clone()
.into_inner(),
case_idx: case_idx.into_inner(),
mode,
};
Some((parsed_test_specifier, reason))
} else {
None
}
},
)
},
)
})
.collect::<Vec<_>>();
if contains_failure { if !failures.is_empty() {
bail!("Some tests failed") bail!("Some tests failed: {failures:#?}")
} }
Ok(()) Ok(())
@@ -91,15 +117,40 @@ fn main() -> anyhow::Result<()> {
) )
.await?; .await?;
let contains_failure = report // Error out if there are any failing tests.
let failures = report
.execution_information .execution_information
.values() .into_iter()
.flat_map(|values| values.case_reports.values()) .flat_map(|(metadata_file_path, metadata_file_report)| {
.flat_map(|values| values.mode_execution_reports.values()) metadata_file_report.case_reports.into_iter().flat_map(
.any(|report| matches!(report.status, Some(TestCaseStatus::Failed { .. }))); move |(case_idx, case_report)| {
let metadata_file_path = metadata_file_path.clone();
case_report.mode_execution_reports.into_iter().filter_map(
move |(mode, execution_report)| {
if let Some(TestCaseStatus::Failed { reason }) =
execution_report.status
{
let parsed_test_specifier =
ParsedTestSpecifier::CaseWithMode {
metadata_file_path: metadata_file_path
.clone()
.into_inner(),
case_idx: case_idx.into_inner(),
mode,
};
Some((parsed_test_specifier, reason))
} else {
None
}
},
)
},
)
})
.collect::<Vec<_>>();
if contains_failure { if !failures.is_empty() {
bail!("Some benchmarks failed") bail!("Some tests failed: {failures:#?}")
} }
Ok(()) Ok(())
+1 -1
View File
@@ -250,7 +250,7 @@ impl GethNode {
construct_concurrency_limited_provider::<Ethereum, _>( construct_concurrency_limited_provider::<Ethereum, _>(
self.connection_string.as_str(), self.connection_string.as_str(),
FallbackGasFiller::default() FallbackGasFiller::default()
.with_fallback_mechanism(self.use_fallback_gas_filler), .with_use_fallback_gas_filler(self.use_fallback_gas_filler),
ChainIdFiller::new(Some(CHAIN_ID)), ChainIdFiller::new(Some(CHAIN_ID)),
NonceFiller::new(self.nonce_manager.clone()), NonceFiller::new(self.nonce_manager.clone()),
self.wallet.clone(), self.wallet.clone(),
@@ -379,7 +379,7 @@ impl LighthouseGethNode {
construct_concurrency_limited_provider::<Ethereum, _>( construct_concurrency_limited_provider::<Ethereum, _>(
self.ws_connection_string.as_str(), self.ws_connection_string.as_str(),
FallbackGasFiller::default() FallbackGasFiller::default()
.with_fallback_mechanism(self.use_fallback_gas_filler), .with_use_fallback_gas_filler(self.use_fallback_gas_filler),
ChainIdFiller::new(Some(CHAIN_ID)), ChainIdFiller::new(Some(CHAIN_ID)),
NonceFiller::new(self.nonce_manager.clone()), NonceFiller::new(self.nonce_manager.clone()),
self.wallet.clone(), self.wallet.clone(),
@@ -47,7 +47,7 @@ use tracing::{instrument, trace};
use crate::{ use crate::{
Node, Node,
constants::INITIAL_BALANCE, constants::{CHAIN_ID, INITIAL_BALANCE},
helpers::{Process, ProcessReadinessWaitBehavior}, helpers::{Process, ProcessReadinessWaitBehavior},
provider_utils::{ provider_utils::{
ConcreteProvider, FallbackGasFiller, construct_concurrency_limited_provider, ConcreteProvider, FallbackGasFiller, construct_concurrency_limited_provider,
@@ -327,9 +327,13 @@ impl SubstrateNode {
.get_or_try_init(|| async move { .get_or_try_init(|| async move {
construct_concurrency_limited_provider::<Ethereum, _>( construct_concurrency_limited_provider::<Ethereum, _>(
self.rpc_url.as_str(), self.rpc_url.as_str(),
FallbackGasFiller::default() FallbackGasFiller::new(
.with_fallback_mechanism(self.use_fallback_gas_filler), u64::MAX,
ChainIdFiller::default(), 50_000_000_000,
1_000_000_000,
self.use_fallback_gas_filler,
),
ChainIdFiller::new(Some(CHAIN_ID)),
NonceFiller::new(self.nonce_manager.clone()), NonceFiller::new(self.nonce_manager.clone()),
self.wallet.clone(), self.wallet.clone(),
) )
@@ -334,8 +334,12 @@ impl ZombienetNode {
.get_or_try_init(|| async move { .get_or_try_init(|| async move {
construct_concurrency_limited_provider::<Ethereum, _>( construct_concurrency_limited_provider::<Ethereum, _>(
self.connection_string.as_str(), self.connection_string.as_str(),
FallbackGasFiller::default() FallbackGasFiller::new(
.with_fallback_mechanism(self.use_fallback_gas_filler), u64::MAX,
5_000_000_000,
1_000_000_000,
self.use_fallback_gas_filler,
),
ChainIdFiller::default(), // TODO: use CHAIN_ID constant ChainIdFiller::default(), // TODO: use CHAIN_ID constant
NonceFiller::new(self.nonce_manager.clone()), NonceFiller::new(self.nonce_manager.clone()),
self.wallet.clone(), self.wallet.clone(),
@@ -1,71 +1,65 @@
use std::{borrow::Cow, fmt::Display};
use alloy::{ use alloy::{
eips::BlockNumberOrTag,
network::{Network, TransactionBuilder}, network::{Network, TransactionBuilder},
providers::{ providers::{
Provider, SendableTx, Provider, SendableTx,
ext::DebugApi, fillers::{GasFiller, TxFiller},
fillers::{GasFillable, GasFiller, TxFiller},
}, },
rpc::types::trace::geth::{ transports::{TransportError, TransportResult},
GethDebugBuiltInTracerType, GethDebugTracerType, GethDebugTracingCallOptions,
GethDebugTracingOptions,
},
transports::{RpcError, TransportResult},
}; };
/// An implementation of [`GasFiller`] with a fallback mechanism for reverting transactions. // Percentage padding applied to estimated gas (e.g. 120 = 20% padding)
/// const GAS_ESTIMATE_PADDING_NUMERATOR: u64 = 120;
/// This struct provides a fallback mechanism for alloy's [`GasFiller`] which kicks in when a const GAS_ESTIMATE_PADDING_DENOMINATOR: u64 = 100;
/// transaction's dry run fails due to it reverting allowing us to get gas estimates even for
/// failing transactions. In this codebase, this is very important since the MatterLabs tests
/// expect some transactions in the test suite revert. Since we're expected to run a number of
/// assertions on these reverting transactions we must commit them to the ledger.
///
/// Therefore, this struct does the following:
///
/// 1. It first attempts to estimate the gas through the mechanism implemented in the [`GasFiller`].
/// 2. If it fails, then we perform a debug trace of the transaction to find out how much gas the
/// transaction needs until it reverts.
/// 3. We fill in these values (either the success or failure case) into the transaction.
///
/// The fallback mechanism of this filler can be completely disabled if we don't want it to be used.
/// In that case, this gas filler will act in an identical way to alloy's [`GasFiller`].
///
/// We then fill in these values into the transaction.
///
/// The previous implementation of this fallback gas filler relied on making use of default values
/// for the gas limit in order to be able to submit the reverting transactions to the network. But,
/// it introduced a number of issues that we weren't anticipating at the time when it was built.
#[derive(Clone, Copy, Debug)]
pub struct FallbackGasFiller {
/// The inner [`GasFiller`] which we pass all of the calls to in the happy path.
inner: GasFiller,
/// A [`bool`] that controls if the fallback mechanism is enabled or not. #[derive(Clone, Debug)]
enable_fallback_mechanism: bool, pub struct FallbackGasFiller {
inner: GasFiller,
default_gas_limit: u64,
default_max_fee_per_gas: u128,
default_priority_fee: u128,
use_fallback_gas_filler: bool,
} }
impl FallbackGasFiller { impl FallbackGasFiller {
pub fn new() -> Self { pub fn new(
default_gas_limit: u64,
default_max_fee_per_gas: u128,
default_priority_fee: u128,
use_fallback_gas_filler: bool,
) -> Self {
Self { Self {
inner: Default::default(), inner: GasFiller,
enable_fallback_mechanism: true, default_gas_limit,
default_max_fee_per_gas,
default_priority_fee,
use_fallback_gas_filler,
} }
} }
pub fn with_fallback_mechanism(mut self, enable: bool) -> Self { pub fn with_default_gas_limit(mut self, default_gas_limit: u64) -> Self {
self.enable_fallback_mechanism = enable; self.default_gas_limit = default_gas_limit;
self self
} }
pub fn with_fallback_mechanism_enabled(self) -> Self { pub fn with_default_max_fee_per_gas(mut self, default_max_fee_per_gas: u128) -> Self {
self.with_fallback_mechanism(true) self.default_max_fee_per_gas = default_max_fee_per_gas;
self
} }
pub fn with_fallback_mechanism_disabled(self) -> Self { pub fn with_default_priority_fee(mut self, default_priority_fee: u128) -> Self {
self.with_fallback_mechanism(false) self.default_priority_fee = default_priority_fee;
self
}
pub fn with_use_fallback_gas_filler(mut self, use_fallback_gas_filler: bool) -> Self {
self.use_fallback_gas_filler = use_fallback_gas_filler;
self
}
}
impl Default for FallbackGasFiller {
fn default() -> Self {
FallbackGasFiller::new(25_000_000, 1_000_000_000, 1_000_000_000, true)
} }
} }
@@ -73,89 +67,32 @@ impl<N> TxFiller<N> for FallbackGasFiller
where where
N: Network, N: Network,
{ {
type Fillable = <GasFiller as TxFiller<N>>::Fillable; type Fillable = Option<<GasFiller as TxFiller<N>>::Fillable>;
fn status( fn status(
&self, &self,
tx: &<N as Network>::TransactionRequest, tx: &<N as Network>::TransactionRequest,
) -> alloy::providers::fillers::FillerControlFlow { ) -> alloy::providers::fillers::FillerControlFlow {
TxFiller::<N>::status(&self.inner, tx) <GasFiller as TxFiller<N>>::status(&self.inner, tx)
} }
fn fill_sync(&self, _: &mut SendableTx<N>) {} fn fill_sync(&self, _: &mut alloy::providers::SendableTx<N>) {}
async fn prepare<P: Provider<N>>( async fn prepare<P: Provider<N>>(
&self, &self,
provider: &P, provider: &P,
tx: &<N as Network>::TransactionRequest, tx: &<N as Network>::TransactionRequest,
) -> TransportResult<Self::Fillable> { ) -> TransportResult<Self::Fillable> {
match ( match self.inner.prepare(provider, tx).await {
self.inner.prepare(provider, tx).await, Ok(fill) => Ok(Some(fill)),
self.enable_fallback_mechanism, Err(err) => {
) { tracing::debug!(error = ?err, "Gas Provider Estimation Failed, using fallback");
// Return the same thing if either this calls succeeds, or if the call falls and the
// fallback mechanism is disabled.
(rtn @ Ok(..), ..) | (rtn @ Err(..), false) => rtn,
(Err(..), true) => {
// Perform a trace of the transaction.
let trace = provider
.debug_trace_call(
tx.clone(),
BlockNumberOrTag::Latest.into(),
GethDebugTracingCallOptions {
tracing_options: GethDebugTracingOptions {
tracer: Some(GethDebugTracerType::BuiltInTracer(
GethDebugBuiltInTracerType::CallTracer,
)),
..Default::default()
},
state_overrides: Default::default(),
block_overrides: Default::default(),
},
)
.await?
.try_into_call_frame()
.map_err(|err| {
RpcError::LocalUsageError(
FallbackGasFillerError::new(format!(
"Expected a callframe trace, but got: {err:?}"
))
.boxed(),
)
})?;
let gas_used = u64::try_from(trace.gas_used).map_err(|_| { if !self.use_fallback_gas_filler {
RpcError::LocalUsageError( Err(err)
FallbackGasFillerError::new(
"Transaction trace returned a value of gas used that exceeds u64",
)
.boxed(),
)
})?;
let gas_limit = gas_used.saturating_mul(120) / 100;
if let Some(gas_price) = tx.gas_price() {
return Ok(GasFillable::Legacy {
gas_limit,
gas_price,
});
}
let estimate = if let (Some(max_fee_per_gas), Some(max_priority_fee_per_gas)) =
(tx.max_fee_per_gas(), tx.max_priority_fee_per_gas())
{
alloy::eips::eip1559::Eip1559Estimation {
max_fee_per_gas,
max_priority_fee_per_gas,
}
} else { } else {
provider.estimate_eip1559_fees().await? Ok(None)
}; }
Ok(GasFillable::Eip1559 {
gas_limit,
estimate,
})
} }
} }
} }
@@ -163,35 +100,31 @@ where
async fn fill( async fn fill(
&self, &self,
fillable: Self::Fillable, fillable: Self::Fillable,
tx: SendableTx<N>, mut tx: alloy::providers::SendableTx<N>,
) -> TransportResult<SendableTx<N>> { ) -> TransportResult<SendableTx<N>> {
self.inner.fill(fillable, tx).await if let Some(fill) = fillable {
let mut tx = self.inner.fill(fill, tx).await?;
if let Some(builder) = tx.as_mut_builder() {
if let Some(estimated) = builder.gas_limit() {
let padded = estimated
.checked_mul(GAS_ESTIMATE_PADDING_NUMERATOR)
.and_then(|v| v.checked_div(GAS_ESTIMATE_PADDING_DENOMINATOR))
.unwrap_or(u64::MAX);
builder.set_gas_limit(padded);
}
}
Ok(tx)
} else if self.use_fallback_gas_filler {
if let Some(builder) = tx.as_mut_builder() {
builder.set_gas_limit(self.default_gas_limit);
builder.set_max_fee_per_gas(self.default_max_fee_per_gas);
builder.set_max_priority_fee_per_gas(self.default_priority_fee);
}
Ok(tx)
} else {
Err(TransportError::UnsupportedFeature(
"Fallback gas filler is disabled and we're attempting to do a gas estimate on a failing transaction",
))
}
} }
} }
impl Default for FallbackGasFiller {
fn default() -> Self {
Self::new()
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct FallbackGasFillerError(Cow<'static, str>);
impl FallbackGasFillerError {
pub fn new(string: impl Into<Cow<'static, str>>) -> Self {
Self(string.into())
}
pub fn boxed(self) -> Box<Self> {
Box::new(self)
}
}
impl Display for FallbackGasFillerError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.0, f)
}
}
impl std::error::Error for FallbackGasFillerError {}