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
-
18
1
import logging
19
2
import pytest
20
- from os import path
3
+ from unittest . mock import MagicMock , PropertyMock
21
4
22
- from unittest .mock import patch , MagicMock , PropertyMock
23
- from web3 import Web3 , HTTPProvider
5
+ from web3 import Web3
24
6
from web3 .providers .base import BaseProvider
25
7
26
8
from pymaker import Address
33
15
from chief_keeper .chief_keeper import ChiefKeeper
34
16
from chief_keeper .database import SimpleDatabase
35
17
36
-
37
18
@pytest .fixture (scope = 'session' )
38
19
def new_deployment () -> Deployment :
39
20
return Deployment ()
@@ -43,42 +24,45 @@ def deployment(new_deployment: Deployment) -> Deployment:
43
24
new_deployment .reset ()
44
25
return new_deployment
45
26
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
49
33
self ._accounts = [
50
34
"0x50FF810797f75f6bfbf2227442e0c961a8562F4C" ,
51
35
"0x9e1FfFaBdC50e54e030F6E5F7fC27c7Dd22a3F4e" ,
52
36
"0x5BEB2D3aA2333A524703Af18310AcFf462c04723" ,
53
37
"0x7fBe5C7C4E7a8B52b8aAA44425Fc1c0d0e72c2AA"
54
38
]
39
+
40
+ @property
41
+ def accounts (self ):
42
+ return self ._accounts
55
43
44
+ class MockWeb3 (Web3 ):
45
+ def __init__ (self , provider : BaseProvider ):
46
+ super ().__init__ (provider )
47
+ self ._eth = MockEth ()
48
+
56
49
@property
57
50
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
62
52
63
53
@pytest .fixture (scope = "session" )
64
54
def web3 () -> Web3 :
65
-
66
55
provider = MagicMock (spec = BaseProvider )
67
56
web3 = MockWeb3 (provider )
68
57
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
-
74
58
register_keys (web3 ,
75
59
["key_file=tests/config/keys/UnlimitedChain/key1.json,pass_file=/dev/null" ,
76
60
"key_file=tests/config/keys/UnlimitedChain/key2.json,pass_file=/dev/null" ,
77
61
"key_file=tests/config/keys/UnlimitedChain/key3.json,pass_file=/dev/null" ,
78
62
"key_file=tests/config/keys/UnlimitedChain/key4.json,pass_file=/dev/null" ,
79
63
"key_file=tests/config/keys/UnlimitedChain/key.json,pass_file=/dev/null" ])
80
64
81
- # reduce logspew
65
+ # Reduce logspew
82
66
logging .getLogger ("web3" ).setLevel (logging .INFO )
83
67
logging .getLogger ("urllib3" ).setLevel (logging .INFO )
84
68
logging .getLogger ("asyncio" ).setLevel (logging .INFO )
@@ -113,15 +97,13 @@ def deployment_address(web3) -> Address:
113
97
114
98
@pytest .fixture (scope = "session" )
115
99
def mcd (web3 ) -> DssDeployment :
116
-
117
100
deployment = DssDeployment .from_network (web3 = web3 , network = "testnet" )
118
101
validate_contracts_loaded (deployment )
119
-
120
102
return deployment
121
103
122
104
@pytest .fixture (scope = "session" )
123
105
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" ))
125
107
assert isinstance (keeper , ChiefKeeper )
126
108
keeper .web3 = mcd .web3 # Assign the mocked web3 instance
127
109
return keeper
0 commit comments