Skip to content

Commit

Permalink
tests: update for bug in EELS.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-tb committed Dec 5, 2024
1 parent c8bec3e commit 77552cc
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 153 deletions.

This file was deleted.

79 changes: 59 additions & 20 deletions tests/prague/eip7742_uncouple_blob_count/test_uncoupled_blob_txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@
Tests uncoupled blob txs for [EIP-7742: Uncouple blob count between CL and EL](https://eips.ethereum.org/EIPS/eip-7742)
""" # noqa: E501

import itertools
from typing import List, Tuple

import pytest

from ethereum_test_tools import Alloc, Environment, StateTestFiller, Transaction
from ethereum_test_tools import (
Alloc,
Block,
BlockchainTestFiller,
Environment,
StateTestFiller,
Transaction,
)

from .spec import Spec, ref_spec_7742

Expand All @@ -15,17 +25,21 @@

@pytest.mark.parametrize(
"blobs_per_tx",
[(0,)],
[
(Spec.CANCUN_MAX_BLOBS_PER_BLOCK + 1,),
(Spec.CANCUN_MAX_BLOBS_PER_BLOCK + 2,),
(Spec.CANCUN_MAX_BLOBS_PER_BLOCK + 3,),
],
)
@pytest.mark.valid_from("Prague")
def test_zero_blobs_in_blob_tx(
def test_blobs_above_cancun_max(
state_test: StateTestFiller,
pre: Alloc,
state_env: Environment,
txs: list[Transaction],
):
"""
Test that a blob transaction with zero blobs is accepted in Prague (EIP-7742).
Test that transactions with blob counts above the Cancun maximum are accepted in Prague.
"""
state_test(
pre=pre,
Expand All @@ -37,21 +51,17 @@ def test_zero_blobs_in_blob_tx(

@pytest.mark.parametrize(
"blobs_per_tx",
[
(Spec.CANCUN_MAX_BLOBS_PER_BLOCK + 1,),
(Spec.CANCUN_MAX_BLOBS_PER_BLOCK + 2,),
(Spec.CANCUN_MAX_BLOBS_PER_BLOCK + 3,),
],
[(i,) for i in range(64, 1024, 64)],
)
@pytest.mark.valid_from("Prague")
def test_blobs_above_cancun_max(
def test_large_number_of_blobs_in_tx(
state_test: StateTestFiller,
pre: Alloc,
state_env: Environment,
txs: list[Transaction],
):
"""
Test that transactions with blob counts above the Cancun maximum are accepted in Prague.
Test transactions with a large number of blobs (64 to 1024 blobs).
"""
state_test(
pre=pre,
Expand All @@ -61,23 +71,52 @@ def test_blobs_above_cancun_max(
)


def invalid_cancun_blob_combinations() -> List[Tuple[int, ...]]:
"""
Returns all possible invalid Cancun blob tx combinations for a given block that use up to
`CANCUN_MAX_BLOBS_PER_BLOCK+1` blobs. These combinations are valid from Prague.
"""
all = [
seq
for i in range(
Spec.CANCUN_MAX_BLOBS_PER_BLOCK + 1, 0, -1
) # We can have from 1 to at most MAX_BLOBS_PER_BLOCK blobs per block
for seq in itertools.combinations_with_replacement(
range(1, Spec.CANCUN_MAX_BLOBS_PER_BLOCK + 2), i
) # We iterate through all possible combinations
if sum(seq) == Spec.CANCUN_MAX_BLOBS_PER_BLOCK + 1
]
# We also add the reversed version of each combination, only if it's not
# already in the list. E.g. (4, 1) is added from (1, 4) but not
# (1, 1, 1, 1, 1) because its reversed version is identical.
all += [tuple(reversed(x)) for x in all if tuple(reversed(x)) not in all]
return all


@pytest.mark.parametrize(
"blobs_per_tx",
[(i,) for i in range(64, 1024, 64)],
invalid_cancun_blob_combinations(),
)
@pytest.mark.valid_from("Prague")
def test_large_number_of_blobs_in_tx(
state_test: StateTestFiller,
def test_invalid_cancun_block_blob_count(
blockchain_test: BlockchainTestFiller,
pre: Alloc,
state_env: Environment,
txs: list[Transaction],
env: Environment,
block: Block,
):
"""
Test transactions with a large number of blobs (64 to 1024 blobs).
Tests all invalid blob combinations for the Cancun fork in a single block,
where the sum of all blobs in a block is `CANCUN_MAX_BLOBS_PER_BLOCK + 1`.
This is a copy of the invalid test from:
`tests/cancun/eip4844_blobs/test_blob_txs.py:test_invalid_block_blob_count`.
In Cancun, these blocks are invalid but in Prague they are valid.
"""
state_test(
blockchain_test(
pre=pre,
post={},
tx=txs[0],
env=state_env,
blocks=[block],
genesis_environment=env,
header_verify=block.header_verify,
)
Original file line number Diff line number Diff line change
Expand Up @@ -136,42 +136,30 @@ def test_multiple_blocks_varied_blobs(
@pytest.mark.parametrize(
"blob_counts_per_block, tx_counts_per_block",
[
# Incremental 1: 0 to 64 blobs, 1 tx per block, 65 blocks
# Incremental: 1 to 64 blobs, 1 tx per block, 64 blocks
(
[i for i in range(65)],
[1] * 65,
[max(1, i) for i in range(64)],
[1] * 64,
),
# Incremental 2: 0 to 256 blobs, 10 txs per block, 26 blocks
# Decremental: 64 to 1 blobs, 1 tx per block, 65 blocks
(
[i * 10 for i in range(26)],
[10] * 26,
[max(1, i) for i in reversed(range(64))],
[1] * 64,
),
# Decremental 1: 64 to 0 blobs, 1 tx per block, 65 blocks
# Incremental then decremental: 1 to 32 to 1 blobs, 1 tx per block, 66 blocks
(
[i for i in reversed(range(65))],
[1] * 65,
),
# Decremental 2: 256 to 0 blobs, 10 txs per block, 26 blocks
(
[i * 10 for i in reversed(range(26))],
[10] * 26,
),
# Incremental then decremental 1: 0 to 32 to 0 blobs, 1 tx per block, 66 blocks
(
[i for i in range(33)] + [i for i in reversed(range(33))],
[max(1, i) for i in range(33)] + [max(1, i) for i in reversed(range(33))],
[1] * 66,
),
# Decremental then incremental 1: 32 to 0 to 32 blobs, 1 tx per block, 66 blocks
# Decremental then incremental: 32 to 1 to 32 blobs, 1 tx per block, 66 blocks
(
[i for i in reversed(range(33))] + [i for i in range(33)],
[max(1, i) for i in reversed(range(33))] + [max(1, i) for i in range(33)],
[1] * 66,
),
],
ids=[
"incremental_1_tx",
"incremental_10_txs",
"decremental_1_tx",
"decremental_10_txs",
"incremental_then_decremental",
"decremental_then_incremental",
],
Expand Down

0 comments on commit 77552cc

Please sign in to comment.