Skip to content

Commit

Permalink
Remove old draft for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fkrause98 committed Jun 6, 2024
1 parent 45aafc4 commit afba6a5
Showing 1 changed file with 0 additions and 202 deletions.
202 changes: 0 additions & 202 deletions core/lib/multivm/src/versions/vm_latest/tests/evm_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5453,208 +5453,6 @@ struct GethTestData {
}
type GethTest = HashMap<String, GethTestData>;

#[test]
pub fn test_general_state() {
let curr_folder = std::path::Path::new("/Users/fran/Programming/zksync/zksync-era/core/lib/multivm/src/versions/vm_latest/tests/tests/GeneralStateTests/VMTests/vmArithmeticTest");

let test = std::fs::read_dir(curr_folder)
.expect("Folder Missing -- Did you start the submodule?")
.into_iter()
.map(|entry| entry.unwrap().path())
.map(|path| {
std::fs::read_to_string(path.clone())
.expect(&format!("Could not read path: {}", path.display()))
})
.map(|json| serde_json::from_str::<GethTest>(&json).unwrap())
.flat_map(|test| {
test.into_iter()
.map(|(test_name, test_data)| (test_name, test_data))
.collect_vec()
})
.collect_vec();

for (
test_name,
GethTestData {
pre,
transaction,
env,
},
) in test
{
println!("Running test: {}", test_name);
let mut storage =
InMemoryStorage::with_system_contracts(zksync_utils::bytecode::hash_bytecode);

let contracts_for_test = pre
.iter()
.map(|(address, bytecode)| {
let address = Address::from_str(&address).unwrap();
insert_evm_contract(
&mut storage,
bytecode.code.as_bytes().to_vec(),
Some(address),
);
return address;
})
.collect_vec();

let calldata = transaction
.data
.into_iter()
.flat_map(|call_data| call_data.into_bytes())
.collect_vec();

let mut vm = VmTesterBuilder::new(HistoryDisabled)
.with_storage(storage)
.with_random_rich_accounts(1)
.with_base_system_smart_contracts(BaseSystemContracts::load_from_disk())
.build();

let account = &mut vm.rich_accounts[0];

let tx = account.get_l2_tx_for_execute(
Execute {
contract_address: Some(*contracts_for_test.first().unwrap()),
calldata,
value: U256::zero(),
factory_deps: None,
},
None,
);

vm.vm.push_transaction(tx);

let debug_tracer = EvmDebugTracer::new();

let tracer_ptr = debug_tracer.into_tracer_pointer();

let VmExecutionResultAndLogs { result, .. } =
vm.vm.inspect(tracer_ptr.into(), VmExecutionMode::Batch);

assert!(!result.is_failed());
}
}
#[macro_export]
macro_rules! generate_evm_test {
($folder_path:expr, $name:tt) => {
#[test]
pub fn $name() {
let folder_path = format!(
"{}/src/versions/vm_latest/tests/tests/{}",
env!("CARGO_MANIFEST_DIR"),
$folder_path
);
let tests_folder = std::path::Path::new(&folder_path);
let test = std::fs::read_dir(tests_folder)
.expect(&format!(
"Folder '{}' is missing -- Did you start the submodule?",
&folder_path
))
.into_iter()
.map(|entry| {
let path = entry.unwrap().path();
let json = std::fs::read_to_string(&path)
.expect(&format!("Could not read path: {}", path.display()));
serde_json::from_str::<GethTest>(&json).expect(&format!(
"File: {} is not a proper geth test",
path.display()
))
})
.flat_map(|test| {
test.into_iter()
.map(|(test_name, test_data)| (test_name, test_data))
.collect_vec()
})
.collect_vec();

for (test_name, test_data) in test {
let GethTestData {
pre,
transaction,
env,
} = test_data;

let mut storage =
InMemoryStorage::with_system_contracts(zksync_utils::bytecode::hash_bytecode);

let contracts_for_test = pre
.iter()
.map(|(address, bytecode)| {
let address = Address::from_str(&address).unwrap();
insert_evm_contract(
&mut storage,
bytecode.code.as_bytes().to_vec(),
Some(address),
);
return address;
})
.collect_vec();

let calldata = transaction
.data
.into_iter()
.flat_map(|call_data| call_data.into_bytes())
.collect_vec();

let mut vm = VmTesterBuilder::new(HistoryDisabled)
.with_storage(storage)
.with_random_rich_accounts(1)
.with_base_system_smart_contracts(BaseSystemContracts::load_from_disk())
.build();

let account = &mut vm.rich_accounts[0];

let tx = account.get_l2_tx_for_execute(
Execute {
contract_address: Some(*contracts_for_test.first().unwrap()),
calldata,
value: U256::zero(),
factory_deps: None,
},
None,
);

vm.vm.push_transaction(tx);

let debug_tracer = EvmDebugTracer::new();

let tracer_ptr = debug_tracer.into_tracer_pointer();

let VmExecutionResultAndLogs { result, .. } =
vm.vm.inspect(tracer_ptr.into(), VmExecutionMode::Batch);

assert!(!result.is_failed());
}
}
};
}
#[cfg(test)]
macro_rules! generate_evm_tests {
() => {
#[test]
pub fn test_show_dirs() {
let folder_path = format!(
"{}/src/versions/vm_latest/tests/tests",
env!("CARGO_MANIFEST_DIR")
);
for entry in walkdir::WalkDir::new(&folder_path)
.min_depth(1)
.max_depth(10)
.filter_entry(|entry| {
entry
.as_ref()
.unwrap()
.path()
.extension()
.is_some_and(|extension| extension == "json")
})
{
println!("{}", entry.unwrap().path().display())
}
}
};
}
#[rstest::rstest]
fn evm_tests(
#[files("src/versions/vm_latest/tests/tests/GeneralStateTests/**/*.json")] file: PathBuf,
Expand Down

0 comments on commit afba6a5

Please sign in to comment.