Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth/tracers: some simple adjustment for the testcase #29450

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions eth/tracers/internal/tracetest/calltrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ type callTrace struct {

// callTracerTest defines a single test to check the call tracer against.
type callTracerTest struct {
Genesis *core.Genesis `json:"genesis"`
Context *callContext `json:"context"`
Input string `json:"input"`
TracerConfig json.RawMessage `json:"tracerConfig"`
Result *callTrace `json:"result"`
tracerTestEnv
Result *callTrace `json:"result"`
}

// Iterates over all the input-output datasets in the tracer test harness and
Expand Down
7 changes: 2 additions & 5 deletions eth/tracers/internal/tracetest/flat_calltrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ type flatCallTraceResult struct {

// flatCallTracerTest defines a single test to check the call tracer against.
type flatCallTracerTest struct {
Genesis *core.Genesis `json:"genesis"`
Context *callContext `json:"context"`
Input string `json:"input"`
TracerConfig json.RawMessage `json:"tracerConfig"`
Result []flatCallTrace `json:"result"`
tracerTestEnv
Result []flatCallTrace `json:"result"`
}

func flatCallTracerTestRunner(tracerName string, filename string, dirPath string, t testing.TB) error {
Expand Down
16 changes: 12 additions & 4 deletions eth/tracers/internal/tracetest/makeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ var makeTest = function(tx, traceConfig) {
delete genesis.transactions;
delete genesis.transactionsRoot;
delete genesis.uncles;
delete genesis.withdrawals;
delete genesis.withdrawalsRoot;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a change for the sake of change :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, I'm tracing another transaction, and the genesis includes lots of withdrawals logs, seems a little redundant

delete genesis.baseFeePerGas;

genesis.gasLimit = genesis.gasLimit.toString();
genesis.number = genesis.number.toString();
Expand Down Expand Up @@ -44,10 +47,15 @@ var makeTest = function(tx, traceConfig) {
context.baseFeePerGas = block.baseFeePerGas.toString();
}

console.log(JSON.stringify({
var data = {
genesis: genesis,
context: context,
input: eth.getRawTransaction(tx),
result: result,
}, null, 2));
input: eth.getRawTransaction(tx),
result: result,
};
if (traceConfig && traceConfig.tracerConfig) {
data.tracerConfig = traceConfig.tracerConfig;
}

console.log(JSON.stringify(data, null, 2));
}
21 changes: 9 additions & 12 deletions eth/tracers/internal/tracetest/prestate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,25 @@ type account struct {
Storage map[common.Hash]common.Hash `json:"storage"`
}

// testcase defines a single test to check the stateDiff tracer against.
type testcase struct {
Genesis *core.Genesis `json:"genesis"`
Context *callContext `json:"context"`
Input string `json:"input"`
TracerConfig json.RawMessage `json:"tracerConfig"`
Result interface{} `json:"result"`
// prestateTracerTest defines a single test to check the stateDiff tracer against.
type prestateTracerTest struct {
tracerTestEnv
Result interface{} `json:"result"`
}

func TestPrestateTracerLegacy(t *testing.T) {
testPrestateDiffTracer("prestateTracerLegacy", "prestate_tracer_legacy", t)
testPrestateTracer("prestateTracerLegacy", "prestate_tracer_legacy", t)
}

func TestPrestateTracer(t *testing.T) {
testPrestateDiffTracer("prestateTracer", "prestate_tracer", t)
testPrestateTracer("prestateTracer", "prestate_tracer", t)
}

func TestPrestateWithDiffModeTracer(t *testing.T) {
testPrestateDiffTracer("prestateTracer", "prestate_tracer_with_diff_mode", t)
testPrestateTracer("prestateTracer", "prestate_tracer_with_diff_mode", t)
}

func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
func testPrestateTracer(tracerName string, dirPath string, t *testing.T) {
files, err := os.ReadDir(filepath.Join("testdata", dirPath))
if err != nil {
t.Fatalf("failed to retrieve tracer test suite: %v", err)
Expand All @@ -78,7 +75,7 @@ func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
t.Parallel()

var (
test = new(testcase)
test = new(prestateTracerTest)
tx = new(types.Transaction)
)
// Call tracer test found, read if from disk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a",
"timestamp": "1709626771",
"totalDifficulty": "1",
"withdrawals": [],
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"alloc": {
"0x0000000000000000000000000000000000000000": {
"balance": "0x272e0528"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a",
"timestamp": "1709626771",
"totalDifficulty": "1",
"withdrawals": [],
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"alloc": {
"0x0000000000000000000000000000000000000000": {
"balance": "0x272e0528"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
"stateRoot": "0xd2ebe0a7f3572ffe3e5b4c78147376d3fca767f236e4dd23f9151acfec7cb0d1",
"timestamp": "1699617692",
"totalDifficulty": "0",
"withdrawals": [],
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"alloc": {
"0x0000000000000000000000000000000000000000": {
"balance": "0x5208"
Expand Down Expand Up @@ -60,4 +58,4 @@
"balance": "0x8ac7230489e80000"
}
}
}
}
14 changes: 12 additions & 2 deletions eth/tracers/internal/tracetest/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tracetest

import (
"encoding/json"
"math/big"
"strings"
"unicode"
Expand All @@ -25,7 +26,8 @@ func camel(str string) string {
return strings.Join(pieces, "")
}

type callContext struct {
// traceContext defines a context used to construct the block context
type traceContext struct {
Number math.HexOrDecimal64 `json:"number"`
Difficulty *math.HexOrDecimal256 `json:"difficulty"`
Time math.HexOrDecimal64 `json:"timestamp"`
Expand All @@ -34,7 +36,7 @@ type callContext struct {
BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"`
}

func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
func (c *traceContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
context := vm.BlockContext{
CanTransfer: core.CanTransfer,
Transfer: core.Transfer,
Expand All @@ -53,3 +55,11 @@ func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
}
return context
}

// tracerTestEnv defines a tracer test required fields
type tracerTestEnv struct {
Genesis *core.Genesis `json:"genesis"`
Context *traceContext `json:"context"`
Input string `json:"input"`
TracerConfig json.RawMessage `json:"tracerConfig"`
}