Skip to content

Commit 4e471a1

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

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,13 @@ 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+
# guard against eth-tester case - eth-tester returns a string
194+
# with no code, so can't parse what the error is.
195+
if isinstance(response["error"], dict):
196+
resp_code = response["error"].get("code")
197+
if resp_code == -32601:
198+
raise MethodUnavailable(response["error"])
194199
raise ValueError(response["error"])
195200
# NULL_RESPONSES includes None, so return False here as the default
196201
# so we don't apply the null_result_formatters if there is no 'result' key

0 commit comments

Comments
 (0)