Update ethereum/tests

This commit is contained in:
adria0.eth
2020-09-10 08:04:14 +02:00
committed by GitHub
parent c84d82580a
commit dd38573a28
22 changed files with 495 additions and 76 deletions

View File

@@ -104,10 +104,14 @@ impl<'a> EvmTestClient<'a> {
ForkSpec::ConstantinopleFix => Some(ethereum::new_constantinople_fix_test()),
ForkSpec::Istanbul => Some(ethereum::new_istanbul_test()),
ForkSpec::EIP158ToByzantiumAt5 => Some(ethereum::new_transition_test()),
ForkSpec::ByzantiumToConstantinopleFixAt5 => {
Some(ethereum::new_byzantium_to_constantinoplefixat5_test())
}
ForkSpec::Berlin => Some(ethereum::new_berlin_test()),
ForkSpec::FrontierToHomesteadAt5
| ForkSpec::HomesteadToDaoAt5
| ForkSpec::HomesteadToEIP150At5 => None,
ForkSpec::ByzantiumToConstantinopleAt5 => None,
| ForkSpec::HomesteadToEIP150At5
| ForkSpec::ByzantiumToConstantinopleAt5 => None,
}
}

View File

@@ -271,6 +271,19 @@ pub fn new_istanbul_test() -> Spec {
)
}
/// Create a new BizantiumToConstaninopleFixAt5 era spec.
pub fn new_byzantium_to_constantinoplefixat5_test() -> Spec {
load(
None,
include_bytes!("../../res/ethereum/byzantium_to_constantinoplefixat5_test.json"),
)
}
/// Create a new Foundation Berlin era spec.
pub fn new_berlin_test() -> Spec {
load(None, include_bytes!("../../res/ethereum/berlin_test.json"))
}
/// Create a new Musicoin-MCIP3-era spec.
pub fn new_mcip3_test() -> Spec {
load(None, include_bytes!("../../res/ethereum/mcip3_test.json"))

View File

@@ -51,6 +51,16 @@ const STACK_SIZE_ENTRY_OVERHEAD: usize = 100 * 1024;
/// Entry stack overhead prior to execution.
const STACK_SIZE_ENTRY_OVERHEAD: usize = 20 * 1024;
#[cfg(any(test, feature = "test-helpers"))]
/// Precompile that can never be prunned from state trie (0x3, only in tests)
const UNPRUNABLE_PRECOMPILE_ADDRESS: Option<Address> = Some(ethereum_types::H160([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
]));
#[cfg(not(any(test, feature = "test-helpers")))]
/// Precompile that can never be prunned from state trie (none)
const UNPRUNABLE_PRECOMPILE_ADDRESS: Option<Address> = None;
/// Returns new address created from address, nonce, and code hash
pub fn contract_address(
address_scheme: CreateContractAddress,
@@ -441,6 +451,11 @@ impl<'a> CallCreateExecutive<'a> {
| Ok(FinalizationResult {
apply_state: false, ..
}) => {
if let Some(addr) = UNPRUNABLE_PRECOMPILE_ADDRESS {
if un_substate.touched.contains(&addr) {
substate.touched.insert(addr);
}
}
state.revert_to_checkpoint();
}
Ok(_) | Err(vm::Error::Internal(_)) => {
@@ -553,9 +568,18 @@ impl<'a> CallCreateExecutive<'a> {
})
}
} else {
// We need balance > 0 in precompiles to be EIP161 compliant, see PR#11597.
// Since RIPEMD160 was removed in mainnet block #2686351, this is activated only in
// tests to check this specific irregular state transition.
if let Some(unprunable_addr) = UNPRUNABLE_PRECOMPILE_ADDRESS {
if unprunable_addr != params.code_address
&& state.balance(&params.code_address)?.is_zero()
{
substate.touched.remove(&params.code_address);
}
}
// just drain the whole gas
state.revert_to_checkpoint();
Err(vm::Error::OutOfGas)
}
};

View File

