Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Filter test cases by label #13

Merged
merged 2 commits into from
Jan 17, 2025
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
4 changes: 4 additions & 0 deletions evm_tester/src/evm_tester/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
3 changes: 2 additions & 1 deletion evm_tester/src/evm_tester/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down Expand Up @@ -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,
Expand Down
16 changes: 15 additions & 1 deletion evm_tester/src/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand All @@ -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.
///
Expand Down
15 changes: 13 additions & 2 deletions evm_tester/src/test/case/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
eravm::system_context::SystemContext,
zk_ee::{ZkOS, ZkOsEVMContext},
},
EraVM, EraVMDeployer, Summary,
EraVM, EraVMDeployer, Filters, Summary,
};

use super::{
Expand Down Expand Up @@ -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![];

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion evm_tester/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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> =
Expand All @@ -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(),
Expand Down
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
Expand Up @@ -96,6 +96,7 @@ impl Collection for EthereumGeneralStateTestsDirectory {
is_json,
test.skip_calldatas,
test.skip_cases,
filters,
))
})
.collect())
Expand Down
Loading