testing.fork_blocks

Documentation for eth_defi.testing.fork_blocks Python module.

Canonical per-chain fork blocks for shared-fork characterisation tests.

For the full rationale and how-to of the shared Anvil fork + fixed fork-block + warm RPC-cache test pattern these constants exist to serve, see the canonical module docstring of eth_defi.testing.anvil_fork_pool. This module only holds the block constants.

Tests that only read (characterise) a vault historically pin a fixed fork_block_number for reproducibility. Historically each test picked its own arbitrary block, so tests on the same chain could not share one Anvil fork. To let many tests share a single fork (via eth_defi.testing.anvil_fork_pool.AnvilForkPool), we normalise them onto one canonical block per chain.

These blocks are not special. 2026-07-24 00:00:00 UTC was picked arbitrarily — it was simply “the most recent midnight” at the time this test suite was optimised. There is nothing significant about this date, block height or the choice of midnight specifically; any recent, settled, fixed block per chain would do equally well. A midnight timestamp was used only because it is easy to compute reproducibly (binary-search the archive for the last block at or before 00:00 UTC). Feel free to bump these to a newer date whenever convenient (then re-run the affected tests to refresh block-dependent asserts).

The canonical block is the last block at or immediately before midnight UTC on that arbitrarily chosen recent date. What actually matters about it is:

  • recent, so vaults integrated and live today generally have state at this block — but this is not a guarantee for a specific vault; validate per vault (read the values) before normalising a test onto it;

  • fixed and reproducible (unlike latest), so value assertions stay stable and the Anvil fork RPC cache stays warm and dense — every same-chain characterisation test replaying reads for one block means the on-disk RPC cache covers them all, so warm runs hit the upstream archive far less;

  • shared, so all normalised tests on a chain reuse one fork.

If a test’s vault did not exist (or has no meaningful state) at the block below, or a value invariant no longer holds there (e.g. an over-utilised lending vault), give that test its own block. When bumping a constant to a newer midnight, re-run the affected tests to refresh any block-dependent assertions.

Chains without archive history (e.g. Monad) cannot use a fixed historical block and must not be normalised here.

Blocks captured by binary-searching the archive node for the last block with timestamp <= 2026-07-24T00:00:00Z.

Module Attributes

ETHEREUM_MIDNIGHT_BLOCK

Ethereum mainnet (chain id 1).

ARBITRUM_MIDNIGHT_BLOCK

Arbitrum One (chain id 42161).

BASE_MIDNIGHT_BLOCK

Base (chain id 8453).

BINANCE_MIDNIGHT_BLOCK

BNB Smart Chain (chain id 56).

POLYGON_MIDNIGHT_BLOCK

Polygon PoS (chain id 137).

AVALANCHE_MIDNIGHT_BLOCK

Avalanche C-Chain (chain id 43114).

HYPERLIQUID_MIDNIGHT_BLOCK

HyperEVM / Hyperliquid (chain id 999).

PLASMA_MIDNIGHT_BLOCK

Plasma (chain id 9745).

SONIC_MIDNIGHT_BLOCK

Sonic (chain id 146).

BERACHAIN_MIDNIGHT_BLOCK

Berachain (chain id 80094).

MIDNIGHT_BLOCKS

Canonical midnight block keyed by chain id, for programmatic lookup.

Functions

get_midnight_block(chain_id)

Return the canonical midnight fork block for a chain id.

ETHEREUM_MIDNIGHT_BLOCK = 25598869

Ethereum mainnet (chain id 1).

ARBITRUM_MIDNIGHT_BLOCK = 487039644

Arbitrum One (chain id 42161).

BASE_MIDNIGHT_BLOCK = 49030926

Base (chain id 8453).

BINANCE_MIDNIGHT_BLOCK = 111758906

BNB Smart Chain (chain id 56).

POLYGON_MIDNIGHT_BLOCK = 90764135

Polygon PoS (chain id 137).

AVALANCHE_MIDNIGHT_BLOCK = 91076594

Avalanche C-Chain (chain id 43114).

HYPERLIQUID_MIDNIGHT_BLOCK = 41271954

HyperEVM / Hyperliquid (chain id 999).

PLASMA_MIDNIGHT_BLOCK = 27910844

Plasma (chain id 9745).

SONIC_MIDNIGHT_BLOCK = 76403589

Sonic (chain id 146).

BERACHAIN_MIDNIGHT_BLOCK = 23918239

Berachain (chain id 80094).

MIDNIGHT_BLOCKS: dict[int, int] = {1: 25598869, 56: 111758906, 137: 90764135, 146: 76403589, 999: 41271954, 8453: 49030926, 9745: 27910844, 42161: 487039644, 43114: 91076594, 80094: 23918239}

Canonical midnight block keyed by chain id, for programmatic lookup.

get_midnight_block(chain_id)

Return the canonical midnight fork block for a chain id.

Parameters

chain_id (int) – EVM chain id, e.g. 1 for Ethereum mainnet.

Returns

Fixed block number to fork at (see module docstring).

Raises

KeyError – If the chain has no canonical midnight block recorded (e.g. a chain without archive history, or one not yet added here).

Return type

int