Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.

Commit 9b60146

Browse files
authored
Merge pull request #22 from mandreyel/fix/ignore-geth-failing-tests
fix: skip test cases failing in geth
2 parents c1e6512 + 450ea8e commit 9b60146

File tree

3 files changed

+72
-28
lines changed

3 files changed

+72
-28
lines changed

ethjson/src/uint.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,25 @@ impl<'a> Visitor<'a> for UintVisitor {
8282
where
8383
E: Error,
8484
{
85+
let parse = |value: &str| {
86+
if value.len() > 64 {
87+
return Err(Error::custom(
88+
format!(
89+
"Invalid hex value 0x{value}: value too big (length={})",
90+
value.len()
91+
)
92+
.as_str(),
93+
));
94+
}
95+
U256::from_str(value)
96+
.map_err(|e| Error::custom(format!("Invalid hex value 0x{value}: {e}").as_str()))
97+
};
98+
8599
let value = match value.len() {
86100
0 => U256::from(0),
87101
2 if value.starts_with("0x") => U256::from(0),
88-
_ if value.starts_with("0x") => {
89-
if value.len() > 66 {
90-
return Err(Error::custom(
91-
format!("Invalid hex value {}: value too big", value).as_str(),
92-
));
93-
}
94-
U256::from_str(&value[2..]).map_err(|e| {
95-
Error::custom(format!("Invalid hex value {}: {}", value, e).as_str())
96-
})?
97-
}
102+
_ if value.starts_with("0x:bigint 0x") => parse(&value[12..])?,
103+
_ if value.starts_with("0x") => parse(&value[2..])?,
98104
_ => U256::from_dec_str(value).map_err(|e| {
99105
Error::custom(format!("Invalid decimal value {}: {:?}", value, e).as_str())
100106
})?,
@@ -177,7 +183,7 @@ mod test {
177183
assert_eq!(
178184
err.to_string(),
179185
format!(
180-
"Invalid hex value {}: value too big at line 1 column 69",
186+
"Invalid hex value {}: value too big (length=65) at line 1 column 69",
181187
hex
182188
)
183189
);

jsontests/src/state.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,18 @@ fn test_run(name: &str, test: Test) {
261261
// Test case may be expected to fail with an unsupported tx type if the current fork is
262262
// older than Berlin (see EIP-2718). However, this is not implemented in sputnik itself and rather
263263
// in the code hosting sputnik. https://github.com/rust-blockchain/evm/pull/40
264-
let tx_type = TxType::from_txbytes(&state.txbytes);
265-
if matches!(
266-
spec,
267-
ForkSpec::EIP150
268-
| ForkSpec::EIP158 | ForkSpec::Frontier
269-
| ForkSpec::Homestead
270-
| ForkSpec::Byzantium
271-
| ForkSpec::Constantinople
272-
| ForkSpec::ConstantinopleFix
273-
| ForkSpec::Istanbul
274-
) && tx_type != TxType::Legacy
275-
&& state.expect_exception == Some("TR_TypeNotSupported".to_string())
276-
{
264+
let expect_tx_type_not_supported =
265+
matches!(
266+
spec,
267+
ForkSpec::EIP150
268+
| ForkSpec::EIP158 | ForkSpec::Frontier
269+
| ForkSpec::Homestead | ForkSpec::Byzantium
270+
| ForkSpec::Constantinople
271+
| ForkSpec::ConstantinopleFix
272+
| ForkSpec::Istanbul
273+
) && TxType::from_txbytes(&state.txbytes) != TxType::Legacy
274+
&& state.expect_exception.as_deref() == Some("TR_TypeNotSupported");
275+
if expect_tx_type_not_supported {
277276
continue;
278277
}
279278

jsontests/tests/state.rs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use evm_jsontests::state as statetests;
2-
use std::collections::HashMap;
32
use std::fs::{self, File};
43
use std::io::BufReader;
54
use std::path::PathBuf;
5+
use std::{collections::HashMap, path::Path};
66

77
pub fn run(dir: &str) {
88
let _ = env_logger::try_init();
@@ -20,18 +20,57 @@ pub fn run(dir: &str) {
2020

2121
let path = entry.path();
2222

23-
let file = File::open(path).expect("Open file failed");
23+
if should_skip(&path) {
24+
println!("Skipping test case {path:?}");
25+
continue;
26+
}
27+
28+
let file = File::open(&path).expect("Open file failed");
2429

2530
let reader = BufReader::new(file);
26-
let coll: HashMap<String, statetests::Test> =
27-
serde_json::from_reader(reader).expect("Parse test cases failed");
31+
let coll: HashMap<String, statetests::Test> = serde_json::from_reader(reader)
32+
.unwrap_or_else(|e| {
33+
panic!("Parsing test case {:?} failed: {:?}", path, e);
34+
});
2835

2936
for (name, test) in coll {
3037
statetests::test(&name, test);
3138
}
3239
}
3340
}
3441

42+
// NOTE: Add a comment here explaining why you're skipping a test case.
43+
const SKIPPED_CASES: &[&str] = &[
44+
// This is an expected failure case for testing that the VM rejects
45+
// transactions with values that are too large, but it's geth
46+
// specific because geth parses the hex string later in the test
47+
// run, whereas this test runner parses everything up-front before
48+
// running the test.
49+
"stTransactionTest/ValueOverflow",
50+
// The below test cases are failing in geth too and as such are
51+
// skipped here until they are fixed there (otherwise we don't know
52+
// what the expected value should be for each test output).
53+
"stTransactionTest/HighGasPrice",
54+
"stCreateTest/CreateTransactionHighNonce",
55+
];
56+
57+
fn should_skip(path: &Path) -> bool {
58+
let matches = |case: &str| {
59+
let file_stem = path.file_stem().unwrap();
60+
let dir_path = path.parent().unwrap();
61+
let dir_name = dir_path.file_name().unwrap();
62+
Path::new(dir_name).join(file_stem) == Path::new(case)
63+
};
64+
65+
for case in SKIPPED_CASES {
66+
if matches(case) {
67+
return true;
68+
}
69+
}
70+
71+
false
72+
}
73+
3574
#[test]
3675
fn st_args_zero_one_balance() {
3776
run("res/ethtests/GeneralStateTests/stArgsZeroOneBalance")

0 commit comments

Comments
 (0)