forked from oceanprotocol/ocean.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest_ganache.py
204 lines (137 loc) · 4.47 KB
/
conftest_ganache.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#
# Copyright 2023 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
#
from typing import Tuple
import pytest
from ocean_lib.example_config import get_config_dict
from ocean_lib.models.data_nft import DataNFT
from ocean_lib.models.data_nft_factory import DataNFTFactoryContract
from ocean_lib.models.datatoken1 import Datatoken1
from ocean_lib.models.factory_router import FactoryRouter
from ocean_lib.models.fixed_rate_exchange import FixedRateExchange
from ocean_lib.ocean.util import get_address_of_type, send_ether, to_wei
from ocean_lib.web3_internal.contract_utils import get_contracts_addresses_all_networks
from tests.resources.helper_functions import (
deploy_erc721_erc20,
get_another_consumer_wallet,
get_consumer_ocean_instance,
get_consumer_wallet,
get_factory_deployer_wallet,
get_file1,
get_file2,
get_file3,
get_ganache_wallet,
get_provider_wallet,
get_publisher_ocean_instance,
get_publisher_wallet,
get_wallet,
setup_logging,
)
_NETWORK = "ganache"
setup_logging()
@pytest.fixture(autouse=True)
def setup_all(request, config, ocean_token):
# a test can skip setup_all() via decorator "@pytest.mark.nosetup_all"
if "nosetup_all" in request.keywords:
return
wallet = get_ganache_wallet()
if not wallet:
return
if not get_contracts_addresses_all_networks(config):
print("Can not find adddresses.")
return
balance = config["web3_instance"].eth.get_balance(wallet.address)
assert balance >= to_wei(10), "Need more ETH"
amt_distribute = to_wei(1000)
ocean_token.mint(wallet, to_wei(2000), {"from": wallet})
for w in (get_publisher_wallet(), get_consumer_wallet()):
balance = config["web3_instance"].eth.get_balance(w.address)
if balance < to_wei(2):
send_ether(config, wallet, w.address, to_wei(4))
if ocean_token.balanceOf(w) < to_wei(100):
ocean_token.mint(w, amt_distribute, {"from": wallet})
@pytest.fixture
def config():
return get_config_dict()
@pytest.fixture
def publisher_ocean():
return get_publisher_ocean_instance()
@pytest.fixture
def basic_asset(publisher_ocean, publisher_wallet):
name = "Branin dataset"
url = "https://raw.githubusercontent.com/trentmc/branin/main/branin.arff"
(data_nft, datatoken, ddo) = publisher_ocean.assets.create_url_asset(
name, url, {"from": publisher_wallet}
)
assert ddo.nft["name"] == name
assert len(ddo.datatokens) == 1
return (data_nft, datatoken, ddo)
@pytest.fixture
def consumer_ocean():
return get_consumer_ocean_instance()
@pytest.fixture
def publisher_wallet():
return get_publisher_wallet()
@pytest.fixture
def consumer_wallet():
return get_consumer_wallet()
@pytest.fixture
def another_consumer_wallet():
return get_another_consumer_wallet()
@pytest.fixture
def factory_deployer_wallet(config):
return get_factory_deployer_wallet(config)
@pytest.fixture
def ocean_address(config) -> str:
return get_address_of_type(config, "Ocean")
@pytest.fixture
def ocean_token(config, ocean_address) -> Datatoken1:
return Datatoken1(config, ocean_address)
@pytest.fixture
def factory_router(config):
return FactoryRouter(config, get_address_of_type(config, "Router"))
@pytest.fixture
def data_nft_factory(config):
return DataNFTFactoryContract(config, get_address_of_type(config, "ERC721Factory"))
@pytest.fixture
def provider_wallet():
return get_provider_wallet()
@pytest.fixture
def file1():
return get_file1()
@pytest.fixture
def file2():
return get_file2()
@pytest.fixture
def file3():
return get_file3()
@pytest.fixture
def FRE(config) -> FixedRateExchange:
return FixedRateExchange(config, get_address_of_type(config, "FixedPrice"))
@pytest.fixture
def data_nft(config, publisher_wallet) -> DataNFT:
return deploy_erc721_erc20(config, publisher_wallet)
@pytest.fixture
def data_NFT_and_DT(config, publisher_wallet) -> Tuple[DataNFT, Datatoken1]:
return deploy_erc721_erc20(config, publisher_wallet, publisher_wallet)
@pytest.fixture
def DT(data_NFT_and_DT) -> Datatoken1:
(_, DT) = data_NFT_and_DT
return DT
# aliases
@pytest.fixture
def OCEAN(ocean_token) -> Datatoken1:
return ocean_token
@pytest.fixture
def alice(publisher_wallet):
return publisher_wallet
@pytest.fixture
def bob(consumer_wallet):
return consumer_wallet
@pytest.fixture
def carlos():
return get_wallet(8)
@pytest.fixture
def dan():
return get_wallet(7)