Skip to main content

Ethereum Hive Simulator Python API

Project description

Ethereum Hive Simulators Python Library

PyPI version Python versions License: GPL v3 uv

Write ethereum/hive simulators using Python.

This library provides a Python API for creating and running Ethereum Hive simulation tests, allowing you to test Ethereum clients against various scenarios and network conditions.

Installation

pip install ethereum-hive

Features

  • Client Management: Start, stop, and manage Ethereum clients.
  • Network Configuration: Configure custom networks and genesis configuration.
  • Test Simulation: Run comprehensive test suites against Ethereum clients.

Quick Start

Start a Hive Development Server

./hive --dev --client go-ethereum

Basic Example

Here's a basic example of how to use the Hive Python API with Hive running in developer mode. It requires a genesis file; please modify the path as required.

from pathlib import Path

from hive.simulation import Simulation
from hive.testing import HiveTestResult

# Create a simulation on a development hive server
simulator = Simulation(url="http://127.0.0.1:3000")

# Get information about the hive instance cli args and clients
hive_info = simulator.hive_instance()

# Start a test suite
suite = simulator.start_suite("my_test_suite", "my test suite description")

# Start a test
test = suite.start_test("my_test", "my test description")

# Start a client for the test
all_clients = simulator.client_types()
print(all_clients[0].version)

# Specify the genesis file; here we use the genesis from the unit test
files = {"genesis.json": Path("src/hive/tests/genesis.json").as_posix()}
env = {"HIVE_CHAIN_ID": "1"}
client = test.start_client(client_type=all_clients[0], environment=env, files=files)

# Run your test logic
# ...

# Stop the test and the suite (will clean-up clients)
test.end(result=HiveTestResult(test_pass=True, details="test details"))
suite.end()

For more detailed examples, check out the unit tests or explore the simulators in the execution-spec-tests repository.

Development

Setup

  1. Install uv:

    curl -LsSf https://astral.sh/uv/install.sh | sh
    
  2. Clone and setup the project:

    git clone https://github.com/marioevz/hive.py.git
    cd hive.py
    uv sync --all-extras
    

Running Tests

Prerequisites

  1. Fetch and build hive:

    git clone https://github.com/ethereum/hive.git
    cd hive
    go build -v .
    
  2. Run hive in dev mode:

    ./hive --dev --client go-ethereum,lighthouse-bn,lighthouse-vc
    
  3. Run the test suite:

    uv run pytest
    

Code Quality

  • Linting: uv run black src/
  • Type checking: uv run mypy src/
  • Import sorting: uv run isort src/

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

Related Projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ethereum_hive-0.1.0a5.tar.gz (75.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ethereum_hive-0.1.0a5-py3-none-any.whl (37.6 kB view details)

Uploaded Python 3

File details

Details for the file ethereum_hive-0.1.0a5.tar.gz.

File metadata

  • Download URL: ethereum_hive-0.1.0a5.tar.gz
  • Upload date:
  • Size: 75.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ethereum_hive-0.1.0a5.tar.gz
Algorithm Hash digest
SHA256 bf91d3144c263a1a6407c931b3864ab3edd40bc5c34b812e571e7c49cc70f9eb
MD5 5c0ee23660375f7ef814cc360950c3b0
BLAKE2b-256 40a895676acd86095a5dcf5dacfa5a991175b3a547dcd5729735fea777b8feec

See more details on using hashes here.

File details

Details for the file ethereum_hive-0.1.0a5-py3-none-any.whl.

File metadata

  • Download URL: ethereum_hive-0.1.0a5-py3-none-any.whl
  • Upload date:
  • Size: 37.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ethereum_hive-0.1.0a5-py3-none-any.whl
Algorithm Hash digest
SHA256 3225747ed83a9124a697db0ab8d736c4820117462e64aa3395bbc1588c4d40d0
MD5 cdeb46bf301b453e68bb210e30dd9275
BLAKE2b-256 7395986727018ac0401562d91961e2f46462ed65a08e2d5162a255d9f871a7ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page