Skip to content

Commit

Permalink
feat: Filter test cases by label (#13)
Browse files Browse the repository at this point in the history
antoniolocascio authored Jan 17, 2025
1 parent 13d9831 commit 37ba6d8
Showing 6 changed files with 38 additions and 5 deletions.
4 changes: 4 additions & 0 deletions evm_tester/src/evm_tester/arguments.rs
Original file line number Diff line number Diff line change
@@ -26,6 +26,10 @@ pub struct Arguments {
#[structopt(short = "g", long = "group")]
pub groups: Vec<String>,

/// Runs only tests with the specified labels.
#[structopt(short = "l", long = "label")]
pub labels: Vec<String>,

/// Sets the number of threads, which execute the tests concurrently.
#[structopt(short = "t", long = "threads")]
pub threads: Option<usize>,
3 changes: 2 additions & 1 deletion evm_tester/src/evm_tester/main.rs
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ fn main_inner(arguments: Arguments) -> anyhow::Result<()> {

let summary = evm_tester::Summary::new(arguments.verbosity, arguments.quiet).wrap();

let filters = evm_tester::Filters::new(arguments.paths, arguments.groups);
let filters = evm_tester::Filters::new(arguments.paths, arguments.groups, arguments.labels);

let evm_tester = evm_tester::EvmTester::new(summary.clone(), filters, arguments.workflow)?;

@@ -102,6 +102,7 @@ mod tests {
quiet: false,
paths: vec!["tests/solidity/simple/default.sol".to_owned()],
groups: vec![],
labels: vec![],
threads: Some(1),
environment: None,
workflow: evm_tester::Workflow::BuildAndRun,
16 changes: 15 additions & 1 deletion evm_tester/src/filters.rs
Original file line number Diff line number Diff line change
@@ -13,16 +13,23 @@ pub struct Filters {
path_filters: HashSet<String>,
/// The group filters.
group_filters: HashSet<String>,
/// The label filters.
label_filters: HashSet<String>,
}

impl Filters {
///
/// A shortcut constructor.
///
pub fn new(path_filters: Vec<String>, group_filters: Vec<String>) -> Self {
pub fn new(
path_filters: Vec<String>,
group_filters: Vec<String>,
label_filters: Vec<String>,
) -> Self {
Self {
path_filters: path_filters.into_iter().collect(),
group_filters: group_filters.into_iter().collect(),
label_filters: label_filters.into_iter().collect(),
}
}

@@ -46,6 +53,13 @@ impl Filters {
self.path_filters.is_empty() || self.path_filters.iter().any(|filter| path.contains(filter))
}

///
/// Check if the test case label is compatible with the filters.
///
pub fn check_case_label(&self, label: &str) -> bool {
self.label_filters.is_empty() || self.label_filters.contains(label)
}

///
/// Check if the test group is compatible with the filters.
///
15 changes: 13 additions & 2 deletions evm_tester/src/test/case/mod.rs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ use crate::{
eravm::system_context::SystemContext,
zk_ee::{ZkOS, ZkOsEVMContext},
},
EraVM, EraVMDeployer, Summary,
EraVM, EraVMDeployer, Filters, Summary,
};

use super::{
@@ -86,6 +86,7 @@ impl Case {
pub fn from_ethereum_test(
test_definition: &TestStructure,
test_filler: &FillerStructure,
filters: &Filters,
) -> Vec<Self> {
let mut cases = vec![];

@@ -158,6 +159,16 @@ impl Case {
None
};

// If label is not preset, we use the index
let final_label = label.clone().unwrap_or(case_idx.to_string());

// Apply label-based filter
if !Filters::check_case_label(filters, final_label.as_str()) {
case_counter += 1;

continue;
}

let prestate = test_definition.pre.clone();

let transaction = Transaction {
@@ -202,7 +213,7 @@ impl Case {
let (expected_state, expect_exception) = &expected_results_states[index];

cases.push(Case {
label: label.unwrap_or(case_idx.to_string()),
label: final_label,
prestate,
transaction,
post_state: None,
4 changes: 3 additions & 1 deletion evm_tester/src/test/mod.rs
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ use crate::summary::Summary;
use crate::test::case::Case;
use crate::vm::eravm::deployers::EraVMDeployer;
use crate::vm::eravm::EraVM;
use crate::Filters;
use crate::ZkOS;

fn wrap_numbers_in_quotes(input: &str) -> String {
@@ -81,6 +82,7 @@ impl Test {
is_json: bool,
skipped_calldatas: Option<Vec<web3::types::Bytes>>,
skipped_cases: Option<Vec<String>>,
filters: &Filters,
) -> Self {
let cleaned_str = str.replace("0x:bigint ", "");
let test_structure: HashMap<String, TestStructure> =
@@ -100,7 +102,7 @@ impl Test {
let test_definition = test_structure.get(keys[0]).expect("Always exists");
let test_filler = test_filler_structure.get(keys[0]).expect("Always exists");

let cases = Case::from_ethereum_test(test_definition, test_filler);
let cases = Case::from_ethereum_test(test_definition, test_filler, filters);

Self {
name: test_name.clone(),
1 change: 1 addition & 0 deletions evm_tester/src/test_suits/ethereum_general_state/mod.rs
Original file line number Diff line number Diff line change
@@ -96,6 +96,7 @@ impl Collection for EthereumGeneralStateTestsDirectory {
is_json,
test.skip_calldatas,
test.skip_cases,
filters,
))
})
.collect())

0 comments on commit 37ba6d8

Please sign in to comment.