Skip to content

Commit

Permalink
Fixes ethereum#2259, remove dependency on eth_maxPriorityFeePerGas
Browse files Browse the repository at this point in the history
  • Loading branch information
broper2 authored and fselmo committed Feb 1, 2022
1 parent 2f2ca36 commit cf47f0c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
28 changes: 14 additions & 14 deletions tests/core/contracts/test_contract_buildTransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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,
}

Expand All @@ -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,
}

Expand All @@ -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,
}

Expand All @@ -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,
}

Expand Down Expand Up @@ -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
),
Expand All @@ -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
),
Expand Down
12 changes: 10 additions & 2 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion web3/providers/eth_tester/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit cf47f0c

Please sign in to comment.