Skip to content

Commit b4e087c

Browse files
kcloweswolovim
authored andcommitted
Add typing to parity module
1 parent 52e6ada commit b4e087c

File tree

6 files changed

+55
-59
lines changed

6 files changed

+55
-59
lines changed

tests/integration/parity/common.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,39 +42,10 @@ def test_eth_uninstallFilter(self, web3):
4242
pytest.xfail('eth_uninstallFilter calls to parity always return true')
4343
super().test_eth_uninstallFilter(web3)
4444

45-
def test_eth_replaceTransaction(self, web3, unlocked_account):
46-
super().test_eth_replaceTransaction(web3, unlocked_account)
47-
4845
@pytest.mark.xfail(reason='Parity is not setup to auto mine')
4946
def test_eth_replaceTransaction_already_mined(self, web3, unlocked_account):
5047
super().test_eth_replaceTransaction_already_mined(web3, unlocked_account)
5148

52-
def test_eth_replaceTransaction_incorrect_nonce(self, web3, unlocked_account):
53-
super().test_eth_replaceTransaction_incorrect_nonce(web3, unlocked_account)
54-
55-
def test_eth_replaceTransaction_gas_price_too_low(self, web3, unlocked_account):
56-
super().test_eth_replaceTransaction_gas_price_too_low(web3, unlocked_account)
57-
58-
def test_eth_replaceTransaction_gas_price_defaulting_minimum(self, web3, unlocked_account):
59-
super().test_eth_replaceTransaction_gas_price_defaulting_minimum(web3, unlocked_account)
60-
61-
def test_eth_replaceTransaction_gas_price_defaulting_strategy_higher(self,
62-
web3,
63-
unlocked_account):
64-
super().test_eth_replaceTransaction_gas_price_defaulting_strategy_higher(
65-
web3, unlocked_account
66-
)
67-
68-
def test_eth_replaceTransaction_gas_price_defaulting_strategy_lower(self,
69-
web3,
70-
unlocked_account):
71-
super().test_eth_replaceTransaction_gas_price_defaulting_strategy_lower(
72-
web3, unlocked_account
73-
)
74-
75-
def test_eth_modifyTransaction(self, web3, unlocked_account):
76-
super().test_eth_modifyTransaction(web3, unlocked_account)
77-
7849
@flaky(max_runs=MAX_FLAKY_RUNS)
7950
def test_eth_getTransactionReceipt_unmined(self, web3, unlocked_account):
8051
# Parity diverges from json-rpc spec and retrieves pending block

web3/_utils/method_formatters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Collection,
77
Dict,
88
Iterable,
9+
NoReturn,
910
Union,
1011
)
1112

@@ -72,6 +73,7 @@
7273
)
7374
from web3.types import (
7475
RPCEndpoint,
76+
RPCResponse,
7577
TReturn,
7678
)
7779

@@ -470,7 +472,7 @@ def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]:
470472
ABI_REQUEST_FORMATTERS = abi_request_formatters(STANDARD_NORMALIZERS, RPC_ABIS)
471473

472474

473-
def raise_invalid_parity_mode(response):
475+
def raise_invalid_parity_mode(response: RPCResponse) -> NoReturn:
474476
error_message = response['error']['message']
475477
raise InvalidParityMode(error_message)
476478

@@ -479,6 +481,7 @@ def raise_invalid_parity_mode(response):
479481
RPC.parity_setMode: raise_invalid_parity_mode,
480482
}
481483

484+
482485
@to_tuple
483486
def combine_formatters(
484487
formatter_maps: Collection[Dict[RPCEndpoint, Callable[..., TReturn]]], method_name: RPCEndpoint

web3/_utils/module_testing/parity_module.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ def test_set_mode_with_bad_string(self, web3: "Web3") -> None:
162162
web3.parity.setMode('not a mode') # type: ignore
163163

164164
def test_set_mode_with_no_argument(self, web3: "Web3") -> None:
165-
with pytest.raises(InvalidParityMode, match='Invalid params: invalid length 0, expected a tuple of size 1.'):
165+
with pytest.raises(
166+
InvalidParityMode,
167+
match='Invalid params: invalid length 0, expected a tuple of size 1.'
168+
):
166169
# type ignored b/c setMode expects arguments
167170
web3.parity.setMode() # type: ignore

web3/method.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
ModuleV2,
4040
)
4141

