-
Notifications
You must be signed in to change notification settings - Fork 38
/
conftest.py
108 lines (77 loc) · 2.38 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
import os
import pytest
from eth_account import Account
from ocean_provider.run import app
from ocean_provider.utils.basics import get_provider_private_key, get_web3, send_ether
from ocean_provider.utils.provider_fees import get_c2d_environments
app = app
@pytest.fixture
def client():
client = app.test_client()
yield client
@pytest.fixture
def publisher_wallet():
return Account.from_key(os.getenv("TEST_PRIVATE_KEY1"))
@pytest.fixture
def publisher_address(publisher_wallet):
return publisher_wallet.address
@pytest.fixture
def consumer_wallet():
return Account.from_key(os.getenv("TEST_PRIVATE_KEY2"))
@pytest.fixture
def consumer_address(consumer_wallet):
return consumer_wallet.address
@pytest.fixture
def ganache_wallet():
web3 = get_web3(8996)
if (
web3.eth.accounts
and web3.eth.accounts[0].lower()
== "0xe2DD09d719Da89e5a3D0F2549c7E24566e947260".lower()
):
return Account.from_key(
"0xfd5c1ccea015b6d663618850824154a3b3fb2882c46cefb05b9a93fea8c3d215"
)
return None
@pytest.fixture
def provider_wallet():
pk = get_provider_private_key(8996)
return Account.from_key(pk)
@pytest.fixture
def provider_address(provider_wallet):
return provider_wallet.address
@pytest.fixture(autouse=True)
def setup_all(provider_address, consumer_address, ganache_wallet):
web3 = get_web3(8996)
if ganache_wallet:
if (
web3.fromWei(
web3.eth.get_balance(provider_address, block_identifier="latest"),
"ether",
)
< 10
):
send_ether(web3, ganache_wallet, provider_address, 25)
if (
web3.fromWei(
web3.eth.get_balance(provider_address, block_identifier="latest"),
"ether",
)
< 10
):
send_ether(web3, ganache_wallet, consumer_address, 25)
@pytest.fixture
def web3():
return get_web3(8996)
@pytest.fixture
def free_c2d_env():
environments = get_c2d_environments(flat=True)
return next(env for env in environments if float(env["priceMin"]) == float(0))
@pytest.fixture
def paid_c2d_env():
environments = get_c2d_environments(flat=True)
return next(env for env in environments if env["id"] == "ocean-compute-env2")