Skip to content

Commit

Permalink
move noopT to native
Browse files Browse the repository at this point in the history
  • Loading branch information
dhyaniarun1993 committed Mar 28, 2024
1 parent 4253a3e commit 822cba0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
2 changes: 0 additions & 2 deletions eth/tracers/js/goja.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ func fromBuf(vm *goja.Runtime, bufType goja.Value, buf goja.Value, allowString b
// jsTracer is an implementation of the Tracer interface which evaluates
// JS functions on the relevant EVM hooks. It uses Goja as its JS engine.
type jsTracer struct {
tracers.NoopTracer

vm *goja.Runtime
env *tracing.VMContext
toBig toBigFn // Converts a hex string into a JS bigint
Expand Down
1 change: 0 additions & 1 deletion eth/tracers/native/4byte.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func init() {
// 0xc281d19e-0: 1
// }
type fourByteTracer struct {
tracers.NoopTracer
ids map[string]int // ids aggregates the 4byte ids found
interrupt uint32 // Atomic flag to signal execution interruption
reason error // Textual reason for the interruption
Expand Down
1 change: 0 additions & 1 deletion eth/tracers/native/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ type callFrameMarshaling struct {
}

type callTracer struct {
tracers.NoopTracer
callstack []callFrame
config callTracerConfig
gasLimit uint64
Expand Down
7 changes: 4 additions & 3 deletions eth/tracers/noop.go → eth/tracers/native/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package tracers
package native

import (
"encoding/json"
Expand All @@ -25,6 +25,7 @@ import (

"github.com/ledgerwatch/erigon/core/tracing"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/eth/tracers"
)

func init() {
Expand All @@ -36,9 +37,9 @@ func init() {
type NoopTracer struct{}

// newNoopTracer returns a new noop tracer.
func newNoopTracer(ctx *Context, _ json.RawMessage) (*Tracer, error) {
func newNoopTracer(ctx *tracers.Context, _ json.RawMessage) (*tracers.Tracer, error) {
t := &NoopTracer{}
return &Tracer{
return &tracers.Tracer{
Hooks: &tracing.Hooks{
OnTxStart: t.OnTxStart,
OnTxEnd: t.OnTxEnd,
Expand Down
59 changes: 59 additions & 0 deletions eth/tracers/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2023 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package tracers

import (
"testing"

"github.com/ledgerwatch/erigon/core/vm"
)

func TestMemCopying(t *testing.T) {
for i, tc := range []struct {
memsize int64
offset int64
size int64
wantErr string
wantSize int
}{
{0, 0, 100, "", 100}, // Should pad up to 100
{0, 100, 0, "", 0}, // No need to pad (0 size)
{100, 50, 100, "", 100}, // Should pad 100-150
{100, 50, 5, "", 5}, // Wanted range fully within memory
{100, -50, 0, "offset or size must not be negative", 0}, // Error
{0, 1, 1024*1024 + 1, "reached limit for padding memory slice: 1048578", 0}, // Error
{10, 0, 1024*1024 + 100, "reached limit for padding memory slice: 1048666", 0}, // Error
} {
mem := vm.NewMemory()
mem.Resize(uint64(tc.memsize))
cpy, err := GetMemoryCopyPadded(mem.Data(), tc.offset, tc.size)
if want := tc.wantErr; want != "" {
if err == nil {
t.Fatalf("test %d: want '%v' have no error", i, want)
}
if have := err.Error(); want != have {
t.Fatalf("test %d: want '%v' have '%v'", i, want, have)
}
continue
}
if err != nil {
t.Fatalf("test %d: unexpected error: %v", i, err)
}
if want, have := tc.wantSize, len(cpy); have != want {
t.Fatalf("test %d: want %v have %v", i, want, have)
}
}
}

0 comments on commit 822cba0

Please sign in to comment.