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

@@ -56,6 +56,7 @@ trie-db = "0.11.0"
patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" }
rand = "0.4"
rayon = "1.1"
regex = "1.3.9"
rlp = { version = "0.3.0", features = ["ethereum"] }
rlp_derive = { path = "../util/rlp-derive" }
rustc-hex = "1.0"
@@ -71,7 +72,7 @@ triehash-ethereum = { version = "0.2", path = "../util/triehash-ethereum" }
unexpected = { path = "../util/unexpected" }
using_queue = { path = "../miner/using-queue" }
vm = { path = "vm" }
walkdir = "2"
walkdir = "2.3"
wasm = { path = "wasm" }
[dev-dependencies]

View File

@@ -0,0 +1,204 @@
{
"name": "Istanbul (test)",
"engine": {
"Ethash": {
"params": {
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0d",
"blockReward": "0x1BC16D674EC80000",
"homesteadTransition": "0x0",
"eip100bTransition": "0x0",
"difficultyBombDelays": {
"0": 5000000
}
}
}
},
"params": {
"gasLimitBoundDivisor": "0x0400",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"accountStartNonce": "0x00",
"maximumExtraDataSize": "0x20",
"minGasLimit": "0x1388",
"networkID" : "0x1",
"maxCodeSize": 24576,
"maxCodeSizeTransition": "0x0",
"eip150Transition": "0x0",
"eip160Transition": "0x0",
"eip161abcTransition": "0x0",
"eip161dTransition": "0x0",
"eip140Transition": "0x0",
"eip211Transition": "0x0",
"eip214Transition": "0x0",
"eip155Transition": "0x0",
"eip658Transition": "0x0",
"eip145Transition": "0x0",
"eip1014Transition": "0x0",
"eip1052Transition": "0x0",
"eip1283Transition": "0x0",
"eip1283DisableTransition": "0x0",
"eip1283ReenableTransition": "0x0",
"eip1344Transition": "0x0",
"eip1706Transition": "0x0",
"eip1884Transition": "0x0",
"eip2028Transition": "0x0",
"eip2315Transition": "0x0"
},
"genesis": {
"seal": {
"ethereum": {
"nonce": "0x0000000000000042",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
},
"difficulty": "0x400000000",
"author": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0x1388"
},
"accounts": {
"0000000000000000000000000000000000000001": { "balance": "1", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
"0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
"0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
"0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
"0000000000000000000000000000000000000005": { "builtin": { "name": "modexp", "activate_at": "0x00", "pricing": { "modexp": { "divisor": 20 } } } },
"0000000000000000000000000000000000000006": {
"builtin": {
"name": "alt_bn128_add",
"pricing": {
"0": {
"price": { "alt_bn128_const_operations": { "price": 500 }}
},
"0": {
"info": "EIP 1108 transition",
"price": { "alt_bn128_const_operations": { "price": 150 }}
}
}
}
},
"0000000000000000000000000000000000000007": {
"builtin": {
"name": "alt_bn128_mul",
"pricing": {
"0": {
"price": { "alt_bn128_const_operations": { "price": 40000 }}
},
"0": {
"info": "EIP 1108 transition",
"price": { "alt_bn128_const_operations": { "price": 6000 }}
}
}
}
},
"0000000000000000000000000000000000000008": {
"builtin": {
"name": "alt_bn128_pairing",
"pricing": {
"0": {
"price": { "alt_bn128_pairing": { "base": 100000, "pair": 80000 }}
},
"0": {
"info": "EIP 1108 transition",
"price": { "alt_bn128_pairing": { "base": 45000, "pair": 34000 }}
}
}
}
},
"0000000000000000000000000000000000000009": {
"builtin": {
"name": "blake2_f",
"activate_at": "0x00",
"pricing": {
"blake2_f": {
"gas_per_round": 1
}
}
}
},
"000000000000000000000000000000000000000a": {
"builtin": {
"name": "bls12_381_g1_add",
"activate_at": "0",
"pricing": {
"bls12_const_operations": { "price": 600 }
}
}
},
"000000000000000000000000000000000000000b": {
"builtin": {
"name": "bls12_381_g1_mul",
"activate_at": "0",
"pricing": {
"bls12_const_operations": { "price": 12000 }
}
}
},
"000000000000000000000000000000000000000c": {
"builtin": {
"name": "bls12_381_g1_multiexp",
"activate_at": "0",
"pricing": {
"bls12_g1_multiexp": { "base": 12000 }
}
}
},
"000000000000000000000000000000000000000d": {
"builtin": {
"name": "bls12_381_g2_add",
"activate_at": "0",
"pricing": {
"bls12_const_operations": { "price": 4500 }
}
}
},
"000000000000000000000000000000000000000e": {
"builtin": {
"name": "bls12_381_g2_mul",
"activate_at": "0",
"pricing": {
"bls12_const_operations": { "price": 55000 }
}
}
},
"000000000000000000000000000000000000000f": {
"builtin": {
"name": "bls12_381_g2_multiexp",
"activate_at": "0",
"pricing": {
"bls12_g2_multiexp": { "base": 55000 }
}
}
},
"0000000000000000000000000000000000000010": {
"builtin": {
"name": "bls12_381_pairing",
"activate_at": "0",
"pricing": {
"bls12_pairing": { "base": 115000, "pair": 23000 }
}
}
},
"0000000000000000000000000000000000000011": {
"builtin": {
"name": "bls12_381_fp_to_g1",
"activate_at": "0",
"pricing": {
"bls12_const_operations": { "price": 5500 }
}
}
},
"0000000000000000000000000000000000000012": {
"builtin": {
"name": "bls12_381_fp2_to_g2",
"activate_at": "0",
"pricing": {
"bls12_const_operations": { "price": 110000 }
}
}
}
}
}

View File

@@ -0,0 +1,108 @@
{
"name": "Byzantium to Constantinople (test)",
"engine": {
"Ethash": {
"params": {
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0d",
"blockReward": {
"0x0": "0x29A2241AF62C0000",
"0x5": "0x1BC16D674EC80000"
},
"homesteadTransition": "0x0",
"eip100bTransition": "0x0",
"difficultyBombDelays": {
"0": 3000000
}
}
}
},
"params": {
"gasLimitBoundDivisor": "0x0400",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"accountStartNonce": "0x00",
"maximumExtraDataSize": "0x20",
"minGasLimit": "0x1388",
"networkID" : "0x1",
"maxCodeSize": 24576,
"maxCodeSizeTransition": "0x0",
"eip150Transition": "0x0",
"eip160Transition": "0x0",
"eip161abcTransition": "0x0",
"eip161dTransition": "0x0",
"eip140Transition": "0x0",
"eip211Transition": "0x0",
"eip214Transition": "0x0",
"eip155Transition": "0x0",
"eip658Transition": "0x0",
"eip145Transition": "0x5",
"eip1014Transition": "0x5",
"eip1052Transition": "0x5",
"eip1283Transition": "0x5" ,
"eip1283DisableTransition": "0x5"
},
"genesis": {
"seal": {
"ethereum": {
"nonce": "0x0000000000000042",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
},
"difficulty": "0x400000000",
"author": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0x1388"
},
"accounts": {
"0000000000000000000000000000000000000001": { "balance": "1", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
"0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
"0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
"0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
"0000000000000000000000000000000000000005": { "builtin": { "name": "modexp", "activate_at": "0x00", "pricing": { "modexp": { "divisor": 20 } } } },
"0000000000000000000000000000000000000006": {
"builtin": {
"name": "alt_bn128_add",
"pricing": {
"0": {
"price": { "alt_bn128_const_operations": { "price": 500 }}
},
"0x7fffffffffffff": {
"info": "EIP 1108 transition",
"price": { "alt_bn128_const_operations": { "price": 150 }}
}
}
}
},
"0000000000000000000000000000000000000007": {
"builtin": {
"name": "alt_bn128_mul",
"pricing": {
"0": {
"price": { "alt_bn128_const_operations": { "price": 40000 }}
},
"0x7fffffffffffff": {
"info": "EIP 1108 transition",
"price": { "alt_bn128_const_operations": { "price": 6000 }}
}
}
}
},
"0000000000000000000000000000000000000008": {
"builtin": {
"name": "alt_bn128_pairing",
"pricing": {
"0": {
"price": { "alt_bn128_pairing": { "base": 100000, "pair": 80000 }}
},
"0x7fffffffffffff": {
"info": "EIP 1108 transition",
"price": { "alt_bn128_pairing": { "base": 45000, "pair": 34000 }}
}
}
}
}
}
}

View File

@@ -3,6 +3,10 @@
{
"path": "res/ethereum/tests/BlockchainTests",
"skip" : []
},
{
"path": "res/ethereum/tests/LegacyTests/Constantinople/BlockchainTests",
"skip" : []
}
],
"state": [
@@ -10,6 +14,11 @@
"path": "res/ethereum/tests/GeneralStateTests",
"skip" : []
},
{
"path": "res/ethereum/tests//LegacyTests/Constantinople/GeneralStateTests",
"skip" : []
}
],
"difficulty": [

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()
};