forked from ethereum/py-geth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
55 lines (38 loc) · 1.22 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import json
from gevent import monkey
monkey.patch_socket()
import requests
import pytest
@pytest.fixture
def open_port():
from geth.utils import get_open_port
return get_open_port()
@pytest.fixture()
def rpc_client(open_port):
from geth.utils.encoding import force_obj_to_text
endpoint = "http://127.0.0.1:{port}".format(port=open_port)
def make_request(method, params=None, raise_on_error=True):
global nonce
nonce += 1 # NOQA
payload = {
"id": nonce,
"jsonrpc": "2.0",
"method": method,
"params": params or [],
}
payload_data = json.dumps(force_obj_to_text(payload))
response = requests.post(endpoint, data=payload_data)
if raise_on_error:
assert response.status_code == 200
result = response.json()
if 'error' in result:
raise AssertionError(result['error'])
assert set(result.keys()) == {"id", "jsonrpc", "result"}
return response.json()['result']
return make_request
@pytest.fixture()
def data_dir(tmpdir):
return str(tmpdir.mkdir("data-dir"))
@pytest.fixture()
def base_dir(tmpdir):
return str(tmpdir.mkdir("base-dir"))