Skip to content

Commit 14b1585

Browse files
committed
feat(tests): Additional cases for BLOCKCHASH
1 parent fec8cab commit 14b1585

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Test fixtures for use by clients are available for each release on the [Github r
2929
- ✨ Expand cases to test *CALL opcodes causing OOG ([#1703](https://github.com/ethereum/execution-specs/pull/1703)).
3030
- ✨ Add tests for `modexp` and `ripemd` precompiled contracts ([#1691](https://github.com/ethereum/execution-specs/pull/1691)).
3131
- ✨ Add `ecrecover` precompile tests originating form `evmone` unittests ([#1685](https://github.com/ethereum/execution-specs/pull/1685)).
32+
- ✨ Add stack overflow tests and expand `BLOCKHASH` tests ([#1728](https://github.com/ethereum/execution-specs/pull/1728)).
3233

3334
## [v5.3.0](https://github.com/ethereum/execution-spec-tests/releases/tag/v5.3.0) - 2025-10-09
3435

tests/frontier/opcodes/test_blockhash.py

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@
1313

1414

1515
@pytest.mark.valid_from("Frontier")
16+
@pytest.mark.parametrize(
17+
"first_block", ["none", "empty", "with_tx", "over_256"]
18+
)
1619
def test_genesis_hash_available(
17-
blockchain_test: BlockchainTestFiller, pre: Alloc
20+
blockchain_test: BlockchainTestFiller,
21+
pre: Alloc,
22+
first_block: str,
1823
) -> None:
1924
"""
2025
Verify BLOCKHASH returns genesis and block 1 hashes.
@@ -29,45 +34,58 @@ def test_genesis_hash_available(
2934
Bug context: revm blockchaintest runner wasn't inserting block_hashes,
3035
causing failures in tests with BLOCKHASH-derived addresses.
3136
"""
32-
storage = Storage()
37+
Storage()
3338

3439
# Store ISZERO(BLOCKHASH(0)) and ISZERO(BLOCKHASH(1))
3540
# Both should be 0 (false) if hashes exist
36-
code = Op.SSTORE(
37-
storage.store_next(0), Op.ISZERO(Op.BLOCKHASH(0))
38-
) + Op.SSTORE(storage.store_next(0), Op.ISZERO(Op.BLOCKHASH(1)))
41+
code = Op.SSTORE(0, Op.ISZERO(Op.BLOCKHASH(0))) + Op.SSTORE(
42+
1, Op.ISZERO(Op.BLOCKHASH(1))
43+
)
3944

4045
contract = pre.deploy_contract(code=code)
4146
sender = pre.fund_eoa()
4247

43-
blocks = [
44-
Block(
45-
txs=[
46-
Transaction(
47-
sender=sender,
48-
to=contract,
49-
gas_limit=100_000,
50-
protected=False,
51-
)
52-
]
53-
),
54-
Block(
55-
txs=[
56-
Transaction(
57-
sender=sender,
58-
to=contract,
59-
gas_limit=100_000,
60-
protected=False,
61-
)
62-
]
63-
),
64-
]
48+
blocks = (
49+
[
50+
Block(
51+
txs=[
52+
Transaction(
53+
sender=sender,
54+
to=contract,
55+
gas_limit=100_000,
56+
protected=False,
57+
)
58+
]
59+
)
60+
]
61+
if first_block == "with_tx"
62+
else [Block()]
63+
if first_block == "empty"
64+
else [Block()] * 256
65+
if first_block == "over_256"
66+
else []
67+
) + (
68+
[
69+
Block(
70+
txs=[
71+
Transaction(
72+
sender=sender,
73+
to=contract,
74+
gas_limit=100_000,
75+
protected=False,
76+
)
77+
]
78+
)
79+
]
80+
)
6581

6682
post = {
6783
contract: Account(
6884
storage={
69-
0: 0, # ISZERO(BLOCKHASH(0)) = 0 (genesis hash exists)
70-
1: 0, # ISZERO(BLOCKHASH(1)) = 0 (block 1 hash exists)
85+
# ISZERO(BLOCKHASH(0)) = 0 (genesis hash exists)
86+
0: 1 if first_block == "over_256" else 0,
87+
# ISZERO(BLOCKHASH(1)) = 0 (if block 1 hash exists)
88+
1: 1 if first_block == "none" else 0,
7189
}
7290
)
7391
}

0 commit comments

Comments
 (0)