degenbot.provider.offline_provider ================================== .. py:module:: degenbot.provider.offline_provider .. autoapi-nested-parse:: 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 :class:`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). .. rubric:: 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 --------------- .. py:class:: OfflineProvider(chain_id: int, blocks: dict[str, dict[str, Any]]) Bases: :py:obj:`_OfflineDataMixin`, :py:obj:`_OfflineLifecycleMixin` Ethereum 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 Rust :class:`AlloyProvider` built over an in-memory offline transport, so it is indistinguishable from a live provider to any consumer (including :class:`BotIo`). Recorded-JSON metadata (``chain_id``, ``block_numbers``) is parsed in Python for the convenience accessors; the public surface is assembled from the mixins. .. attribute:: chain_id The chain ID this provider serves data for .. attribute:: blocks Dictionary of recorded block data keyed by block number string .. rubric:: 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) .. py:method:: from_json_file(path: pathlib.Path) -> OfflineProvider :classmethod: 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). :param path: Path to the JSON file containing recorded data :returns: An OfflineProvider instance loaded from the file.