Skip to content

Commit

Permalink
fix: some providers are importing base fees as hex int (ApeWorX#2218)
Browse files Browse the repository at this point in the history
Co-authored-by: slush <[email protected]>
  • Loading branch information
bitwise-constructs and bitwise-constructs authored Aug 13, 2024
1 parent dec6b28 commit 6a1cf26
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def base_fee(self) -> int:
# Non-EIP-1559 chains or we time-travelled pre-London fork.
return self._get_last_base_fee()

return pending_base_fee
return to_int(pending_base_fee)

@property
def call_trace_approach(self) -> Optional[TraceApproach]:
Expand All @@ -284,7 +284,7 @@ def _get_fee_history(self, block_number: int) -> FeeHistory:
def _get_last_base_fee(self) -> int:
base_fee = self._get_latest_block_rpc().get("baseFeePerGas", None)
if base_fee is not None:
return base_fee
return to_int(base_fee)

raise APINotImplementedError("No base fee found in block.")

Expand Down
16 changes: 16 additions & 0 deletions tests/functional/geth/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,22 @@ def test_base_fee_no_history(geth_provider, mocker, ret):
assert actual == expected


@geth_process_test
def test_base_fee_hex_decode(geth_provider, mocker):
orig = geth_provider._web3.eth.fee_history
mock_fee_history = mocker.MagicMock()
mock_fee_history.return_value = {"baseFeePerGas": ["0x6", "0x7"]}
expected = 7
geth_provider._web3.eth.fee_history = mock_fee_history

try:
actual = geth_provider.base_fee
finally:
geth_provider._web3.eth.fee_history = orig

assert actual == expected


@geth_process_test
def test_estimate_gas_cost(geth_contract, geth_provider, geth_account):
txn = geth_contract.setNumber.as_transaction(900, sender=geth_account)
Expand Down

0 comments on commit 6a1cf26

Please sign in to comment.