-
Notifications
You must be signed in to change notification settings - Fork 218
/
conftest.py
60 lines (43 loc) · 1.13 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
56
57
58
59
60
import json
import pytest
import requests
@pytest.fixture
def open_port():
from geth.utils import (
get_open_port,
)
return get_open_port()
@pytest.fixture()
def rpc_client(open_port):
from testrpc.client.utils import (
force_obj_to_text,
)
endpoint = f"http://127.0.0.1:{open_port}"
def make_request(method, params=None):
global nonce
nonce += 1
payload = {
"id": nonce,
"jsonrpc": "2.0",
"method": method,
"params": params or [],
}
payload_data = json.dumps(force_obj_to_text(payload, True))
response = requests.post(
endpoint,
data=payload_data,
headers={
"Content-Type": "application/json",
},
)
result = response.json()
if "error" in result:
raise AssertionError(result["error"])
return result["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"))