Skip to content

Commit

Permalink
module/debug: Added CallTrace.RevertReason (#173)
Browse files Browse the repository at this point in the history
* adding revert reason and test case

* added new line

* slight order change

---------

Co-authored-by: lmittmann <[email protected]>
  • Loading branch information
krishnateja262 and lmittmann authored Aug 1, 2024
1 parent 00271d6 commit d792352
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
43 changes: 23 additions & 20 deletions module/debug/call_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,33 @@ func CallTraceTx(txHash common.Hash, overrides w3types.State) w3types.RPCCallerF
}

type CallTrace struct {
From common.Address
To common.Address
Type string
Gas uint64
GasUsed uint64
Value *big.Int
Input []byte
Output []byte
Error string
Calls []*CallTrace
From common.Address
To common.Address
Type string
Gas uint64
GasUsed uint64
Value *big.Int
Input []byte
Output []byte
Error string
RevertReason string
Calls []*CallTrace
}

// UnmarshalJSON implements the [json.Unmarshaler].
func (c *CallTrace) UnmarshalJSON(data []byte) error {
type call struct {
From common.Address `json:"from"`
To common.Address `json:"to"`
Type string `json:"type"`
Gas hexutil.Uint64 `json:"gas"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
Value *hexutil.Big `json:"value"`
Input hexutil.Bytes `json:"input"`
Output hexutil.Bytes `json:"output"`
Error string `json:"error"`
Calls []*CallTrace `json:"calls"`
From common.Address `json:"from"`
To common.Address `json:"to"`
Type string `json:"type"`
Gas hexutil.Uint64 `json:"gas"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
Value *hexutil.Big `json:"value"`
Input hexutil.Bytes `json:"input"`
Output hexutil.Bytes `json:"output"`
Error string `json:"error"`
RevertReason string `json:"revertReason"`
Calls []*CallTrace `json:"calls"`
}

var dec call
Expand All @@ -71,6 +73,7 @@ func (c *CallTrace) UnmarshalJSON(data []byte) error {
c.Input = dec.Input
c.Output = dec.Output
c.Error = dec.Error
c.RevertReason = dec.RevertReason
c.Calls = dec.Calls
return nil
}
Expand Down
13 changes: 13 additions & 0 deletions module/debug/call_trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ func TestCallTraceTx(t *testing.T) {
Gas: 49979000,
Value: w3.I("1 ether"),
},
}, {
Golden: "traceTx_revertReason",
Call: debug.CallTraceTx(w3.H("0x6ea1798a2d0d21db18d6e45ca00f230160b05f172f6022aa138a0b605831d740"), w3types.State{}),
WantRet: &debug.CallTrace{
From: w3.A("0x84abea9c66d30d00549429f5f687e16708aa20c0"),
To: w3.A("0xd0a7333587053a5bae772bd37b9aae724e367619"),
Type: "CALL",
Gas: 146604,
GasUsed: 81510,
Value: w3.I("0x0"),
Error: "execution reverted",
RevertReason: "BA: Insufficient gas (ETH) for refund",
},
},
}

Expand Down
2 changes: 2 additions & 0 deletions module/debug/testdata/traceTx_revertReason.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> {"jsonrpc":"2.0","id":1,"method":"debug_traceTransaction","params":["0x6ea1798a2d0d21db18d6e45ca00f230160b05f172f6022aa138a0b605831d740",{"tracer":"callTracer"}]}
< {"jsonrpc":"2.0","id":1,"result":{"from":"0x84abea9c66d30d00549429f5f687e16708aa20c0","gas":"0x23cac","gasUsed":"0x13e66","to":"0xd0a7333587053a5bae772bd37b9aae724e367619","error":"execution reverted","revertReason":"BA: Insufficient gas (ETH) for refund","calls":[],"value":"0x0","type":"CALL"}}

0 comments on commit d792352

Please sign in to comment.