degenbot.provider.offline_provider¶
Offline provider for testing without RPC calls.
This module provides a provider implementation that serves pre-recorded chain data from JSON files, allowing tests to run without requiring a live blockchain connection.
The heavy lifting lives in the Rust degenbot_rpc::offline module (an
in-memory alloy Transport over recorded data). This Python class is a thin
delegating shell: it parses the recorded JSON for metadata (chain_id,
block_numbers) and holds a real Rust AlloyProvider (PyAlloyProvider)
that answers call/get_code/get_block/get_block_number via the
offline transport — so a consumer cannot distinguish an OfflineProvider from
a live provider. BotIo can hold it natively (O2/B1).
Example
>>> from degenbot.provider import OfflineProvider
>>>
>>> # Load recorded data
>>> offline = OfflineProvider.from_json_file(
... Path("tests/fixtures/chain_data/1/multi_block.json")
... )
>>>
>>> # Use in tests
>>> result = offline.call(to="0x...", data=calldata, block=24945700)
Module Contents¶
- class degenbot.provider.offline_provider.OfflineProvider(chain_id: int, blocks: dict[str, dict[str, Any]])¶
Bases:
_OfflineDataMixin,_OfflineLifecycleMixinEthereum provider that serves pre-recorded chain data.
Delegates every data-serving RPC (
call,get_code,get_block,get_block_number,get_block_timestamp) to a real RustAlloyProviderbuilt over an in-memory offline transport, so it is indistinguishable from a live provider to any consumer (includingBotIo). Recorded-JSON metadata (chain_id,block_numbers) is parsed in Python for the convenience accessors; the public surface is assembled from the mixins.- chain_id¶
The chain ID this provider serves data for
- blocks¶
Dictionary of recorded block data keyed by block number string
Example
>>> offline = OfflineProvider( ... chain_id=1, ... blocks={ ... "24945700": { ... "timestamp": 1776984059, ... "calls": {"0x...:0x...": "0x..."}, ... "code": {"0x...": "0x..."}, ... } ... }, ... ) >>> result = offline.call(to="0x...", data=b"...", block=24945700)
- classmethod from_json_file(path: pathlib.Path) OfflineProvider¶
Load recorded data from a JSON file.
Supports both old multi-block format (with “blocks” key) and new single-block format (with “block_number” key).
- Parameters:
path – Path to the JSON file containing recorded data
- Returns:
An OfflineProvider instance loaded from the file.