Skip to content

Commit a7544eb

Browse files
authored
feat(consume): Clarify mismatched fields on blockhash mismatch (#2126)
* feat(consume): Clarify mismatched fields on blockhash mismatch * chore: slight tweak to previous commit
1 parent 2127283 commit a7544eb

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/pytest_plugins/consume/simulators/simulator_logic/test_via_rlp.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99

1010
from ethereum_test_fixtures import BlockchainFixture
11+
from ethereum_test_fixtures.blockchain import FixtureBlock, FixtureHeader
1112
from ethereum_test_rpc import EthRPC
1213

1314
from ..helpers.exceptions import GenesisBlockMismatchExceptionError
@@ -38,4 +39,34 @@ def test_via_rlp(
3839
logger.info("Calling getBlockByNumber to get latest block...")
3940
block = eth_rpc.get_block_by_number("latest")
4041
assert block, "`getBlockByNumber` didn't return a block."
41-
assert block["hash"] == str(fixture.last_block_hash), "hash mismatch in last block"
42+
if block["hash"] != str(fixture.last_block_hash):
43+
try:
44+
block_header = FixtureHeader.model_validate(block).model_dump()
45+
last_block = FixtureBlock.model_validate(fixture.blocks[-1])
46+
last_block_header = last_block.header.model_dump()
47+
48+
if block_header["number"] != last_block_header["number"]:
49+
# raise with clearer message if block number mismatches
50+
raise AssertionError(
51+
f"block number mismatch in last block: got "
52+
f"`{block_header['number']}`, "
53+
f"expected `{last_block_header['number']}``"
54+
)
55+
56+
# find all mismatched fields
57+
mismatches = []
58+
for block_field, block_value in block_header.items():
59+
fixture_value = last_block_header[block_field]
60+
if str(block_value) != str(fixture_value):
61+
mismatches.append(
62+
f" {block_field}: got `{block_value}`, expected `{fixture_value}`"
63+
)
64+
raise AssertionError(
65+
"blockHash mismatch in last block - field mismatches:"
66+
f"\n{'\n'.join(mismatches)}"
67+
)
68+
except Exception as e:
69+
raise AssertionError(
70+
f"blockHash mismatch in last block: got `{block['hash']}`, "
71+
f"expected `{fixture.last_block_hash}`"
72+
) from e

0 commit comments

Comments
 (0)