Skip to content

Commit e1d4a94

Browse files
committed
docs: fix example in readme
1 parent 802b7ef commit e1d4a94

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

README.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,49 @@ pip install ethereum-hive
2323

2424
## Quick Start
2525

26-
Here's a basic example of how to use the Hive Python API:
26+
### Start a Hive Development Server
27+
28+
```console
29+
./hive --dev --client go-ethereum
30+
```
31+
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.
2735

2836
```python
29-
from hive import Hive
30-
from hive.client import Client
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")
3153

32-
# Initialize Hive simulator
33-
hive = Hive()
54+
# Start a client for the test
55+
all_clients = simulator.client_types()
56+
print(all_clients[0].version)
3457

35-
# Start a client
36-
client = hive.start_client("go-ethereum")
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)
3762

3863
# Run your test logic
3964
# ...
4065

41-
# Stop the client
42-
hive.stop_client(client)
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()
4369
```
4470

4571
For more detailed examples, check out the [unit tests](src/hive/tests/test_sanity.py) or explore the simulators in the [execution-spec-tests](https://github.com/ethereum/execution-spec-tests) repository.

0 commit comments

Comments
 (0)