Skip to content

Commit

Permalink
Debug test (#686)
Browse files Browse the repository at this point in the history
* test: add coverage tests for api/debug package from 0 to 80.2%

* refactor: extract custom tracer does not exist error into public var

* refactor: extract function to create the tracer

* test: increment debug code coverage

* refactor: typo in test functions name

* doc: add comments to separate api/debug endpoints tests

* fix: remove unnecessary conversion

* refactor: remnove deferred error handling when attempting to create a custom tracer

* refactor: replace extractTracer with createTracer method in debug struct

* refactor: remove unused struct

* test: readd attempt to create non existing tracer test

* refactor: remove unused var
  • Loading branch information
paologalligit authored Apr 22, 2024
1 parent 992ef0f commit ac224fd
Show file tree
Hide file tree
Showing 2 changed files with 558 additions and 26 deletions.
42 changes: 16 additions & 26 deletions api/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package debug

import (
"context"
"encoding/json"
"math"
"math/big"
"net/http"
Expand Down Expand Up @@ -151,20 +152,12 @@ func (d *Debug) handleTraceClause(w http.ResponseWriter, req *http.Request) erro
if err := utils.ParseJSON(req.Body, &opt); err != nil {
return utils.BadRequest(errors.WithMessage(err, "body"))
}
var tracer tracers.Tracer
if opt.Name == "" {
tr, err := logger.NewStructLogger(opt.Config)
if err != nil {
return utils.Forbidden(err)
}
tracer = tr
} else {
tr, err := tracers.DefaultDirectory.New(opt.Name, opt.Config, d.allowCustomTracer)
if err != nil {
return utils.Forbidden(err)
}
tracer = tr

tracer, err := d.createTracer(opt.Name, opt.Config)
if err != nil {
return utils.Forbidden(err)
}

blockID, txIndex, clauseIndex, err := d.parseTarget(opt.Target)
if err != nil {
return err
Expand All @@ -187,19 +180,9 @@ func (d *Debug) handleTraceCall(w http.ResponseWriter, req *http.Request) error
return err
}

var tracer tracers.Tracer
if opt.Name == "" {
tr, err := logger.NewStructLogger(opt.Config)
if err != nil {
return utils.Forbidden(err)
}
tracer = tr
} else {
tr, err := tracers.DefaultDirectory.New(opt.Name, opt.Config, d.allowCustomTracer)
if err != nil {
return utils.Forbidden(err)
}
tracer = tr
tracer, err := d.createTracer(opt.Name, opt.Config)
if err != nil {
return utils.Forbidden(err)
}

txCtx, gas, clause, err := d.handleTraceCallOption(&opt)
Expand All @@ -215,6 +198,13 @@ func (d *Debug) handleTraceCall(w http.ResponseWriter, req *http.Request) error
return utils.WriteJSON(w, res)
}

func (d *Debug) createTracer(name string, config json.RawMessage) (tracers.Tracer, error) {
if name == "" {
return logger.NewStructLogger(config)
}
return tracers.DefaultDirectory.New(name, config, d.allowCustomTracer)
}

func (d *Debug) traceCall(ctx context.Context, tracer tracers.Tracer, summary *chain.BlockSummary, txCtx *xenv.TransactionContext, gas uint64, clause *tx.Clause) (interface{}, error) {
header := summary.Header
state := d.stater.NewState(header.StateRoot(), header.Number(), summary.Conflicts, summary.SteadyNum)
Expand Down
Loading

0 comments on commit ac224fd

Please sign in to comment.