Skip to content

Commit b710603

Browse files
committed
Add eth-tester MethodNotFound response format
1 parent 699bf6c commit b710603

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

tests/core/manager/test_response_formatters.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
"available",
4242
},
4343
}
44+
ETH_TESTER_METHOD_NOT_FOUND_RESP_FORMAT = {
45+
"error": "the method eth_getTransactionByHash does not exist/is not available",
46+
}
4447

4548

4649
def raise_contract_logic_error(response):
@@ -121,6 +124,13 @@ def raise_contract_logic_error(response):
121124
identity,
122125
MethodUnavailable,
123126
),
127+
(
128+
ETH_TESTER_METHOD_NOT_FOUND_RESP_FORMAT,
129+
(),
130+
identity,
131+
identity,
132+
ValueError,
133+
),
124134
],
125135
)
126136
def test_formatted_response_raises_errors(

web3/manager.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,14 @@ def formatted_response(
189189
) -> Any:
190190
if "error" in response:
191191
apply_error_formatters(error_formatters, response)
192-
if response["error"].get("code") == -32601:
193-
raise MethodUnavailable(response["error"])
192+
193+
try:
194+
resp_code = response["error"].get("code")
195+
if resp_code == -32601:
196+
raise MethodUnavailable(response["error"])
197+
# eth-tester returns the error response as a string
198+
except AttributeError:
199+
pass
194200
raise ValueError(response["error"])
195201
# NULL_RESPONSES includes None, so return False here as the default
196202
# so we don't apply the null_result_formatters if there is no 'result' key

0 commit comments

Comments
 (0)