Skip to content

Commit c068329

Browse files
kcloweswolovim
authored andcommitted
Change RPCResponse type to only allow an RPCError
1 parent b4e087c commit c068329

File tree

7 files changed

+15
-18
lines changed

7 files changed

+15
-18
lines changed

conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import pytest
32
import time
43
import warnings

newsfragments/validate_files.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Towncrier silently ignores files that do not match the expected ending.
44
# We use this script to ensure we catch these as errors in CI.
55

6-
import os
76
import pathlib
87
import sys
98

web3/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,6 @@ class InvalidEventABI(ValueError):
197197
class InvalidParityMode(TypeError, ValueError):
198198
# Inherits from TypeError for backwards compatibility
199199
"""
200-
Raised when web3.parity.setMode() is called with no args
200+
Raised when web3.parity.setMode() is called with no or invalid args
201201
"""
202202
pass

web3/module.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@ 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 - remove once web3 calls are moved to middleware
102103
self.web3 = web3

web3/parity.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def list_storage_keys_munger(
170170
)
171171

172172
def trace_replay_transaction_munger(
173-
self, block_identifier: _Hash32, mode: ParityTraceMode=['trace']
173+
self, block_identifier: Union[_Hash32, BlockIdentifier], mode: ParityTraceMode=['trace']
174174
) -> Tuple[Union[BlockIdentifier, _Hash32], ParityTraceMode]:
175175
return (block_identifier, mode)
176176

@@ -179,14 +179,9 @@ def trace_replay_transaction_munger(
179179
mungers=[trace_replay_transaction_munger],
180180
)
181181

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-
187182
traceReplayBlockTransactions: Method[Callable[..., List[ParityBlockTrace]]] = Method(
188183
RPC.trace_replayBlockTransactions,
189-
mungers=[trace_replay_block_transactions_munger]
184+
mungers=[trace_replay_transaction_munger]
190185
)
191186

192187
traceBlock: Method[Callable[[BlockIdentifier], List[ParityBlockTrace]]] = Method(

web3/providers/eth_tester/main.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)
1515
from web3.types import (
1616
RPCEndpoint,
17+
RPCError,
1718
RPCResponse,
1819
)
1920

@@ -87,16 +88,18 @@ def make_request(self, method: RPCEndpoint, params: Any) -> RPCResponse:
8788
try:
8889
delegator = self.api_endpoints[namespace][endpoint]
8990
except KeyError:
90-
return RPCResponse({
91-
"error": "Unknown RPC Endpoint: {0}".format(method),
92-
})
93-
91+
return RPCResponse(
92+
{"error": RPCError({"message": f"Unknown RPC Endpoint: {method}", "code": -32600})}
93+
)
9494
try:
9595
response = delegator(self.ethereum_tester, params)
9696
except NotImplementedError:
97-
return RPCResponse({
98-
"error": "RPC Endpoint has not been implemented: {0}".format(method),
99-
})
97+
return RPCResponse(
98+
{"error": RPCError({
99+
"message": f"RPC Endpoint has not been implemented: {method}",
100+
"code": -32600,
101+
})}
102+
)
100103
else:
101104
return {
102105
'result': response,

web3/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class RPCError(TypedDict):
119119

120120

121121
class RPCResponse(TypedDict, total=False):
122-
error: Union[RPCError, str]
122+
error: RPCError
123123
id: int
124124
jsonrpc: Literal["2.0"]
125125
result: Any

0 commit comments

Comments
 (0)