diff --git a/tests/core/contracts/test_contract_buildTransaction.py b/tests/core/contracts/test_contract_buildTransaction.py index 85a8ffe324..637c4ddb84 100644 --- a/tests/core/contracts/test_contract_buildTransaction.py +++ b/tests/core/contracts/test_contract_buildTransaction.py @@ -54,8 +54,8 @@ def test_build_transaction_not_paying_to_nonpayable_function( 'to': payable_tester_contract.address, 'data': '0xe4cb8f5c', 'value': 0, - 'maxFeePerGas': 2750000000, - 'maxPriorityFeePerGas': 10 ** 9, + 'maxFeePerGas': 3750000000, + 'maxPriorityFeePerGas': 2 * (10 ** 9), 'chainId': 61, } @@ -76,8 +76,8 @@ def test_build_transaction_with_contract_no_arguments(web3, math_contract, build 'to': math_contract.address, 'data': '0xd09de08a', 'value': 0, - 'maxFeePerGas': 2750000000, - 'maxPriorityFeePerGas': 10 ** 9, + 'maxFeePerGas': 3750000000, + 'maxPriorityFeePerGas': 2 * (10 ** 9), 'chainId': 61, } @@ -88,8 +88,8 @@ def test_build_transaction_with_contract_fallback_function(web3, fallback_functi 'to': fallback_function_contract.address, 'data': '0x', 'value': 0, - 'maxFeePerGas': 2750000000, - 'maxPriorityFeePerGas': 10 ** 9, + 'maxFeePerGas': 3750000000, + 'maxPriorityFeePerGas': 2 * (10 ** 9), 'chainId': 61, } @@ -108,8 +108,8 @@ def test_build_transaction_with_contract_class_method( 'to': math_contract.address, 'data': '0xd09de08a', 'value': 0, - 'maxFeePerGas': 2750000000, - 'maxPriorityFeePerGas': 10 ** 9, + 'maxFeePerGas': 3750000000, + 'maxPriorityFeePerGas': 2 * (10 ** 9), 'chainId': 61, } @@ -123,8 +123,8 @@ def test_build_transaction_with_contract_default_account_is_set( 'to': math_contract.address, 'data': '0xd09de08a', 'value': 0, - 'maxFeePerGas': 2750000000, - 'maxPriorityFeePerGas': 10 ** 9, + 'maxFeePerGas': 3750000000, + 'maxPriorityFeePerGas': 2 * (10 ** 9), 'chainId': 61, } @@ -167,14 +167,14 @@ def test_build_transaction_with_contract_to_address_supplied_errors(web3, ( {}, (5,), {}, { 'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501 - 'value': 0, 'maxFeePerGas': 2750000000, 'maxPriorityFeePerGas': 1000000000, + 'value': 0, 'maxFeePerGas': 3750000000, 'maxPriorityFeePerGas': 2 * (10 ** 9), 'chainId': 61, }, False ), ( {'gas': 800000}, (5,), {}, { 'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501 - 'value': 0, 'maxFeePerGas': 2750000000, 'maxPriorityFeePerGas': 1000000000, + 'value': 0, 'maxFeePerGas': 3750000000, 'maxPriorityFeePerGas': 2 * (10 ** 9), 'chainId': 61, }, False ), @@ -194,14 +194,14 @@ def test_build_transaction_with_contract_to_address_supplied_errors(web3, ( {'nonce': 7}, (5,), {}, { 'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501 - 'value': 0, 'maxFeePerGas': 2750000000, 'maxPriorityFeePerGas': 1000000000, + 'value': 0, 'maxFeePerGas': 3750000000, 'maxPriorityFeePerGas': 2 * (10 ** 9), 'nonce': 7, 'chainId': 61, }, True ), ( {'value': 20000}, (5,), {}, { 'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005', # noqa: E501 - 'value': 20000, 'maxFeePerGas': 2750000000, 'maxPriorityFeePerGas': 1000000000, + 'value': 20000, 'maxFeePerGas': 3750000000, 'maxPriorityFeePerGas': 2 * (10 ** 9), 'chainId': 61, }, False ), diff --git a/web3/eth.py b/web3/eth.py index 2dc05952ad..35c3fe27bf 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -356,7 +356,11 @@ async def hashrate(self) -> int: @property async def max_priority_fee(self) -> Wei: - return await self._max_priority_fee() # type: ignore + fee_history = await self.fee_history(20, 'pending', [float(1)]) + priority_fees_per_gas = fee_history['reward'] + fees_sum = sum([fee[0] for fee in priority_fees_per_gas]) + max_priority_fee_estimate = round(fees_sum/len(priority_fees_per_gas)) + return Wei(max_priority_fee_estimate) @property async def mining(self) -> bool: @@ -604,7 +608,11 @@ def chainId(self) -> int: @property def max_priority_fee(self) -> Wei: - return self._max_priority_fee() + fee_history = self.fee_history(20, 'pending', [float(1)]) + priority_fees_per_gas = fee_history['reward'] + fees_sum = sum([fee[0] for fee in priority_fees_per_gas]) + max_priority_fee_estimate = round(fees_sum/len(priority_fees_per_gas)) + return Wei(max_priority_fee_estimate) def get_storage_at_munger( self, diff --git a/web3/providers/eth_tester/defaults.py b/web3/providers/eth_tester/defaults.py index a33d337ef6..532b03ffae 100644 --- a/web3/providers/eth_tester/defaults.py +++ b/web3/providers/eth_tester/defaults.py @@ -213,7 +213,9 @@ def personal_send_transaction(eth_tester: "EthereumTester", params: Any) -> HexS 'mining': static_return(False), 'hashrate': static_return(0), 'chainId': static_return('0x3d'), - 'feeHistory': not_implemented, + 'feeHistory': static_return( + {'baseFeePerGas': [134919017071, 134775902021, 117928914269], 'gasUsedRatio': [0.4957570088140204, 0.0], + 'oldestBlock': 13865084, 'reward': [[2500000000], [1500000000]]}), 'maxPriorityFeePerGas': static_return(10 ** 9), 'gasPrice': static_return(10 ** 9), # must be >= base fee post-London 'accounts': call_eth_tester('get_accounts'),