42-
Munger = Callable[[Union["Module", "ModuleV2"], Any], Any]
42+
Munger = Callable[..., Any]
4343

4444

4545
@to_tuple
@@ -160,7 +160,7 @@ def input_munger(
160160
mungers_iter = iter(self.mungers)
161161
root_munger = next(mungers_iter)
162162
munged_inputs = pipe(
163-
root_munger(module, *args, **kwargs), # type: ignore
163+
root_munger(module, *args, **kwargs),
164164
*map(lambda m: _munger_star_apply(functools.partial(m, module)), mungers_iter))
165165

166166
return munged_inputs

web3/module.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,4 @@ def __init__(self, web3: "Web3") -> None:
9999
self.retrieve_caller_fn = retrieve_async_method_call_fn(web3, self)
100100
else:
101101
self.retrieve_caller_fn = retrieve_blocking_method_call_fn(web3, self)
102-
#TODO: Think about what this could be. web3.eth? web3.something else?
103102
self.web3 = web3

web3/parity.py

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from typing import (
2+
Callable,
23
List,
34
Optional,
5+
<<<<<<< HEAD
6+
=======
7+
Tuple,
8+
>>>>>>> Add typing to parity module
49
Union,
510
)
611

@@ -48,7 +53,6 @@
4853
default_root_munger,
4954
)
5055
from web3.module import (
51-
Module,
5256
ModuleV2,
5357
)
5458
from web3.types import (
@@ -129,63 +133,73 @@ class Parity(ModuleV2):
129133
shh: ParityShh
130134
personal: ParityPersonal
131135

132-
enode = Method(
136+
enode: Method[Callable[[], str]] = Method(
133137
RPC.parity_enode,
134138
mungers=None,
135139
)
136140

137141
def list_storage_keys_munger(
138142
self,
139-
address: Union[Address, ChecksumAddress, ENS],
143+
address: Union[Address, ChecksumAddress, ENS, Hash32],
140144
quantity: int,
141145
hash_: Hash32,
146+
<<<<<<< HEAD
142147
block_identifier: Optional[BlockIdentifier] = None,
143148
) -> List[Hash32]:
149+
=======
150+
block_identifier: Optional[BlockIdentifier]=None,
151+
) -> Tuple[Union[Address, ChecksumAddress, ENS, Hash32], int, Hash32, BlockIdentifier]:
152+
>>>>>>> Add typing to parity module
144153
if block_identifier is None:
145154
block_identifier = self.defaultBlock
146-
return [address, quantity, hash_, block_identifier]
155+
return (address, quantity, hash_, block_identifier)
147156

148-
listStorageKeys = Method(
157+
listStorageKeys: Method[Callable[..., List[Hash32]]] = Method(
149158
RPC.parity_listStorageKeys,
150159
mungers=[list_storage_keys_munger],
151160
)
152161

153-
netPeers = Method(
162+
netPeers: Method[Callable[[], ParityNetPeers]] = Method(
154163
RPC.parity_netPeers,
155164
mungers=None
156165
)
157166

158-
addReservedPeer = Method(
167+
addReservedPeer: Method[Callable[[EnodeURI], bool]] = Method(
159168
RPC.parity_addReservedPeer,
160169
mungers=[default_root_munger],
161170
)
162171

163-
def trace_transactions_munger(
164-
self, block_identifier: BlockIdentifier, mode: ParityTraceMode=['trace']
165-
) -> List[ParityBlockTrace]:
166-
return [block_identifier, mode]
172+
def trace_replay_transaction_munger(
173+
self, block_identifier: _Hash32, mode: ParityTraceMode=['trace']
174+
) -> Tuple[Union[BlockIdentifier, _Hash32], ParityTraceMode]:
175+
return (block_identifier, mode)
167176

168-
traceReplayTransaction = Method(
177+
traceReplayTransaction: Method[Callable[..., ParityBlockTrace]] = Method(
169178
RPC.trace_replayTransaction,
170-
mungers=[trace_transactions_munger],
179+
mungers=[trace_replay_transaction_munger],
171180
)
172181

173-
traceReplayBlockTransactions = Method(
182+
def trace_replay_block_transactions_munger(
183+
self, block_identifier: BlockIdentifier, mode: ParityTraceMode=['trace']
184+
) -> Tuple[BlockIdentifier, ParityTraceMode]:
185+
return (block_identifier, mode)
186+
187+
traceReplayBlockTransactions: Method[Callable[..., List[ParityBlockTrace]]] = Method(
174188
RPC.trace_replayBlockTransactions,
175-
mungers=[trace_transactions_munger]
189+
mungers=[trace_replay_block_transactions_munger]
176190
)
177191

178-
traceBlock = Method(
192+
traceBlock: Method[Callable[[BlockIdentifier], List[ParityBlockTrace]]] = Method(
179193
RPC.trace_block,
180194
mungers=[default_root_munger],
181195
)
182196

183-
traceFilter = Method(
197+
traceFilter: Method[Callable[[ParityFilterParams], List[ParityFilterTrace]]] = Method(
184198
RPC.trace_filter,
185199
mungers=[default_root_munger],
186200
)
187201

188-
traceTransaction = Method(
202+
traceTransaction: Method[Callable[[_Hash32], List[ParityFilterTrace]]] = Method(
189203
RPC.trace_transaction,
190204
mungers=[default_root_munger],
191205
)
@@ -194,33 +208,39 @@ def trace_call_munger(
194208
self,
195209
transaction: TxParams,
196210
mode: ParityTraceMode=['trace'],
197-
block_identifier: BlockIdentifier=None
198-
) -> ParityBlockTrace:
211+
block_identifier: Optional[BlockIdentifier]=None
212+
) -> Tuple[TxParams, ParityTraceMode, BlockIdentifier]:
213+
# TODO: move to middleware
199214
if 'from' not in transaction and is_checksum_address(self.web3.eth.defaultAccount):
200215
transaction = assoc(transaction, 'from', self.web3.eth.defaultAccount)
201216

202217
# TODO: move to middleware
203218
if block_identifier is None:
204219
block_identifier = self.defaultBlock
205220

206-
return [transaction, mode, block_identifier]
221+
return (transaction, mode, block_identifier)
207222

208-
traceCall = Method(
223+
traceCall: Method[Callable[..., ParityBlockTrace]] = Method(
209224
RPC.trace_call,
210225
mungers=[trace_call_munger],
211226
)
212227

213-
traceRawTransaction = Method(
228+
def trace_transactions_munger(
229+
self, raw_transaction: HexStr, mode: ParityTraceMode=['trace']
230+
) -> Tuple[HexStr, ParityTraceMode]:
231+
return (raw_transaction, mode)
232+
233+
traceRawTransaction: Method[Callable[..., ParityBlockTrace]] = Method(
214234
RPC.trace_rawTransaction,
215235
mungers=[trace_transactions_munger],
216236
)
217237

218-
setMode = Method(
238+
setMode: Method[Callable[[ParityMode], bool]] = Method(
219239
RPC.parity_setMode,
220240
mungers=[default_root_munger],
221241
)
222242

223-
mode = Method(
243+
mode: Method[Callable[[], ParityMode]] = Method(
224244
RPC.parity_mode,
225245
mungers=None
226246
)

0 commit comments

Comments
 (0)