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: Parse expect_exception and add to Case struct #10

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 15 additions & 5 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 super::{
filler_structure::{ExpectStructure, FillerStructure, LabelValue, U256Parsed},
filler_structure::{self, ExpectStructure, FillerStructure, LabelValue, U256Parsed},

Check failure on line 20 in evm_tester/src/test/case/mod.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `self`
test_structure::{env_section::EnvSection, pre_state::PreState, TestStructure},
};

Expand All @@ -29,6 +29,7 @@
pub transaction: Transaction,
pub post_state: Option<PostStateForCase>,
pub expected_state: HashMap<web3::types::Address, AccountFillerStruct>,
pub expect_exception: bool,
pub env: EnvSection,
}

Expand Down Expand Up @@ -85,14 +86,22 @@
let mut cases = vec![];

let mut indexes_for_expected_results = vec![];
let mut expected_results_states: Vec<HashMap<zksync_types::H160, AccountFillerStruct>> =
vec![];
// The boolean represents if the expectException flag is set.
let mut expected_results_states: Vec<(
HashMap<zksync_types::H160, AccountFillerStruct>,
bool,
)> = vec![];

for expected_struct in &test_filler.expect {
let mut indexes_for_struct = (vec![], vec![], vec![]);

let expected_accounts = ExpectStructure::get_expected_result(&expected_struct.result);
expected_results_states.push(expected_accounts);
// TODO: maybe filter only the exceptions that mark it as "invalid".
let expect_exception = expected_struct
.expect_exception
.as_ref()
.is_some_and(|m| !m.is_empty());
expected_results_states.push((expected_accounts, expect_exception));

if let Some(indexes) = expected_struct.indexes.as_ref() {
fill_indexes_for_expected_states(&indexes.data, &mut indexes_for_struct.0);
Expand Down Expand Up @@ -186,7 +195,7 @@
}

let index: usize = expected_state_index.try_into().unwrap();
let expected_state = &expected_results_states[index];
let (expected_state, expect_exception) = &expected_results_states[index];

cases.push(Case {
label: label.unwrap_or(case_idx.to_string()),
Expand All @@ -195,6 +204,7 @@
post_state: None,
expected_state: expected_state.clone(),
env: test_definition.env.clone(),
expect_exception: *expect_exception,
});

case_counter += 1;
Expand Down
3 changes: 3 additions & 0 deletions evm_tester/src/test/filler_structure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,12 @@ pub enum AccountFillerStructMaybe {
}

#[derive(Debug, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct ExpectStructure {
pub indexes: Option<ExpectedIndexesStructure>,
pub result: HashMap<AddressMaybe, AccountFillerStructMaybe>,
pub expect_exception:
Option<HashMap<GenericSerializedSimpleValue, GenericSerializedSimpleValue>>,
}

impl ExpectStructure {
Expand Down
Loading