Skip to content

Commit

Permalink
fix: formatting for eth_call
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Aug 7, 2021
1 parent abfe67d commit 9709ecd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions brownie/network/middlewares/hardhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ def process_request(self, make_request: Callable, method: str, params: List) ->
result = make_request(method, params)

# modify Hardhat transaction error to mimick the format that Ganache uses
if method == "eth_sendTransaction" and "error" in result:
if method in ("eth_call", "eth_sendTransaction") and "error" in result:
message = result["error"]["message"]
if message.startswith("VM Exception") or message.startswith("Transaction reverted"):
txid = self.w3.eth.getBlock("latest")["transactions"][0]
if method == "eth_call":
# ganache returns a txid even on a failed eth_call, which is weird,
# but we still mimick it here for the sake of consistency
txid = "0x"
else:
txid = self.w3.eth.getBlock("latest")["transactions"][0].hex()
data: Dict = {}
result["error"]["data"] = {txid.hex(): data}
result["error"]["data"] = {txid: data}
message = message.split(": ", maxsplit=1)[-1]
if message == "Transaction reverted without a reason":
data.update({"error": "revert", "reason": None})
Expand Down

0 comments on commit 9709ecd

Please sign in to comment.