Skip to content

Commit

Permalink
evm-tests: extended debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Apr 12, 2024
1 parent 1392a36 commit be9e967
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 26 deletions.
9 changes: 9 additions & 0 deletions evm-tests/jsontests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ fn main() {
arg!(-w --very_verbose "Very verbose output")
.default_value("false")
.action(ArgAction::SetTrue),
)
.arg(
arg!(-p --print_state "When test failed print state")
.default_value("false")
.action(ArgAction::SetTrue),
),
)
.get_matches();
Expand Down Expand Up @@ -71,6 +76,7 @@ fn main() {
verbose: matches.get_flag("verbose"),
verbose_failed: matches.get_flag("verbose_failed"),
very_verbose: matches.get_flag("very_verbose"),
print_state: matches.get_flag("print_state"),
};
let mut tests_result = TestExecutionResult::new();
for src_name in matches.get_many::<PathBuf>("PATH").unwrap() {
Expand Down Expand Up @@ -183,9 +189,11 @@ const SKIPPED_CASES: &[&str] = &[
"stTransactionTest/HighGasPrice",
"stTransactionTest/HighGasPriceParis",
"stCreateTest/CreateTransactionHighNonce",
// Long execution
"stTimeConsuming/static_Call50000_sha256",
"stTimeConsuming/CALLBlake2f_MaxRounds",
"vmPerformance/loopMul",
"Pyspecs",
];

fn should_skip(path: &Path) -> bool {
Expand All @@ -194,6 +202,7 @@ fn should_skip(path: &Path) -> bool {
let dir_path = path.parent().unwrap();
let dir_name = dir_path.file_name().unwrap();
Path::new(dir_name).join(file_stem) == Path::new(case)
|| Path::new(dir_name) == Path::new(case)
};

for case in SKIPPED_CASES {
Expand Down
66 changes: 40 additions & 26 deletions evm-tests/jsontests/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use serde::Deserialize;
use sha3::{Digest, Keccak256};
use std::collections::BTreeMap;
use std::str::FromStr;
use std::u128;

#[derive(Default, Debug, Clone)]
pub struct VerboseOutput {
pub verbose: bool,
pub verbose_failed: bool,
pub very_verbose: bool,
pub print_state: bool,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -331,11 +331,6 @@ fn test_run(
.map_or_else(U256::zero, |acc| acc.balance);

for (i, state) in states.iter().enumerate() {
if verbose_output.very_verbose {
print!(" [{:?}] {}:{} ... ", spec, name, i);
flush();
}

let transaction = test.0.transaction.select(&state.indexes);
let mut backend = MemoryBackend::new(&vicinity, original_state.clone());

Expand Down Expand Up @@ -409,6 +404,13 @@ fn test_run(
}
}

if verbose_output.print_state {
println!(
"gas_limit: {gas_limit}\nused_gas: {:?}",
executor.used_gas()
);
}

let actual_fee = executor.fee(vicinity.gas_price);
// Forks after London burn miner rewards and thus have different gas fee
// calculation (see EIP-1559)
Expand Down Expand Up @@ -444,29 +446,41 @@ fn test_run(
};
tests_result.failed_tests.push(failed_res);
tests_result.failed += 1;
println!("failed\t<----");
// Print detailed state data
for (addr, acc) in backend.state().clone() {
// Decode balance
let mut write_buf = [0u8; 32];
acc.balance.to_big_endian(&mut write_buf[..]);
let balance = if acc.balance > U256::from(u128::MAX) {
hex::encode(write_buf)
} else {
format!("{:x?}", acc.balance.as_u128())
};

println!(" [{:?}] {}:{} ... failed\t<----", spec, name, i);
if verbose_output.print_state {
// Print detailed state data
println!(
"{:?}: {{\n balance: {}\n code: {:?}\n nonce: {}\n storage: {:#?}\n}}",
addr,
balance,
acc.code,
acc.nonce,
acc.storage
);
"expected_hash:\t{:?}\nactual_hash:\t{actual_hash:?}",
state.hash.0,
);
for (addr, acc) in backend.state().clone() {
// Decode balance
let mut write_buf = [0u8; 32];
acc.balance.to_big_endian(&mut write_buf[..]);
// Convert to balance to Hex format
// let balance = if acc.balance > U256::from(u128::MAX) {
// hex::encode(write_buf)
// } else {
// format!("{:x?}", acc.balance.as_u128())
// };
let balance = acc.balance.to_string();

println!(
"{:?}: {{\n balance: {}\n code: {:?}\n nonce: {}\n storage: {:#?}\n}}",
addr,
balance,
hex::encode(acc.code),
acc.nonce,
acc.storage
);
}
if let Some(e) = state.expect_exception.as_ref() {
println!("-> expect_exception: {e}");
}
}
} else if verbose_output.very_verbose {
println!("passed");
} else if verbose_output.very_verbose && !verbose_output.verbose_failed {
println!(" [{:?}] {}:{} ... passed", spec, name, i);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
access_list: &[(H160, Vec<H256>)],
) -> Result<(), ExitError> {
let transaction_cost = gasometer::create_transaction_cost(init_code, access_list);
// TODOFEE
println!("record_create_transaction_cost: {record_create_transaction_cost:?}");
let gasometer = &mut self.state.metadata_mut().gasometer;
gasometer.record_transaction(transaction_cost)
}
Expand Down Expand Up @@ -637,6 +639,8 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
}

let transaction_cost = gasometer::call_transaction_cost(&data, &access_list);
// TODOFEE
println!("transaction_cost: {transaction_cost:?}");
let gasometer = &mut self.state.metadata_mut().gasometer;
match gasometer.record_transaction(transaction_cost) {
Ok(()) => (),
Expand Down

0 comments on commit be9e967

Please sign in to comment.