openethereum/crates/ethcore/src/json_tests/local.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

207 lines
7.7 KiB
Rust
Raw Normal View History

use super::HookType;
use ethereum_types::U256;
use ethjson::{self, blockchain::Block};
use log::warn;
use rlp::RlpStream;
use std::path::Path;
Sunce86/eip 1559 (#393) * eip1559 hard fork activation * eip1559 hard fork activation 2 * added new transaction type for eip1559 * added base fee field to block header * fmt fix * added base fee calculation. added block header validation against base fee * fmt * temporarily added modified transaction pool * tx pool fix of PendingIterator * tx pool fix of UnorderedIterator * tx pool added test for set_scoring * transaction pool changes * added tests for eip1559 transaction and eip1559 receipt * added test for eip1559 transaction execution * block gas limit / block gas target handling * base fee verification moved out of engine * calculate_base_fee moved to EthereumMachine * handling of base_fee_per_gas as part of seal * handling of base_fee_per_gas changed. Different encoding/decoding of block header * eip1559 transaction execution - gas price handling * eip1559 transaction execution - verification, fee burning * effectiveGasPrice removed from the receipt payload (specs) * added support for 1559 txs in tx pool verification * added Aleut test network configuration * effective_tip_scaled replaced by typed_gas_price * eip 3198 - Basefee opcode * rpc - updated structs Block and Header * rpc changes for 1559 * variable renaming according to spec * - typed_gas_price renamed to effective_gas_price - elasticity_multiplier definition moved to update_schedule() * calculate_base_fee simplified * Evm environment context temporary fix for gas limit * fmt fix * fixed fake_sign::sign_call * temporary fix for GASLIMIT opcode to provide gas_target actually * gas_target removed from block header according to spec change: https://github.com/ethereum/EIPs/pull/3566 * tx pool verification fix * env_info base fee changed to Option * fmt fix * pretty format * updated ethereum tests * cache_pending refresh on each update of score * code review fixes * fmt fix * code review fix - changed handling of eip1559_base_fee_max_change_denominator * code review fix - modification.gas_price * Skip gas_limit_bump for Aura * gas_limit calculation changed to target ceil * gas_limit calculation will target ceil on 1559 activation block * transaction verification updated according spec: https://github.com/ethereum/EIPs/pull/3594 * updated json tests * ethereum json tests fix for base_fee
2021-06-04 12:12:24 +02:00
use types::{
transaction::{TypedTransaction, TypedTxId, UnverifiedTransaction},
BlockNumber,
};
use verification::queue::kind::blocks::Unverified;
pub fn json_local_block_en_de_test<H: FnMut(&str, HookType)>(
_test: &ethjson::test::LocalTests,
path: &Path,
json_data: &[u8],
start_stop_hook: &mut H,
) -> Vec<String> {
let tests = ethjson::local_tests::BlockEnDeTest::load(json_data).expect(&format!(
"Could not parse JSON chain test data from {}",
path.display()
));
let mut failed = Vec::new();
for (name, ref_block) in tests.into_iter() {
start_stop_hook(&name, HookType::OnStart);
Sunce86/eip 1559 (#393) * eip1559 hard fork activation * eip1559 hard fork activation 2 * added new transaction type for eip1559 * added base fee field to block header * fmt fix * added base fee calculation. added block header validation against base fee * fmt * temporarily added modified transaction pool * tx pool fix of PendingIterator * tx pool fix of UnorderedIterator * tx pool added test for set_scoring * transaction pool changes * added tests for eip1559 transaction and eip1559 receipt * added test for eip1559 transaction execution * block gas limit / block gas target handling * base fee verification moved out of engine * calculate_base_fee moved to EthereumMachine * handling of base_fee_per_gas as part of seal * handling of base_fee_per_gas changed. Different encoding/decoding of block header * eip1559 transaction execution - gas price handling * eip1559 transaction execution - verification, fee burning * effectiveGasPrice removed from the receipt payload (specs) * added support for 1559 txs in tx pool verification * added Aleut test network configuration * effective_tip_scaled replaced by typed_gas_price * eip 3198 - Basefee opcode * rpc - updated structs Block and Header * rpc changes for 1559 * variable renaming according to spec * - typed_gas_price renamed to effective_gas_price - elasticity_multiplier definition moved to update_schedule() * calculate_base_fee simplified * Evm environment context temporary fix for gas limit * fmt fix * fixed fake_sign::sign_call * temporary fix for GASLIMIT opcode to provide gas_target actually * gas_target removed from block header according to spec change: https://github.com/ethereum/EIPs/pull/3566 * tx pool verification fix * env_info base fee changed to Option * fmt fix * pretty format * updated ethereum tests * cache_pending refresh on each update of score * code review fixes * fmt fix * code review fix - changed handling of eip1559_base_fee_max_change_denominator * code review fix - modification.gas_price * Skip gas_limit_bump for Aura * gas_limit calculation changed to target ceil * gas_limit calculation will target ceil on 1559 activation block * transaction verification updated according spec: https://github.com/ethereum/EIPs/pull/3594 * updated json tests * ethereum json tests fix for base_fee
2021-06-04 12:12:24 +02:00
let block = Unverified::from_rlp(ref_block.rlp(), BlockNumber::max_value());
let block = match block {
Ok(block) => block,
Err(decoder_err) => {
warn!(target: "json-tests", "Error decoding test block: {:?}", decoder_err);
failed.push(name.clone());
continue;
}
};
if !is_same_block(&ref_block, &block) {
println!("block failed {:?}", block);
failed.push(name.clone())
}
start_stop_hook(&name, HookType::OnStop);
}
failed
}
fn rlp_append_block(block: &Unverified) -> Vec<u8> {
let mut rlps = RlpStream::new();
rlps.begin_list(3);
rlps.append(&block.header);
UnverifiedTransaction::rlp_append_list(&mut rlps, &block.transactions);
rlps.append_list(&block.uncles);
rlps.out()
}
pub fn is_same_block(ref_block: &Block, block: &Unverified) -> bool {
let test_exp = |exp: bool, err: &str| -> bool {
if !exp {
println!("Test mismatch on:{}", err);
}
exp
};
let header_ok = if let Some(ref header) = ref_block.header {
test_exp(*block.header.gas_used() == header.gas_used.0, "Gas used")
&& test_exp(
*block.header.uncles_hash() == header.uncles_hash.0,
"Uncles hash",
)
&& test_exp(
*block.header.transactions_root() == header.transactions_root.0,
"Transaction Root",
)
&& test_exp(
block.header.timestamp() == header.timestamp.0.as_u64(),
"Timestamp",
)
&& test_exp(
*block.header.state_root() == header.state_root.0,
"StateRoot",
)
&& test_exp(
*block.header.receipts_root() == header.receipts_root.0,
"ReceiptsRoot",
)
&& test_exp(
*block.header.parent_hash() == header.parent_hash.0,
"ParentHash",
)
&& test_exp(
block.header.number() == header.number.0.as_u64(),
"Blocn Number",
)
&& test_exp(block.header.hash() == header.hash.0, "Header hash")
&& test_exp(*block.header.gas_limit() == header.gas_limit.0, "GasLimit")
&& test_exp(*block.header.gas_used() == header.gas_used.0, "GasUsed")
&& test_exp(
*block.header.extra_data() == header.extra_data.0,
"ExtraData",
)
&& test_exp(
*block.header.difficulty() == header.difficulty.0,
"Difficulty",
)
&& test_exp(*block.header.author() == header.author.0, "Author")
&& test_exp(*block.header.log_bloom() == header.bloom.0, "Bloom")
} else {
true
};
// check transactions
let transaction_ok = if let Some(ref txs) = ref_block.transactions {
let mut is_all_ok = true;
for (ref_tx, tx) in txs.iter().zip(block.transactions.iter()) {
// check signatures
let mut is_ok = test_exp(U256::from(tx.signature().r()) == ref_tx.r.0, "Sig R")
&& test_exp(U256::from(tx.signature().s()) == ref_tx.s.0, "Sig S");
is_ok = is_ok
&& if let Some(chain_id) = ref_tx.chain_id {
test_exp(tx.chain_id() == Some(chain_id.0.as_u64()), "Chain Id")
} else {
true
};
// check type
let ttype = if let Some(ttype) = ref_tx.transaction_type {
let ttype = ttype.0.byte(0);
if let Some(id) = TypedTxId::from_u8_id(ttype) {
id
} else {
println!("Unknown transaction {}", ttype);
continue;
}
} else {
TypedTxId::Legacy
};
is_ok = is_ok
&& test_exp(tx.tx().nonce == ref_tx.nonce.0, "Tx nonce")
&& test_exp(tx.tx().gas_price == ref_tx.gas_price.0, "Tx gas price")
&& test_exp(tx.tx().gas == ref_tx.gas_limit.0, "Tx gas")
&& test_exp(tx.tx().value == ref_tx.value.0, "Tx value")
&& test_exp(tx.tx().data == ref_tx.data.0, "Tx data")
&& test_exp(ref_tx.hash.is_some(), "tx hash is none");
if let Some(hash) = ref_tx.hash {
is_ok = is_ok && test_exp(tx.hash() == hash, "Hash mismatch");
}
// check specific tx data
is_ok = is_ok
&& match ttype {
TypedTxId::Legacy => {
test_exp(tx.legacy_v() == ref_tx.v.0.as_u64(), "Original Sig V")
}
Sunce86/eip 1559 (#393) * eip1559 hard fork activation * eip1559 hard fork activation 2 * added new transaction type for eip1559 * added base fee field to block header * fmt fix * added base fee calculation. added block header validation against base fee * fmt * temporarily added modified transaction pool * tx pool fix of PendingIterator * tx pool fix of UnorderedIterator * tx pool added test for set_scoring * transaction pool changes * added tests for eip1559 transaction and eip1559 receipt * added test for eip1559 transaction execution * block gas limit / block gas target handling * base fee verification moved out of engine * calculate_base_fee moved to EthereumMachine * handling of base_fee_per_gas as part of seal * handling of base_fee_per_gas changed. Different encoding/decoding of block header * eip1559 transaction execution - gas price handling * eip1559 transaction execution - verification, fee burning * effectiveGasPrice removed from the receipt payload (specs) * added support for 1559 txs in tx pool verification * added Aleut test network configuration * effective_tip_scaled replaced by typed_gas_price * eip 3198 - Basefee opcode * rpc - updated structs Block and Header * rpc changes for 1559 * variable renaming according to spec * - typed_gas_price renamed to effective_gas_price - elasticity_multiplier definition moved to update_schedule() * calculate_base_fee simplified * Evm environment context temporary fix for gas limit * fmt fix * fixed fake_sign::sign_call * temporary fix for GASLIMIT opcode to provide gas_target actually * gas_target removed from block header according to spec change: https://github.com/ethereum/EIPs/pull/3566 * tx pool verification fix * env_info base fee changed to Option * fmt fix * pretty format * updated ethereum tests * cache_pending refresh on each update of score * code review fixes * fmt fix * code review fix - changed handling of eip1559_base_fee_max_change_denominator * code review fix - modification.gas_price * Skip gas_limit_bump for Aura * gas_limit calculation changed to target ceil * gas_limit calculation will target ceil on 1559 activation block * transaction verification updated according spec: https://github.com/ethereum/EIPs/pull/3594 * updated json tests * ethereum json tests fix for base_fee
2021-06-04 12:12:24 +02:00
TypedTxId::AccessList | TypedTxId::EIP1559Transaction => {
test_exp(tx.standard_v() as u64 == ref_tx.v.0.as_u64(), "Sig V");
let al = match tx.as_unsigned() {
TypedTransaction::AccessList(tx) => &tx.access_list,
Sunce86/eip 1559 (#393) * eip1559 hard fork activation * eip1559 hard fork activation 2 * added new transaction type for eip1559 * added base fee field to block header * fmt fix * added base fee calculation. added block header validation against base fee * fmt * temporarily added modified transaction pool * tx pool fix of PendingIterator * tx pool fix of UnorderedIterator * tx pool added test for set_scoring * transaction pool changes * added tests for eip1559 transaction and eip1559 receipt * added test for eip1559 transaction execution * block gas limit / block gas target handling * base fee verification moved out of engine * calculate_base_fee moved to EthereumMachine * handling of base_fee_per_gas as part of seal * handling of base_fee_per_gas changed. Different encoding/decoding of block header * eip1559 transaction execution - gas price handling * eip1559 transaction execution - verification, fee burning * effectiveGasPrice removed from the receipt payload (specs) * added support for 1559 txs in tx pool verification * added Aleut test network configuration * effective_tip_scaled replaced by typed_gas_price * eip 3198 - Basefee opcode * rpc - updated structs Block and Header * rpc changes for 1559 * variable renaming according to spec * - typed_gas_price renamed to effective_gas_price - elasticity_multiplier definition moved to update_schedule() * calculate_base_fee simplified * Evm environment context temporary fix for gas limit * fmt fix * fixed fake_sign::sign_call * temporary fix for GASLIMIT opcode to provide gas_target actually * gas_target removed from block header according to spec change: https://github.com/ethereum/EIPs/pull/3566 * tx pool verification fix * env_info base fee changed to Option * fmt fix * pretty format * updated ethereum tests * cache_pending refresh on each update of score * code review fixes * fmt fix * code review fix - changed handling of eip1559_base_fee_max_change_denominator * code review fix - modification.gas_price * Skip gas_limit_bump for Aura * gas_limit calculation changed to target ceil * gas_limit calculation will target ceil on 1559 activation block * transaction verification updated according spec: https://github.com/ethereum/EIPs/pull/3594 * updated json tests * ethereum json tests fix for base_fee
2021-06-04 12:12:24 +02:00
TypedTransaction::EIP1559Transaction(tx) => &tx.transaction.access_list,
_ => {
println!("Wrong data in tx type");
continue;
}
};
if let Some(ref ref_al) = ref_tx.access_list {
if ref_al.len() != al.len() {
println!("Access list mismatch");
continue;
}
let mut is_ok = true;
for (al, ref_al) in al.iter().zip(ref_al.iter()) {
is_ok = is_ok && test_exp(al.0 == ref_al.address, "AL address");
if al.1.len() != ref_al.storage_keys.len() {
println!("Access list mismatch");
continue;
}
for (key, ref_key) in al.1.iter().zip(ref_al.storage_keys.iter()) {
is_ok = is_ok && test_exp(key == ref_key, "Key mismatch");
}
}
is_ok
} else {
false
}
}
};
if !is_ok {
println!(
"Transaction not valid got: {:?} \n expected:{:?}\n",
tx, ref_tx
);
}
is_all_ok = is_ok && is_all_ok;
}
is_all_ok
} else {
true
};
let encript_ok = {
let rlp = rlp_append_block(&block);
rlp == ref_block.rlp()
};
header_ok && transaction_ok && encript_ok
}