aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-08-25 00:20:26 +0800
committerGitHub <noreply@github.com>2016-08-25 00:20:26 +0800
commit806e3cd0751e7769bddbb2d4250b4520d912df42 (patch)
tree3188e4e6624ea79f05ee68bff5f6c7ca43d7bcad
parenta2b2c8adc9dcd45e86ba26ce69db506c8d4b018a (diff)
parent8923325d5c9e14e33478261b6c191e8fb092e1c4 (diff)
downloaddexon-806e3cd0751e7769bddbb2d4250b4520d912df42.tar
dexon-806e3cd0751e7769bddbb2d4250b4520d912df42.tar.gz
dexon-806e3cd0751e7769bddbb2d4250b4520d912df42.tar.bz2
dexon-806e3cd0751e7769bddbb2d4250b4520d912df42.tar.lz
dexon-806e3cd0751e7769bddbb2d4250b4520d912df42.tar.xz
dexon-806e3cd0751e7769bddbb2d4250b4520d912df42.tar.zst
dexon-806e3cd0751e7769bddbb2d4250b4520d912df42.zip
Merge pull request #2943 from Arachnid/tracing
internal/ethapi: Fix bug in opCodeWrapper usage
-rw-r--r--internal/ethapi/tracer.go4
-rw-r--r--internal/ethapi/tracer_test.go25
2 files changed, 23 insertions, 6 deletions
diff --git a/internal/ethapi/tracer.go b/internal/ethapi/tracer.go
index 37cb7ec36..16ec6ebf0 100644
--- a/internal/ethapi/tracer.go
+++ b/internal/ethapi/tracer.go
@@ -284,8 +284,10 @@ func (jst *JavascriptTracer) CaptureState(env vm.Environment, pc uint64, op vm.O
jst.stack.stack = stack
jst.db.db = env.Db()
+ ocw := &opCodeWrapper{op}
+
jst.log["pc"] = pc
- jst.log["op"] = &opCodeWrapper{op}
+ jst.log["op"] = ocw.toValue(jst.vm)
jst.log["gas"] = gas.Int64()
jst.log["gasPrice"] = cost.Int64()
jst.log["memory"] = jst.memvalue
diff --git a/internal/ethapi/tracer_test.go b/internal/ethapi/tracer_test.go
index dbc38bbbc..301ff4840 100644
--- a/internal/ethapi/tracer_test.go
+++ b/internal/ethapi/tracer_test.go
@@ -19,6 +19,7 @@ package ethapi
import (
"errors"
"math/big"
+ "reflect"
"testing"
"time"
@@ -140,12 +141,26 @@ func TestStack(t *testing.T) {
t.Fatal(err)
}
- value, ok := ret.([]int)
- if !ok {
- t.Errorf("Expected return value to be []int, was %T", ret)
+ expected := []int{0, 1, 2}
+ if !reflect.DeepEqual(ret, expected) {
+ t.Errorf("Expected return value to be %#v, got %#v", expected, ret)
+ }
+}
+
+func TestOpcodes(t *testing.T) {
+ tracer, err := NewJavascriptTracer("{opcodes: [], step: function(log) { this.opcodes.push(log.op.toString()); }, result: function() { return this.opcodes; }}")
+ if err != nil {
+ t.Fatal(err)
}
- if len(value) != 3 || value[0] != 0 || value[1] != 1 || value[2] != 2 {
- t.Errorf("Expected return value to be [0 1 2], got %v", value)
+
+ ret, err := runTrace(tracer)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ expected := []string{"PUSH1", "PUSH1", "STOP"}
+ if !reflect.DeepEqual(ret, expected) {
+ t.Errorf("Expected return value to be %#v, got %#v", expected, ret)
}
}