Adds eth_maxPriorityFeePerGas implementaiton (#570)
* added eth_maxPriorityFeePerGas rpc call * cargo fmt * moved block_base_fee implementation into the trait * added basic test for eth_maxPriorityFeePerGas * added test for eth_maxPriorityFeePerGas calculation * Added support for zero-cost transactions * Added 'eip1559_not_activated' error * Fixes 'chain::supplier::test::return_nodes' test * cargo fmt * cargo fmt * made calculation of fallback priority fee to ignore zero-cost transactions * cargo fmt * made use of 'saturating_sub' instead of minus
This commit is contained in:
@@ -23,7 +23,7 @@ use std::{
|
||||
|
||||
use accounts::AccountProvider;
|
||||
use ethcore::{
|
||||
client::{BlockChainClient, EachBlockWith, Executed, TestBlockChainClient},
|
||||
client::{BlockChainClient, EachBlockWith, EvmTestClient, Executed, TestBlockChainClient},
|
||||
miner::{self, MinerService},
|
||||
};
|
||||
use ethereum_types::{Address, Bloom, H160, H256, U256};
|
||||
@@ -51,6 +51,12 @@ fn blockchain_client() -> Arc<TestBlockChainClient> {
|
||||
Arc::new(client)
|
||||
}
|
||||
|
||||
fn eip1559_blockchain_client() -> Arc<TestBlockChainClient> {
|
||||
let spec = EvmTestClient::spec_from_json(ðjson::spec::ForkSpec::London).unwrap();
|
||||
let client = TestBlockChainClient::new_with_spec(spec);
|
||||
Arc::new(client)
|
||||
}
|
||||
|
||||
fn accounts_provider() -> Arc<AccountProvider> {
|
||||
Arc::new(AccountProvider::transient_provider())
|
||||
}
|
||||
@@ -89,8 +95,25 @@ impl Default for EthTester {
|
||||
|
||||
impl EthTester {
|
||||
pub fn new_with_options(options: EthClientOptions) -> Self {
|
||||
let runtime = Runtime::with_thread_count(1);
|
||||
let client = blockchain_client();
|
||||
EthTester::new_with_client_and_options(client, options)
|
||||
}
|
||||
|
||||
fn new_eip1559_with_options(options: EthClientOptions) -> Self {
|
||||
let client = eip1559_blockchain_client();
|
||||
EthTester::new_with_client_and_options(client, options)
|
||||
}
|
||||
|
||||
pub fn add_blocks(&self, count: usize, with: EachBlockWith) {
|
||||
self.client.add_blocks(count, with);
|
||||
self.sync.increase_imported_block_number(count as u64);
|
||||
}
|
||||
|
||||
fn new_with_client_and_options(
|
||||
client: Arc<TestBlockChainClient>,
|
||||
options: EthClientOptions,
|
||||
) -> Self {
|
||||
let runtime = Runtime::with_thread_count(1);
|
||||
let sync = sync_provider();
|
||||
let ap = accounts_provider();
|
||||
let ap2 = ap.clone();
|
||||
@@ -126,11 +149,6 @@ impl EthTester {
|
||||
hashrates,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_blocks(&self, count: usize, with: EachBlockWith) {
|
||||
self.client.add_blocks(count, with);
|
||||
self.sync.increase_imported_block_number(count as u64);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -537,6 +555,33 @@ fn rpc_eth_gas_price() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_eth_get_max_priority_fee_per_gas() {
|
||||
let tester = EthTester::new_eip1559_with_options(Default::default());
|
||||
|
||||
let request = r#"{"method":"eth_maxPriorityFeePerGas","params":[],"id":1,"jsonrpc":"2.0"}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x77359400","id":1}"#; // 2 GWei
|
||||
|
||||
assert_eq!(
|
||||
tester.io.handle_request_sync(request),
|
||||
Some(response.to_owned())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_eth_get_max_priority_fee_per_gas_error() {
|
||||
let tester = EthTester::default();
|
||||
|
||||
let request = r#"{"method":"eth_maxPriorityFeePerGas","params":[],"id":1,"jsonrpc":"2.0"}"#;
|
||||
let response =
|
||||
r#"{"jsonrpc":"2.0","error":{"code":-32000,"message":"EIP-1559 is not activated"},"id":1}"#;
|
||||
|
||||
assert_eq!(
|
||||
tester.io.handle_request_sync(request),
|
||||
Some(response.to_owned())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_eth_accounts() {
|
||||
let tester = EthTester::default();
|
||||
|
||||
Reference in New Issue
Block a user