|  | 
| 1 | 1 | # Ethereum Hive Simulators Python Library | 
| 2 | 2 | 
 | 
| 3 |  | -Write hive simulators using python | 
|  | 3 | +[](https://badge.fury.io/py/ethereum-hive) | 
|  | 4 | +[](https://pypi.org/project/ethereum-hive/) | 
|  | 5 | +[](https://www.gnu.org/licenses/gpl-3.0) | 
|  | 6 | +[](https://github.com/astral-sh/uv) | 
| 4 | 7 | 
 | 
| 5 |  | -## Run tests | 
|  | 8 | +Write [ethereum/hive](https://github.com/ethereum/hive) simulators using Python. | 
| 6 | 9 | 
 | 
| 7 |  | -#### Fetch and build hive: | 
|  | 10 | +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. | 
|  | 11 | + | 
|  | 12 | +## Installation | 
| 8 | 13 | 
 | 
| 9 | 14 | ```bash | 
| 10 |  | -git clone https://github.com/ethereum/hive.git | 
| 11 |  | -cd hive | 
| 12 |  | -go build -v . | 
|  | 15 | +pip install ethereum-hive | 
| 13 | 16 | ``` | 
| 14 | 17 | 
 | 
| 15 |  | -#### Run hive in dev mode | 
| 16 |  | -```bash | 
| 17 |  | -./hive --dev --client go-ethereum,lighthouse-bn,lighthouse-vc | 
|  | 18 | +## Features | 
|  | 19 | + | 
|  | 20 | +- **Client Management**: Start, stop, and manage Ethereum clients. | 
|  | 21 | +- **Network Configuration**: Configure custom networks and genesis configuration. | 
|  | 22 | +- **Test Simulation**: Run comprehensive test suites against Ethereum clients. | 
|  | 23 | + | 
|  | 24 | +## Quick Start | 
|  | 25 | + | 
|  | 26 | +### Start a Hive Development Server | 
|  | 27 | + | 
|  | 28 | +```console | 
|  | 29 | +./hive --dev --client go-ethereum | 
| 18 | 30 | ``` | 
| 19 | 31 | 
 | 
| 20 |  | -#### Run tests | 
| 21 |  | -```bash | 
| 22 |  | -pytest | 
| 23 |  | -``` | 
|  | 32 | +### Basic Example | 
|  | 33 | + | 
|  | 34 | +Here's a basic example of how to use the Hive Python API with Hive running in developer mode. It requires a [genesis file](https://github.com/ethereum/hive-python-api/blob/e4a1108f3a8feab4c0d638f1393a94319733ae89/src/hive/tests/genesis.json); please modify the path as required. | 
|  | 35 | + | 
|  | 36 | +```python | 
|  | 37 | +from pathlib import Path | 
|  | 38 | + | 
|  | 39 | +from hive.simulation import Simulation | 
|  | 40 | +from hive.testing import HiveTestResult | 
|  | 41 | + | 
|  | 42 | +# Create a simulation on a development hive server | 
|  | 43 | +simulator = Simulation(url="http://127.0.0.1:3000") | 
|  | 44 | + | 
|  | 45 | +# Get information about the hive instance cli args and clients | 
|  | 46 | +hive_info = simulator.hive_instance() | 
|  | 47 | + | 
|  | 48 | +# Start a test suite | 
|  | 49 | +suite = simulator.start_suite("my_test_suite", "my test suite description") | 
|  | 50 | + | 
|  | 51 | +# Start a test | 
|  | 52 | +test = suite.start_test("my_test", "my test description") | 
|  | 53 | + | 
|  | 54 | +# Start a client for the test | 
|  | 55 | +all_clients = simulator.client_types() | 
|  | 56 | +print(all_clients[0].version) | 
|  | 57 | + | 
|  | 58 | +# Specify the genesis file; here we use the genesis from the unit test | 
|  | 59 | +files = {"genesis.json": Path("src/hive/tests/genesis.json").as_posix()} | 
|  | 60 | +env = {"HIVE_CHAIN_ID": "1"} | 
|  | 61 | +client = test.start_client(client_type=all_clients[0], environment=env, files=files) | 
|  | 62 | + | 
|  | 63 | +# Run your test logic | 
|  | 64 | +# ... | 
|  | 65 | + | 
|  | 66 | +# Stop the test and the suite (will clean-up clients) | 
|  | 67 | +test.end(result=HiveTestResult(test_pass=True, details="test details")) | 
|  | 68 | +suite.end() | 
|  | 69 | +``` | 
|  | 70 | + | 
|  | 71 | +For more detailed examples, check out the [unit tests](https://github.com/ethereum/hive-python-api/blob/e4a1108f3a8feab4c0d638f1393a94319733ae89/src/hive/tests/test_sanity.py) or explore the simulators in the [execution-spec-tests](https://github.com/ethereum/execution-spec-tests) repository. | 
|  | 72 | + | 
|  | 73 | +## Development | 
|  | 74 | + | 
|  | 75 | +### Setup | 
|  | 76 | + | 
|  | 77 | +1. Install `uv`: | 
|  | 78 | + | 
|  | 79 | +   ```bash | 
|  | 80 | +   curl -LsSf https://astral.sh/uv/install.sh | sh | 
|  | 81 | +   ``` | 
|  | 82 | + | 
|  | 83 | +2. Clone and setup the project: | 
|  | 84 | + | 
|  | 85 | +   ```bash | 
|  | 86 | +   git clone https://github.com/marioevz/hive.py.git | 
|  | 87 | +   cd hive.py | 
|  | 88 | +   uv sync --all-extras | 
|  | 89 | +   ``` | 
|  | 90 | + | 
|  | 91 | +### Running Tests | 
|  | 92 | + | 
|  | 93 | +#### Prerequisites | 
|  | 94 | + | 
|  | 95 | +1. Fetch and build hive: | 
|  | 96 | + | 
|  | 97 | +   ```bash | 
|  | 98 | +   git clone https://github.com/ethereum/hive.git | 
|  | 99 | +   cd hive | 
|  | 100 | +   go build -v . | 
|  | 101 | +   ``` | 
|  | 102 | + | 
|  | 103 | +2. Run hive in dev mode: | 
|  | 104 | + | 
|  | 105 | +   ```bash | 
|  | 106 | +   ./hive --dev --client go-ethereum,lighthouse-bn,lighthouse-vc | 
|  | 107 | +   ``` | 
|  | 108 | + | 
|  | 109 | +3. Run the test suite: | 
|  | 110 | + | 
|  | 111 | +   ```bash | 
|  | 112 | +   uv run pytest | 
|  | 113 | +   ``` | 
|  | 114 | + | 
|  | 115 | +### Code Quality | 
|  | 116 | + | 
|  | 117 | +- **Linting**: `uv run black src/` | 
|  | 118 | +- **Type checking**: `uv run mypy src/` | 
|  | 119 | +- **Import sorting**: `uv run isort src/` | 
|  | 120 | + | 
|  | 121 | +## Contributing | 
|  | 122 | + | 
|  | 123 | +Contributions are welcome! Please feel free to submit a Pull Request. | 
|  | 124 | + | 
|  | 125 | +## License | 
|  | 126 | + | 
|  | 127 | +This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details. | 
|  | 128 | + | 
|  | 129 | +## Related Projects | 
|  | 130 | + | 
|  | 131 | +- [ethereum/hive](https://github.com/ethereum/hive) - The main Hive testing framework. | 
|  | 132 | +- [ethereum/execution-spec-tests](https://github.com/ethereum/execution-spec-tests) - Contains implementations of several Hive simulators. | 
0 commit comments