Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
begmaroman committed Oct 5, 2023
1 parent 4073c1e commit 1b3ffd6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 92 deletions.
54 changes: 9 additions & 45 deletions jsonrpc/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ func (c *Client) Debug() *Debug {
}

type TraceTransactionOptions struct {
EnableMemory bool
DisableStack bool
DisableStorage bool
EnableReturnData bool
Timeout string
Tracer string
TracerConfig map[string]interface{}
EnableMemory bool `json:"enableMemory"`
DisableStack bool `json:"disableStack"`
DisableStorage bool `json:"disableStorage"`
EnableReturnData bool `json:"enableReturnData"`
Timeout string `json:"timeout,omitempty"`
Tracer string `json:"tracer,omitempty"`
TracerConfig map[string]interface{} `json:"tracerConfig,omitempty"`
}

type TransactionTrace struct {
Expand All @@ -38,44 +38,8 @@ type StructLogs struct {
Storage map[string]string
}

func (d *Debug) TraceTransaction(hash ethgo.Hash, opts *TraceTransactionOptions) (*TransactionTrace, error) {
func (d *Debug) TraceTransaction(hash ethgo.Hash, opts TraceTransactionOptions) (*TransactionTrace, error) {
var res *TransactionTrace
err := d.c.Call("debug_traceTransaction", &res, hash, toTraceTransactionOpts(opts))
err := d.c.Call("debug_traceTransaction", &res, hash, opts)
return res, err
}

func toTraceTransactionOpts(opts *TraceTransactionOptions) map[string]interface{} {
optsMap := make(map[string]interface{})

if opts != nil {
if opts.EnableMemory {
optsMap["enableMemory"] = true
}

if opts.DisableStack {
optsMap["disableStack"] = true
}

if opts.DisableStorage {
optsMap["disableStorage"] = true
}

if opts.EnableReturnData {
optsMap["enableReturnData"] = true
}

if opts.Timeout != "" {
optsMap["timeout"] = opts.Timeout
}

if opts.Tracer != "" {
optsMap["tracer"] = opts.Tracer

if len(opts.TracerConfig) > 0 {
optsMap["tracerConfig"] = opts.TracerConfig
}
}
}

return optsMap
}
48 changes: 1 addition & 47 deletions jsonrpc/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,54 +22,8 @@ func TestDebug_TraceTransaction(t *testing.T) {
r, err := s.TxnTo(addr, "setA2")
require.NoError(t, err)

trace, err := c.Debug().TraceTransaction(r.TransactionHash, nil)
trace, err := c.Debug().TraceTransaction(r.TransactionHash, TraceTransactionOptions{})
assert.NoError(t, err)
assert.Greater(t, trace.Gas, uint64(20000))
assert.NotEmpty(t, trace.StructLogs)
}

func Test_toTraceTransactionOpts(t *testing.T) {
tests := []struct {
name string
opts *TraceTransactionOptions
want map[string]interface{}
}{
{
name: "nil options provided",
opts: nil,
want: map[string]interface{}{},
},
{
name: "all fields are provided",
opts: &TraceTransactionOptions{
EnableMemory: true,
DisableStack: true,
DisableStorage: true,
EnableReturnData: true,
Timeout: "1s",
Tracer: "callTracer",
TracerConfig: map[string]interface{}{
"onlyTopCall": true,
"withLog": true,
},
},
want: map[string]interface{}{
"disableStack": true,
"disableStorage": true,
"enableMemory": true,
"enableReturnData": true,
"timeout": "1s",
"tracer": "callTracer",
"tracerConfig": map[string]interface{}{
"onlyTopCall": true,
"withLog": true,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, toTraceTransactionOpts(tt.opts), "toTraceTransactionOpts(%v)", tt.opts)
})
}
}

0 comments on commit 1b3ffd6

Please sign in to comment.