Skip to content

Commit

Permalink
refac: preserve test structure in summary
Browse files Browse the repository at this point in the history
  • Loading branch information
sayon committed Dec 2, 2024
1 parent 7d45446 commit 2b79711
Show file tree
Hide file tree
Showing 18 changed files with 569 additions and 604 deletions.
73 changes: 42 additions & 31 deletions compiler_tester/src/directories/ethereum/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use crate::environment::Environment;
use crate::filters::Filters;
use crate::summary::Summary;
use crate::test::case::Case;
use crate::test::description::TestDescription;
use crate::test::selector::TestSelector;
use crate::test::Test;
use crate::vm::address_iterator::AddressIterator;
use crate::vm::eravm::address_iterator::EraVMAddressIterator;
Expand All @@ -24,8 +26,8 @@ use crate::vm::evm::address_iterator::EVMAddressIterator;
///
#[derive(Debug)]
pub struct EthereumTest {
/// The test identifier.
pub identifier: String,
/// The test selector.
pub selector: TestSelector,
/// The index test entity.
pub index_entity: solidity_adapter::EnabledTest,
/// The test data.
Expand All @@ -41,26 +43,31 @@ impl EthereumTest {
summary: Arc<Mutex<Summary>>,
filters: &Filters,
) -> Option<Self> {
let identifier = index_entity.path.to_string_lossy().to_string();
let path = index_entity.path.to_string_lossy().to_string();

if !filters.check_case_path(&identifier) {
if !filters.check_case_path(&path) {
return None;
}

if !filters.check_group(&index_entity.group) {
return None;
}

let selector = TestSelector {
path,
case: None,
input: None,
};
let test = match solidity_adapter::Test::try_from(index_entity.path.as_path()) {
Ok(test) => test,
Err(error) => {
Summary::invalid(summary, None, identifier, error);
Summary::invalid(summary, TestDescription::default_for(selector), error);
return None;
}
};

Some(Self {
identifier,
selector,
index_entity,
test,
})
Expand Down Expand Up @@ -177,9 +184,12 @@ impl EthereumTest {
None => {
Summary::invalid(
summary,
Some(mode.to_owned()),
self.identifier.to_owned(),
anyhow::anyhow!("The Ethereum test `{}` sources are empty", self.identifier),
TestDescription {
group: None,
mode: Some(mode.clone()),
selector: self.selector.clone(),
},
anyhow::anyhow!("The Ethereum test `{}` sources are empty", &self.selector),
);
None
}
Expand All @@ -204,6 +214,12 @@ impl Buildable for EthereumTest {

let last_source = self.last_source(summary.clone(), &mode)?;

let test_description = TestDescription {
group: None,
mode: Some(mode.clone()),
selector: self.selector.clone(),
};

let (contract_address, libraries_addresses, libraries) = match self.get_addresses(
EraVMAddressIterator::new(),
calls.as_slice(),
Expand All @@ -213,15 +229,15 @@ impl Buildable for EthereumTest {
(contract_address, libraries_addresses, libraries)
}
Err(error) => {
Summary::invalid(summary, Some(mode), self.identifier.to_owned(), error);
Summary::invalid(summary, test_description, error);
return None;
}
};

let evm_version = self.test.params.evm_version;
let eravm_input = match compiler
.compile_for_eravm(
self.identifier.to_owned(),
self.selector.to_string(),
self.test.sources.clone(),
libraries,
&mode,
Expand All @@ -232,7 +248,7 @@ impl Buildable for EthereumTest {
{
Ok(output) => output,
Err(error) => {
Summary::invalid(summary, Some(mode), self.identifier.to_owned(), error);
Summary::invalid(summary, test_description, error);
return None;
}
};
Expand All @@ -244,7 +260,7 @@ impl Buildable for EthereumTest {
) {
Ok(instance) => instance,
Err(error) => {
Summary::invalid(summary, Some(mode), self.identifier.to_owned(), error);
Summary::invalid(summary, test_description, error);
return None;
}
};
Expand All @@ -257,12 +273,7 @@ impl Buildable for EthereumTest {
) {
Ok(case) => case,
Err(error) => {
Summary::invalid(
summary.clone(),
Some(mode),
self.identifier.to_owned(),
error,
);
Summary::invalid(summary.clone(), test_description, error);
return None;
}
};
Expand All @@ -281,7 +292,7 @@ impl Buildable for EthereumTest {
.collect();

Some(Test::new(
self.identifier.to_owned(),
self.selector.to_string(),
vec![case],
mode,
self.index_entity.group.clone(),
Expand All @@ -305,6 +316,11 @@ impl Buildable for EthereumTest {
let mut calls = self.test.calls.clone();
self.insert_deploy_calls(&mut calls);

let test_description = TestDescription {
group: None,
mode: Some(mode.clone()),
selector: self.selector.clone(),
};
let last_source = self.last_source(summary.clone(), &mode)?;

let (contract_address, libraries_addresses, libraries) = match self.get_addresses(
Expand All @@ -316,15 +332,15 @@ impl Buildable for EthereumTest {
(contract_address, libraries_addresses, libraries)
}
Err(error) => {
Summary::invalid(summary, Some(mode), self.identifier.to_owned(), error);
Summary::invalid(summary, test_description, error);
return None;
}
};

let evm_version = self.test.params.evm_version;
let evm_input = match compiler
.compile_for_evm(
self.identifier.to_owned(),
self.selector.to_string(),
self.test.sources.clone(),
libraries,
&mode,
Expand All @@ -336,7 +352,7 @@ impl Buildable for EthereumTest {
{
Ok(output) => output,
Err(error) => {
Summary::invalid(summary, Some(mode), self.identifier.to_owned(), error);
Summary::invalid(summary, test_description, error);
return None;
}
};
Expand All @@ -348,7 +364,7 @@ impl Buildable for EthereumTest {
) {
Ok(instance) => instance,
Err(error) => {
Summary::invalid(summary, Some(mode), self.identifier.to_owned(), error);
Summary::invalid(summary, test_description, error);
return None;
}
};
Expand All @@ -361,18 +377,13 @@ impl Buildable for EthereumTest {
) {
Ok(case) => case,
Err(error) => {
Summary::invalid(
summary.clone(),
Some(mode),
self.identifier.to_owned(),
error,
);
Summary::invalid(summary.clone(), test_description, error);
return None;
}
};

Some(Test::new(
self.identifier.to_owned(),
self.selector.path.to_string(),
vec![case],
mode,
self.index_entity.group.clone(),
Expand Down
Loading

0 comments on commit 2b79711

Please sign in to comment.