Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
118 changes: 59 additions & 59 deletions Cargo.lock

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -227,24 +227,24 @@ opentelemetry-semantic-conventions = "0.31.0"
opentelemetry-appender-tracing = "0.31.1"

# Reth dependencies
reth-db-models = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-chainspec = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-trie-common = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-primitives-traits = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-revm = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-storage-api = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-execution-types = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-network = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-network-peers = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-net-nat = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-eth-wire = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-discv5 = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-provider = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-rpc-eth-types = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-tasks = { git = "https://github.com/paradigmxyz/reth", tag = "v1.11.1" }
reth-db-models = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-evm-ethereum = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-chainspec = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-trie-common = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-primitives = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-primitives-traits = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-revm = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-storage-api = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-transaction-pool = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-execution-types = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-network = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-network-peers = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-net-nat = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-eth-wire = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-discv5 = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-provider = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-rpc-eth-types = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }
reth-tasks = { git = "https://github.com/matter-labs/reth.git", branch = "fix/discv5-shutdown-v1.11.1" }

zksync-os-revm = { git = "https://github.com/matter-labs/zksync-os-revm", tag = "v0.0.4" }

Expand Down
101 changes: 32 additions & 69 deletions integration-tests-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Parse for CaseList {
enum ParamKind {
TestCase,
Tester,
TesterBuilder,
TestEnvironment,
}

fn param_kind(arg: &FnArg) -> Result<Option<ParamKind>> {
Expand All @@ -46,7 +46,7 @@ fn type_kind(ty: &Type) -> Option<ParamKind> {
match ident.as_str() {
"TestCase" => Some(ParamKind::TestCase),
"Tester" => Some(ParamKind::Tester),
"TesterBuilder" => Some(ParamKind::TesterBuilder),
"TestEnvironment" => Some(ParamKind::TestEnvironment),
_ => None,
}
}
Expand All @@ -61,25 +61,12 @@ fn path_matches(path: &syn::Path, expected: &[&str]) -> bool {
.all(|(actual, expected)| actual == expected)
}

fn split_helper_attrs(
attrs: Vec<Attribute>,
) -> Result<(Vec<Attribute>, Option<syn::Expr>, Option<TokenStream2>)> {
fn split_helper_attrs(attrs: Vec<Attribute>) -> Result<(Vec<Attribute>, Option<TokenStream2>)> {
let mut output = Vec::with_capacity(attrs.len());
let mut builder_expr = None;
let mut runtime_args = None;

for attr in attrs {
if attr.path().is_ident("test_builder") {
if builder_expr.is_some() {
return Err(syn::Error::new_spanned(
attr,
"duplicate `test_builder` attribute",
));
}
builder_expr = Some(attr.parse_args()?);
} else if attr.path().is_ident("test_runtime")
|| path_matches(attr.path(), &["tokio", "test"])
{
if attr.path().is_ident("test_runtime") || path_matches(attr.path(), &["tokio", "test"]) {
if runtime_args.is_some() {
return Err(syn::Error::new_spanned(
attr,
Expand All @@ -94,7 +81,7 @@ fn split_helper_attrs(
}
}

Ok((output, builder_expr, runtime_args))
Ok((output, runtime_args))
}

fn case_fn_name(case: &Path) -> Result<syn::Ident> {
Expand All @@ -114,19 +101,19 @@ fn case_fn_name(case: &Path) -> Result<syn::Ident> {
/// module with one wrapper test per case:
///
/// - each wrapper binds `let case = <path>;`
/// - if the function takes a `TesterBuilder`, the wrapper starts from `case.builder()`
/// - if the function takes a `Tester`, the wrapper builds it with `case.builder().build().await?`
/// - if the function takes a `TestEnvironment`, the wrapper prepares it from the case
/// - if the function takes a `Tester`, the wrapper prepares the environment and launches a default node
/// - if the function takes a `TestCase`, the wrapper passes the case value directly
/// - each wrapper is annotated with `#[test_log::test(tokio::test)]` by default
///
/// Supported parameter types are:
///
/// - `TestCase`
/// - `TesterBuilder`
/// - `TestEnvironment`
/// - `Tester`
///
/// `TestCase` may be combined with either `TesterBuilder` or `Tester`.
/// `TesterBuilder` and `Tester` cannot be used together in the same function signature.
/// `TestCase` may be combined with either `TestEnvironment` or `Tester`.
/// `TestEnvironment` and `Tester` cannot be used together in the same function signature.
///
/// # Cases
///
Expand All @@ -139,21 +126,6 @@ fn case_fn_name(case: &Path) -> Result<syn::Ident> {
/// Each path should evaluate to a `TestCase`, typically one of the exported constants from
/// `zksync_os_integration_tests`.
///
/// # Builder customization
///
/// Use `#[test_builder(...)]` when every generated case should apply the same builder tweak before
/// the `TesterBuilder` or `Tester` is created. The argument must be a function or closure with the
/// shape `fn(TesterBuilder) -> TesterBuilder`.
///
/// ```ignore
/// #[test_multisetup([CURRENT_TO_L1, NEXT_TO_GATEWAY])]
/// #[test_builder(|builder| builder.block_time(Duration::from_secs(5)))]
/// async fn pending_nonce_uses_slow_blocks(tester: Tester) -> anyhow::Result<()> {
/// // `tester` is built from the adjusted builder for each case.
/// Ok(())
/// }
/// ```
///
/// # Runtime customization
///
/// Use `#[test_runtime(...)]` to pass options to the generated `tokio::test(...)` runtime.
Expand Down Expand Up @@ -199,11 +171,14 @@ fn case_fn_name(case: &Path) -> Result<syn::Ident> {
/// Customize the builder inside the test before constructing a `Tester`:
///
/// ```ignore
/// use zksync_os_integration_tests::{CURRENT_TO_L1, TesterBuilder, test_multisetup};
/// use zksync_os_integration_tests::{CURRENT_TO_L1, TestEnvironment, test_multisetup};
///
/// #[test_multisetup([CURRENT_TO_L1])]
/// async fn prover_flow(builder: TesterBuilder) -> anyhow::Result<()> {
/// let tester = builder.enable_prover().build().await?;
/// async fn prover_flow(env: TestEnvironment) -> anyhow::Result<()> {
/// let mut config = env.default_config().await?;
/// config.prover_api_config.fake_fri_provers.enabled = false;
/// config.prover_api_config.fake_snark_provers.enabled = false;
/// let tester = env.launch(config).await?;
/// tester.prover_tester.wait_for_batch_proven(1).await?;
/// Ok(())
/// }
Expand Down Expand Up @@ -231,9 +206,8 @@ fn case_fn_name(case: &Path) -> Result<syn::Ident> {
///
/// - the annotated function must be `async`
/// - methods taking `self` are not supported
/// - only `TestCase`, `TesterBuilder`, and `Tester` parameters are accepted
/// - `TesterBuilder` and `Tester` cannot be used together in the same function
/// - `#[test_builder(...)]` may be used at most once
/// - only `TestCase`, `TestEnvironment`, and `Tester` parameters are accepted
/// - `TestEnvironment` and `Tester` cannot be used together in the same function
/// - `#[test_runtime(...)]` may be used at most once
#[proc_macro_attribute]
pub fn test_multisetup(attr: TokenStream, item: TokenStream) -> TokenStream {
Expand All @@ -246,7 +220,7 @@ pub fn test_multisetup(attr: TokenStream, item: TokenStream) -> TokenStream {
.into();
}

let (wrapper_attrs, builder_expr, runtime_args) = match split_helper_attrs(input.attrs) {
let (wrapper_attrs, runtime_args) = match split_helper_attrs(input.attrs) {
Ok(attrs) => attrs,
Err(err) => return err.into_compile_error().into(),
};
Expand All @@ -256,7 +230,7 @@ pub fn test_multisetup(attr: TokenStream, item: TokenStream) -> TokenStream {
let mod_name = input.sig.ident.clone();
input.sig.ident = impl_name.clone();

let mut needs_builder = false;
let mut needs_environment = false;
let mut needs_tester = false;
let mut arg_exprs = Vec::with_capacity(input.sig.inputs.len());

Expand All @@ -265,9 +239,9 @@ pub fn test_multisetup(attr: TokenStream, item: TokenStream) -> TokenStream {
Ok(Some(ParamKind::TestCase)) => {
arg_exprs.push(quote!(case));
}
Ok(Some(ParamKind::TesterBuilder)) => {
needs_builder = true;
arg_exprs.push(quote!(builder.clone()));
Ok(Some(ParamKind::TestEnvironment)) => {
needs_environment = true;
arg_exprs.push(quote!(environment));
}
Ok(Some(ParamKind::Tester)) => {
needs_tester = true;
Expand All @@ -276,7 +250,7 @@ pub fn test_multisetup(attr: TokenStream, item: TokenStream) -> TokenStream {
Ok(None) => {
return syn::Error::new_spanned(
arg,
"supported parameters are `Tester`, `TesterBuilder`, and `TestCase`",
"supported parameters are `Tester`, `TestEnvironment`, and `TestCase`",
)
.into_compile_error()
.into();
Expand All @@ -285,37 +259,26 @@ pub fn test_multisetup(attr: TokenStream, item: TokenStream) -> TokenStream {
}
}

if needs_builder && needs_tester {
if needs_environment && needs_tester {
return syn::Error::new_spanned(
&input.sig.inputs,
"`TesterBuilder` and `Tester` cannot be used together in the same test function",
"`TestEnvironment` and `Tester` cannot be used together in the same test function",
)
.into_compile_error()
.into();
}

let builder_setup = if needs_builder || needs_tester {
if let Some(builder_expr) = builder_expr {
quote! {
let builder = {
let configure: fn(
::zksync_os_integration_tests::TesterBuilder,
) -> ::zksync_os_integration_tests::TesterBuilder = #builder_expr;
let builder: ::zksync_os_integration_tests::TesterBuilder = case.builder();
configure(builder)
};
}
} else {
quote! {
let builder: ::zksync_os_integration_tests::TesterBuilder = case.builder();
}
let environment_setup = if needs_environment || needs_tester {
quote! {
let environment: ::zksync_os_integration_tests::TestEnvironment =
case.environment().await?;
}
} else {
quote! {}
};
let tester_setup = if needs_tester {
quote! {
let tester = builder.build().await?;
let tester = environment.launch_default().await?;
}
} else {
quote! {}
Expand Down Expand Up @@ -346,7 +309,7 @@ pub fn test_multisetup(attr: TokenStream, item: TokenStream) -> TokenStream {
#(#wrapper_attrs)*
async fn #fn_name() -> anyhow::Result<()> {
let case = #case;
#builder_setup
#environment_setup
#tester_setup
#impl_name(#(#arg_exprs),*).await
}
Expand Down
Loading
Loading