Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,14 @@ def fn(
)
// parent_base_fee_per_gas
) + parent_gas_target
# When the proportional increase rounds down to zero, the
# base fee still rises by one, and the estimate above can
# exceed the gas limit. A full block reaches that increase.
parent_gas_used = min(parent_gas_used, parent_gas_limit)
# Flooring the estimate can leave it a little short.
while (
base_fee_per_gas_calculator(
parent_gas_used < parent_gas_limit
and base_fee_per_gas_calculator(
parent_base_fee_per_gas=parent_base_fee_per_gas,
parent_gas_used=parent_gas_used,
parent_gas_limit=parent_gas_limit,
Expand All @@ -164,6 +169,9 @@ def fn(
parent_base_fee_per_gas,
)

assert 0 <= parent_gas_used <= parent_gas_limit, (
"required base fee is not reachable in one block"
)
assert (
base_fee_per_gas_calculator(
parent_base_fee_per_gas=parent_base_fee_per_gas,
Expand Down
60 changes: 60 additions & 0 deletions packages/testing/src/execution_testing/forks/tests/test_forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,66 @@ def test_base_fee_change_calculator_round_trip(
)


@pytest.mark.parametrize("fork", [London, Amsterdam])
@pytest.mark.parametrize("parent_base_fee_per_gas", [1, 7, 8])
def test_base_fee_change_calculator_minimum_increase(
fork: Fork, parent_base_fee_per_gas: int
) -> None:
"""
Test that the gas returned for the minimum base fee increase fits in
the parent gas limit, including base fees too small for the regular
increase to reach one wei.
"""
gas_limit = 30_000_000
base_fee_per_gas = fork.base_fee_per_gas_calculator()
gas_for_base_fee = fork.base_fee_change_calculator()
required = parent_base_fee_per_gas + 1
gas_used = gas_for_base_fee(
parent_base_fee_per_gas=parent_base_fee_per_gas,
parent_gas_limit=gas_limit,
required_base_fee_per_gas=required,
)
assert gas_used <= gas_limit
assert (
base_fee_per_gas(
parent_base_fee_per_gas=parent_base_fee_per_gas,
parent_gas_used=gas_used,
parent_gas_limit=gas_limit,
)
== required
)


@pytest.mark.parametrize("fork", [London, Amsterdam])
@pytest.mark.parametrize("parent_base_fee_per_gas", [7, 100])
@pytest.mark.parametrize(
"full_block", [False, True], ids=["decrease", "increase"]
)
def test_base_fee_change_calculator_unreachable(
fork: Fork, parent_base_fee_per_gas: int, full_block: bool
) -> None:
"""
Test that a base fee one step past what an empty or full block reaches
raises instead of returning gas outside the block.
"""
gas_limit = 30_000_000
base_fee_per_gas = fork.base_fee_per_gas_calculator()
gas_for_base_fee = fork.base_fee_change_calculator()
reachable = base_fee_per_gas(
parent_base_fee_per_gas=parent_base_fee_per_gas,
parent_gas_used=gas_limit if full_block else 0,
parent_gas_limit=gas_limit,
)
with pytest.raises(AssertionError):
gas_for_base_fee(
parent_base_fee_per_gas=parent_base_fee_per_gas,
parent_gas_limit=gas_limit,
required_base_fee_per_gas=(
reachable + 1 if full_block else reachable - 1
),
)


def test_bpo_fork() -> None: # noqa: D103
assert Osaka.bpo_fork() is False
assert BPO1.bpo_fork() is True
Expand Down
Loading