@@ -135,10 +135,15 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(
let mut failed = Vec::new();
for (name, blockchain) in tests.into_iter() {
if !super::debug_include_test(&name) {
continue;
}
let skip_test = test
.skip
.iter()
.any(|block_test| block_test.names.contains(&name));
if skip_test {
info!(" SKIPPED {:?} {:?}", name, blockchain.network);
continue;

View File

@@ -37,6 +37,10 @@ pub fn json_difficulty_test<H: FnMut(&str, HookType)>(
let engine = &spec.engine;
for (name, test) in tests.into_iter() {
if !super::debug_include_test(&name) {
continue;
}
start_stop_hook(&name, HookType::OnStart);
let mut parent_header = Header::new();

View File

@@ -252,6 +252,10 @@ pub fn json_executive_test<H: FnMut(&str, HookType)>(
let mut failed = Vec::new();
for (name, vm) in tests.into_iter() {
if !super::debug_include_test(&name) {
continue;
}
start_stop_hook(&format!("{}", name), HookType::OnStart);
let mut fail = false;

View File

@@ -27,5 +27,5 @@ mod trie;
pub use self::{
executive::json_executive_test,
test_common::{find_json_files_recursive, HookType},
test_common::{debug_include_test, find_json_files_recursive, HookType},
};

View File

@@ -236,7 +236,10 @@ fn ethereum_json_tests() {
let runner =
TestRunner::load(content.as_slice()).expect("cannot load ethereum tests spec file");
println!("----------------------------------------------------");
let result = runner.run();
let result = match std::env::var_os("TEST_DEBUG") {
Some(_) => runner.run_without_par(),
_ => runner.run(),
};
println!("----------------------------------------------------");
flushln!(
"SUCCESS: {} FAILED: {} {:?}",

View File

@@ -56,6 +56,10 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(
let mut failed = Vec::new();
for (name, test) in tests.into_iter() {
if !super::debug_include_test(&name) {
continue;
}
start_stop_hook(&name, HookType::OnStart);
{

View File

@@ -35,3 +35,14 @@ pub fn find_json_files_recursive(path: &PathBuf) -> Vec<PathBuf> {
.map(DirEntry::into_path)
.collect::<Vec<PathBuf>>()
}
pub fn debug_include_test(name: &str) -> bool {
match std::env::var_os("TEST_DEBUG") {
Some(s) => s.to_string_lossy().split_terminator(",").any(|expr| {
regex::Regex::new(expr)
.expect("invalid regex expression in TEST_DEBUG")
.is_match(name)
}),
_ => true,
}
}

View File

@@ -37,6 +37,10 @@ pub fn json_transaction_test<H: FnMut(&str, HookType)>(
));
let mut failed = Vec::new();
for (name, test) in tests.into_iter() {
if !super::debug_include_test(&name) {
continue;
}
start_stop_hook(&name, HookType::OnStart);
println!(" - tx: {} ", name);

View File

@@ -36,6 +36,10 @@ pub fn json_trie_test<H: FnMut(&str, HookType)>(
let mut failed = vec![];
for (name, test) in tests.into_iter() {
if !super::debug_include_test(&name) {
continue;
}
start_stop_hook(&name, HookType::OnStart);
let mut memdb = journaldb::new_memory_db();

View File

@@ -657,45 +657,49 @@ impl Spec {
gas_limit: U256::max_value(),
};
let from = Address::default();
for &(ref address, ref constructor) in self.constructors.iter() {
trace!(target: "spec", "run_constructors: Creating a contract at {}.", address);
trace!(target: "spec", " .. root before = {}", state.root());
let params = ActionParams {
code_address: address.clone(),
code_hash: Some(keccak(constructor)),
address: address.clone(),
sender: from.clone(),
origin: from.clone(),
gas: U256::max_value(),
gas_price: Default::default(),
value: ActionValue::Transfer(Default::default()),
code: Some(Arc::new(constructor.clone())),
data: None,
call_type: CallType::None,
params_type: ParamsType::Embedded,
};
if !self.constructors.is_empty() {
let from = Address::default();
for &(ref address, ref constructor) in self.constructors.iter() {
trace!(target: "spec", "run_constructors: Creating a contract at {}.", address);
trace!(target: "spec", " .. root before = {}", state.root());
let params = ActionParams {
code_address: address.clone(),
code_hash: Some(keccak(constructor)),
address: address.clone(),
sender: from.clone(),
origin: from.clone(),
gas: U256::max_value(),
gas_price: Default::default(),
value: ActionValue::Transfer(Default::default()),
code: Some(Arc::new(constructor.clone())),
data: None,
call_type: CallType::None,
params_type: ParamsType::Embedded,
};
let mut substate = Substate::new();
let mut substate = Substate::new();
{
let machine = self.engine.machine();
let schedule = machine.schedule(env_info.number);
let mut exec = Executive::new(&mut state, &env_info, &machine, &schedule);
if let Err(e) =
exec.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer)
{
warn!(target: "spec", "Genesis constructor execution at {} failed: {}.", address, e);
let machine = self.engine.machine();
let schedule = machine.schedule(env_info.number);
let mut exec = Executive::new(&mut state, &env_info, &machine, &schedule);
if let Err(e) =
exec.create(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer)
{
warn!(target: "spec", "Genesis constructor execution at {} failed: {}.", address, e);
}
}
}
if let Err(e) = state.commit() {
warn!(target: "spec", "Genesis constructor trie commit at {} failed: {}.", address, e);
}
if let Err(e) = state.commit() {
warn!(target: "spec", "Genesis constructor trie commit at {} failed: {}.", address, e);
}
trace!(target: "spec", " .. root after = {}", state.root());
trace!(target: "spec", " .. root after = {}", state.root());
}
} else {
state.populate_from(self.genesis_state().to_owned());
state.commit()?;
}
state.drop()
};