|
8 | 8 | import logging |
9 | 9 |
|
10 | 10 | from ethereum_test_fixtures import BlockchainFixture |
| 11 | +from ethereum_test_fixtures.blockchain import FixtureBlock, FixtureHeader |
11 | 12 | from ethereum_test_rpc import EthRPC |
12 | 13 |
|
13 | 14 | from ..helpers.exceptions import GenesisBlockMismatchExceptionError |
@@ -38,4 +39,34 @@ def test_via_rlp( |
38 | 39 | logger.info("Calling getBlockByNumber to get latest block...") |
39 | 40 | block = eth_rpc.get_block_by_number("latest") |
40 | 41 | 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