Skip to content

Commit fdc37a8

Browse files
committed
sintax
1 parent e55f3a9 commit fdc37a8

File tree

1 file changed

+20
-38
lines changed

1 file changed

+20
-38
lines changed

tests/conftest.py

+20-38
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
1-
# This file is part of Maker Keeper Framework.
2-
#
3-
# Copyright (C) 2017-2019 reverendus, EdNoepel
4-
#
5-
# This program is free software: you can redistribute it and/or modify
6-
# it under the terms of the GNU Affero General Public License as published by
7-
# the Free Software Foundation, either version 3 of the License, or
8-
# (at your option) any later version.
9-
#
10-
# This program is distributed in the hope that it will be useful,
11-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
# GNU Affero General Public License for more details.
14-
#
15-
# You should have received a copy of the GNU Affero General Public License
16-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17-
181
import logging
192
import pytest
20-
from os import path
3+
from unittest.mock import MagicMock, PropertyMock
214

22-
from unittest.mock import patch, MagicMock, PropertyMock
23-
from web3 import Web3, HTTPProvider
5+
from web3 import Web3
246
from web3.providers.base import BaseProvider
257

268
from pymaker import Address
@@ -33,7 +15,6 @@
3315
from chief_keeper.chief_keeper import ChiefKeeper
3416
from chief_keeper.database import SimpleDatabase
3517

36-
3718
@pytest.fixture(scope='session')
3819
def new_deployment() -> Deployment:
3920
return Deployment()
@@ -43,42 +24,45 @@ def deployment(new_deployment: Deployment) -> Deployment:
4324
new_deployment.reset()
4425
return new_deployment
4526

46-
class MockWeb3(Web3):
47-
def __init__(self, provider: BaseProvider):
48-
super().__init__(provider)
27+
class MockEth:
28+
def __init__(self):
29+
self.defaultAccount = "0x50FF810797f75f6bfbf2227442e0c961a8562F4C"
30+
self.sendTransaction = MagicMock()
31+
self.getBalance = MagicMock(return_value=1000000000000000000) # 1 ETH
32+
self.blockNumber = 12345678
4933
self._accounts = [
5034
"0x50FF810797f75f6bfbf2227442e0c961a8562F4C",
5135
"0x9e1FfFaBdC50e54e030F6E5F7fC27c7Dd22a3F4e",
5236
"0x5BEB2D3aA2333A524703Af18310AcFf462c04723",
5337
"0x7fBe5C7C4E7a8B52b8aAA44425Fc1c0d0e72c2AA"
5438
]
39+
40+
@property
41+
def accounts(self):
42+
return self._accounts
5543

44+
class MockWeb3(Web3):
45+
def __init__(self, provider: BaseProvider):
46+
super().__init__(provider)
47+
self._eth = MockEth()
48+
5649
@property
5750
def eth(self):
58-
eth_mock = MagicMock()
59-
accounts_mock = PropertyMock(return_value=self._accounts)
60-
type(eth_mock).accounts = accounts_mock
61-
return eth_mock
51+
return self._eth
6252

6353
@pytest.fixture(scope="session")
6454
def web3() -> Web3:
65-
6655
provider = MagicMock(spec=BaseProvider)
6756
web3 = MockWeb3(provider)
6857

69-
web3.eth.defaultAccount = "0x50FF810797f75f6bfbf2227442e0c961a8562F4C"
70-
web3.eth.sendTransaction = MagicMock()
71-
web3.eth.getBalance = MagicMock(return_value=1000000000000000000) # 1 ETH
72-
web3.eth.blockNumber = 12345678
73-
7458
register_keys(web3,
7559
["key_file=tests/config/keys/UnlimitedChain/key1.json,pass_file=/dev/null",
7660
"key_file=tests/config/keys/UnlimitedChain/key2.json,pass_file=/dev/null",
7761
"key_file=tests/config/keys/UnlimitedChain/key3.json,pass_file=/dev/null",
7862
"key_file=tests/config/keys/UnlimitedChain/key4.json,pass_file=/dev/null",
7963
"key_file=tests/config/keys/UnlimitedChain/key.json,pass_file=/dev/null"])
8064

81-
# reduce logspew
65+
# Reduce logspew
8266
logging.getLogger("web3").setLevel(logging.INFO)
8367
logging.getLogger("urllib3").setLevel(logging.INFO)
8468
logging.getLogger("asyncio").setLevel(logging.INFO)
@@ -113,15 +97,13 @@ def deployment_address(web3) -> Address:
11397

11498
@pytest.fixture(scope="session")
11599
def mcd(web3) -> DssDeployment:
116-
117100
deployment = DssDeployment.from_network(web3=web3, network="testnet")
118101
validate_contracts_loaded(deployment)
119-
120102
return deployment
121103

122104
@pytest.fixture(scope="session")
123105
def keeper(mcd: DssDeployment, keeper_address: Address) -> ChiefKeeper:
124-
keeper = ChiefKeeper(args=args(f"--eth-from {keeper_address} --network testnet --rpc-primary-url https://localhost:8545 --rpc-backup-url https://localhost:8545"), web3=mcd.web3)
106+
keeper = ChiefKeeper(args=args(f"--eth-from {keeper_address} --network testnet --rpc-primary-url http://localhost:8545 --rpc-backup-url http://localhost:8545"))
125107
assert isinstance(keeper, ChiefKeeper)
126108
keeper.web3 = mcd.web3 # Assign the mocked web3 instance
127109
return keeper

0 commit comments

Comments
 (0)