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

testool update #1237

Merged
merged 4 commits into from
Apr 28, 2024
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
40 changes: 33 additions & 7 deletions testool/Config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[[suite]]
id="default"
path="tests/src/GeneralStateTestsFiller/**/*"
paths = [
"tests/src/GeneralStateTestsFiller/**/*"
]
max_gas = 500000
max_steps = 1000
ignore_tests = [
Expand All @@ -11,47 +13,71 @@ ignore_tests = [

[[suite]]
id="EIP1153"
path = "tests/src/GeneralStateTestsFiller/Cancun/stEIP1153-transientStorage/*"
paths = [
"tests/src/GeneralStateTestsFiller/Cancun/stEIP1153-transientStorage/*"
]
max_gas = 500000
max_steps = 1000
ignore_tests = []

[[suite]]
id="EIP2930"
path="tests/src/GeneralStateTestsFiller/stEIP2930/*"
paths = [
"tests/src/GeneralStateTestsFiller/stEIP2930/*"
]
max_gas = 500000
max_steps = 1000
ignore_tests = []

[[suite]]
id="EIP1559"
path="tests/src/GeneralStateTestsFiller/stEIP1559/**/*"
paths = [
"tests/src/GeneralStateTestsFiller/stEIP1559/**/*"
]
max_gas = 500000
max_steps = 1000
ignore_tests = []


[[suite]]
id="precompile"
path="tests/src/GeneralStateTestsFiller/stPreCompiledContracts/*"
paths = [
"tests/src/GeneralStateTestsFiller/stPreCompiledContracts/*"
]
max_gas = 500000
max_steps = 1000
ignore_tests = []

[[suite]]
id="precompile2"
path="tests/src/GeneralStateTestsFiller/stPreCompiledContracts2/*"
paths = [
"tests/src/GeneralStateTestsFiller/stPreCompiledContracts2/*"
]
max_gas = 500000
max_steps = 1000
ignore_tests = []

[[suite]]
id="nightly"
path="tests/src/GeneralStateTestsFiller/**/*"
paths = [
"tests/src/GeneralStateTestsFiller/**/*"
]
max_gas = 0
max_steps = 100000
ignore_tests=[]

[[suite]]
id="curie"
paths = [
"tests/src/GeneralStateTestsFiller/stEIP1559/*",
"tests/src/GeneralStateTestsFiller/stEIP2930/*",
"tests/src/GeneralStateTestsFiller/Cancun/stEIP1153-transientStorage/*",
"tests/src/GeneralStateTestsFiller/Cancun/stEIP5656-MCOPY/*"
]
max_gas = 0
max_steps = 100000
ignore_tests = []

[[set]]
id = "sigkill"
desc = "tests that sigkill"
Expand Down
11 changes: 7 additions & 4 deletions testool/src/abi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use anyhow::Result;
use eth_types::{Bytes, U256};
use sha3::Digest;
use std::cell::RefCell;

thread_local! {
/// dirty hack to enable normalization
pub static ENABLE_NORMALIZE: RefCell<bool> = RefCell::new(true);
}

/// encodes an abi call (e.g. "f(uint) 1")
pub fn encode_funccall(spec: &str) -> Result<Bytes> {
Expand Down Expand Up @@ -74,10 +80,7 @@ pub fn encode_funccall(spec: &str) -> Result<Bytes> {
state_mutability: StateMutability::Payable,
constant: Some(false),
};
// Shoule be false for stEIP1153-transientStorage,
// due to this bughttps://github.com/ethereum/tests/issues/1369
let enable_normalize = true;
let bytes: Vec<u8> = if !enable_normalize {
let bytes: Vec<u8> = if !ENABLE_NORMALIZE.with_borrow(|b| *b) {
let encoded_params = ethers_core::abi::encode(&args);
let short_signature: Vec<u8> = sha3::Keccak256::digest(tokens[0])[0..4].to_vec();
let bytes: Vec<u8> = short_signature.into_iter().chain(encoded_params).collect();
Expand Down
4 changes: 2 additions & 2 deletions testool/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Config {
#[derive(Debug, Clone, Deserialize)]
pub struct TestSuite {
pub id: String,
pub path: String,
pub paths: Vec<String>,
pub max_gas: u64,
pub max_steps: u64,

Expand All @@ -28,7 +28,7 @@ impl Default for TestSuite {
fn default() -> Self {
Self {
id: "default".to_string(),
path: String::default(),
paths: vec![],
max_gas: u64::MAX,
max_steps: u64::MAX,
ignore_tests: Some(Filter::any()),
Expand Down
6 changes: 5 additions & 1 deletion testool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ fn go() -> Result<()> {
let compiler = Compiler::new(true, Some(PathBuf::from(CODEHASH_FILE)))?;
let suite = config.suite(&args.suite)?.clone();
let mut state_tests = load_statetests_suite(&suite, config, compiler)?;
log::info!("{} tests collected in {}", state_tests.len(), suite.path);
log::info!(
"{} tests collected in {}",
state_tests.len(),
suite.paths.join(", ")
);

if args.ls {
let mut list: Vec<_> = state_tests.into_iter().map(|t| t.id).collect();
Expand Down
8 changes: 7 additions & 1 deletion testool/src/statetest/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ pub fn load_statetests_suite(
let skip_paths: Vec<&String> = config.skip_paths.iter().flat_map(|t| &t.paths).collect();
let skip_tests: Vec<&String> = config.skip_tests.iter().flat_map(|t| &t.tests).collect();

let tcs = glob::glob(&suite.path)
let tcs = suite
.paths
.iter()
.map(|p| glob::glob(p))
.collect::<Result<Vec<glob::Paths>, glob::PatternError>>()
.context("failed to read glob")?
.into_iter()
.flatten()
.filter_map(|v| v.ok())
.filter(|f| {
!skip_paths
Expand Down
9 changes: 8 additions & 1 deletion testool/src/statetest/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{
parse,
spec::{AccountMatch, Env, StateTest, DEFAULT_BASE_FEE},
};
use crate::{utils::MainnetFork, Compiler};
use crate::{abi, utils::MainnetFork, Compiler};
use anyhow::{anyhow, bail, Context, Result};
use eth_types::{geth_types::Account, Address, Bytes, H256, U256};
use ethers_core::{k256::ecdsa::SigningKey, utils::secret_key_to_address};
Expand Down Expand Up @@ -50,6 +50,13 @@ impl<'a> YamlStateTestBuilder<'a> {

/// generates `StateTest` vectors from a ethereum yaml test specification
pub fn load_yaml(&mut self, path: &str, source: &str) -> Result<Vec<StateTest>> {
// Shoule be false for stEIP1153-transientStorage,
// due to this bug https://github.com/ethereum/tests/issues/1369
if path.contains("stEIP1153-transientStorage") {
abi::ENABLE_NORMALIZE.with_borrow_mut(|b| *b = false)
} else {
abi::ENABLE_NORMALIZE.with_borrow_mut(|b| *b = true)
}
//log::trace!("load_yaml {path}");
// get the yaml root element
let doc = yaml_rust::YamlLoader::load_from_str(source)
Expand Down
Loading