From b928380b64e4f9a7d7da45a51266330053e9a688 Mon Sep 17 00:00:00 2001 From: Dusan Stanivukovic Date: Thu, 10 Jun 2021 15:01:48 +0200 Subject: [PATCH] test update (#429) support for 9.0.1 ethereum tests --- .../test/berlin_to_londonat5_test.json | 212 ++++++++++++++++++ crates/ethcore/res/json_tests | 2 +- crates/ethcore/src/client/evm_test_client.rs | 1 + crates/ethcore/src/ethereum/mod.rs | 8 + crates/ethcore/src/json_tests/local.rs | 18 +- crates/ethcore/src/json_tests/state.rs | 12 +- crates/ethjson/src/blockchain/transaction.rs | 4 +- crates/ethjson/src/spec/spec.rs | 1 + crates/ethjson/src/state/test.rs | 58 ++++- crates/ethjson/src/state/transaction.rs | 6 +- crates/ethjson/src/vm/env.rs | 2 +- 11 files changed, 307 insertions(+), 17 deletions(-) create mode 100644 crates/ethcore/res/chainspec/test/berlin_to_londonat5_test.json diff --git a/crates/ethcore/res/chainspec/test/berlin_to_londonat5_test.json b/crates/ethcore/res/chainspec/test/berlin_to_londonat5_test.json new file mode 100644 index 000000000..acaa9187d --- /dev/null +++ b/crates/ethcore/res/chainspec/test/berlin_to_londonat5_test.json @@ -0,0 +1,212 @@ +{ + "name": "BerlinToLondonAt5 (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", + "eip2929Transition": "0x0", + "eip2930Transition": "0x0", + "eip1559Transition": "0x5", + "eip3198Transition": "0x5", + "eip3541Transition": "0x5", + "eip3529Transition": "0x5", + "eip1559BaseFeeMaxChangeDenominator": "0x8", + "eip1559ElasticityMultiplier": "0x2", + "eip1559BaseFeeInitialValue": "0x3B9ACA00" + }, + "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": { + "0": { + "price": { + "modexp2565": {} + } + } + } + } + }, + "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 + } + } + } + } + } +} \ No newline at end of file diff --git a/crates/ethcore/res/json_tests b/crates/ethcore/res/json_tests index 8a81997b2..fa0ab110f 160000 --- a/crates/ethcore/res/json_tests +++ b/crates/ethcore/res/json_tests @@ -1 +1 @@ -Subproject commit 8a81997b22475f1dd90f0d01128c43b18f8877b2 +Subproject commit fa0ab110f3f45d1f6786f978ea596a18ecbe8275 diff --git a/crates/ethcore/src/client/evm_test_client.rs b/crates/ethcore/src/client/evm_test_client.rs index 5ccb7b14d..97c8d01b3 100644 --- a/crates/ethcore/src/client/evm_test_client.rs +++ b/crates/ethcore/src/client/evm_test_client.rs @@ -108,6 +108,7 @@ impl<'a> EvmTestClient<'a> { } ForkSpec::Berlin => Some(ethereum::new_berlin_test()), ForkSpec::London => Some(ethereum::new_london_test()), + ForkSpec::BerlinToLondonAt5 => Some(ethereum::new_berlin_to_london_test()), ForkSpec::FrontierToHomesteadAt5 | ForkSpec::HomesteadToDaoAt5 | ForkSpec::HomesteadToEIP150At5 diff --git a/crates/ethcore/src/ethereum/mod.rs b/crates/ethcore/src/ethereum/mod.rs index 15b6fe903..5b46036ba 100644 --- a/crates/ethcore/src/ethereum/mod.rs +++ b/crates/ethcore/src/ethereum/mod.rs @@ -282,6 +282,14 @@ pub fn new_london_test() -> Spec { ) } +/// Create a new BerlinToLondonAt5 era spec. +pub fn new_berlin_to_london_test() -> Spec { + load( + None, + include_bytes!("../../res/chainspec/test/berlin_to_londonat5_test.json"), + ) +} + /// Create a new Musicoin-MCIP3-era spec. pub fn new_mcip3_test() -> Spec { load( diff --git a/crates/ethcore/src/json_tests/local.rs b/crates/ethcore/src/json_tests/local.rs index dbb5e240c..bc20d32ae 100644 --- a/crates/ethcore/src/json_tests/local.rs +++ b/crates/ethcore/src/json_tests/local.rs @@ -134,8 +134,24 @@ pub fn is_same_block(ref_block: &Block, block: &Unverified) -> bool { TypedTxId::Legacy }; is_ok = is_ok + && { + match ref_tx.gas_price { + Some(gas_price) => { + test_exp(tx.tx().gas_price == gas_price.0, "Tx gas price") + } + None => { + test_exp( + tx.tx().gas_price == ref_tx.max_fee_per_gas.unwrap_or_default().0, + "Tx max fee per gas", + ) && test_exp( + tx.max_priority_fee_per_gas() + == ref_tx.max_priority_fee_per_gas.unwrap_or_default().0, + "Tx max priority fee per gas", + ) + } + } + } && 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") diff --git a/crates/ethcore/src/json_tests/state.rs b/crates/ethcore/src/json_tests/state.rs index 0070b8710..445c60a0b 100644 --- a/crates/ethcore/src/json_tests/state.rs +++ b/crates/ethcore/src/json_tests/state.rs @@ -16,7 +16,7 @@ use super::{test_common::*, HookType}; use client::{EvmTestClient, EvmTestError, TransactErr, TransactSuccess}; -use ethjson; +use ethjson::{self, spec::ForkSpec}; use pod_state::PodState; use std::path::Path; use trace; @@ -77,6 +77,14 @@ pub fn json_state_test( } }; + //hardcode base fee for part of the london tests, that miss base fee field in env + let mut test_env = env.clone(); + if spec_name >= ForkSpec::London { + if test_env.base_fee.is_none() { + test_env.base_fee = Some(0x0a.into()); + } + } + for (i, state) in states.into_iter().enumerate() { let info = format!( "TestState/{}/{:?}/{}/trie", @@ -94,7 +102,7 @@ pub fn json_state_test( let result = || -> Result<_, EvmTestError> { Ok(EvmTestClient::from_pod_state(&spec, pre.clone())?.transact( - &env, + &test_env, transaction, trace::NoopTracer, trace::NoopVMTracer, diff --git a/crates/ethjson/src/blockchain/transaction.rs b/crates/ethjson/src/blockchain/transaction.rs index dc470a29d..b251fa4c0 100644 --- a/crates/ethjson/src/blockchain/transaction.rs +++ b/crates/ethjson/src/blockchain/transaction.rs @@ -27,7 +27,7 @@ pub struct Transaction { pub transaction_type: Option, pub data: Bytes, pub gas_limit: Uint, - pub gas_price: Uint, + pub gas_price: Option, pub nonce: Uint, pub r: Uint, pub s: Uint, @@ -35,6 +35,8 @@ pub struct Transaction { pub value: Uint, pub chain_id: Option, pub access_list: Option, + pub max_fee_per_gas: Option, + pub max_priority_fee_per_gas: Option, pub hash: Option, } diff --git a/crates/ethjson/src/spec/spec.rs b/crates/ethjson/src/spec/spec.rs index 0d45d63ff..69a86c418 100644 --- a/crates/ethjson/src/spec/spec.rs +++ b/crates/ethjson/src/spec/spec.rs @@ -39,6 +39,7 @@ pub enum ForkSpec { ByzantiumToConstantinopleFixAt5, Berlin, London, + BerlinToLondonAt5, } /// Spec deserialization. diff --git a/crates/ethjson/src/state/test.rs b/crates/ethjson/src/state/test.rs index 5ee43e40b..a1a4323bd 100644 --- a/crates/ethjson/src/state/test.rs +++ b/crates/ethjson/src/state/test.rs @@ -27,7 +27,7 @@ use crate::{ }; use common_types::transaction::{ - AccessListTx, Action, SignedTransaction, Transaction, TypedTransaction, + AccessListTx, Action, EIP1559TransactionTx, SignedTransaction, Transaction, TypedTransaction, }; use serde_json::{self, Error}; @@ -84,7 +84,7 @@ pub struct MultiTransaction { /// Gas limit set. pub gas_limit: Vec, /// Gas price. - pub gas_price: Uint, + pub gas_price: Option, /// Nonce. pub nonce: Uint, /// Secret key. @@ -94,6 +94,10 @@ pub struct MultiTransaction { pub to: MaybeEmpty
, /// Value set. pub value: Vec, + /// Max fee per gas. + pub max_fee_per_gas: Option, + /// Max priority fee per gas. + pub max_priority_fee_per_gas: Option, } fn sign_with_secret(tx: TypedTransaction, secret: Option) -> SignedTransaction { @@ -113,7 +117,10 @@ impl MultiTransaction { let to: Option
= self.to.clone().into(); let transaction = Transaction { nonce: self.nonce.clone().into(), - gas_price: self.gas_price.clone().into(), + gas_price: match self.gas_price { + Some(x) => x.into(), + None => self.max_fee_per_gas.unwrap().into(), + }, gas: self.gas_limit[indexes.gas as usize].clone().into(), action: match to { Some(to) => Action::Call(to.into()), @@ -126,7 +133,7 @@ impl MultiTransaction { if let Some(access_lists) = self.access_lists.as_ref() { if access_lists.len() > indexes.data as usize { if let Some(access_list) = access_lists[indexes.data as usize].clone() { - //access list type of transaction + //access list exist let access_list = access_list .into_iter() @@ -138,18 +145,49 @@ impl MultiTransaction { }) .collect(); - let tx = TypedTransaction::AccessList(AccessListTx { + let al_tx = AccessListTx { transaction, access_list, - }); + }; - return sign_with_secret(tx, secret); + match self.gas_price { + Some(_) => { + let tx = TypedTransaction::AccessList(al_tx); + return sign_with_secret(tx, secret); + } + None => { + let tx = TypedTransaction::EIP1559Transaction(EIP1559TransactionTx { + transaction: al_tx, + max_priority_fee_per_gas: self + .max_priority_fee_per_gas + .unwrap() + .into(), + }); + return sign_with_secret(tx, secret); + } + } } } - } + }; - let tx = TypedTransaction::Legacy(transaction); - sign_with_secret(tx, secret) + match self.gas_price { + Some(_) => { + let tx = TypedTransaction::Legacy(transaction); + sign_with_secret(tx, secret) + } + None => { + let al_tx = AccessListTx { + transaction, + access_list: common_types::transaction::AccessList::default(), + }; + + let tx = TypedTransaction::EIP1559Transaction(EIP1559TransactionTx { + transaction: al_tx, + max_priority_fee_per_gas: self.max_priority_fee_per_gas.unwrap().into(), + }); + sign_with_secret(tx, secret) + } + } } } diff --git a/crates/ethjson/src/state/transaction.rs b/crates/ethjson/src/state/transaction.rs index ffb291471..693967326 100644 --- a/crates/ethjson/src/state/transaction.rs +++ b/crates/ethjson/src/state/transaction.rs @@ -32,7 +32,7 @@ pub struct Transaction { /// Gas limit. pub gas_limit: Uint, /// Gas price. - pub gas_price: Uint, + pub gas_price: Option, /// Nonce. pub nonce: Uint, /// Secret key. @@ -42,6 +42,10 @@ pub struct Transaction { pub to: MaybeEmpty
, /// Value. pub value: Uint, + /// Max fee per gas. + pub max_fee_per_gas: Option, + /// Max priority fee per gas. + pub max_priority_fee_per_gas: Option, } #[cfg(test)] diff --git a/crates/ethjson/src/vm/env.rs b/crates/ethjson/src/vm/env.rs index 932f86a62..249456d29 100644 --- a/crates/ethjson/src/vm/env.rs +++ b/crates/ethjson/src/vm/env.rs @@ -36,7 +36,7 @@ pub struct Env { #[serde(rename = "currentTimestamp")] pub timestamp: Uint, /// Block base fee. - #[serde(rename = "currentBlockBaseFee")] + #[serde(rename = "currentBaseFee")] pub base_fee: Option, }