Skip to content

Commit dcc0b37

Browse files
authored
eth/tracers: refactor block context in test runner (#29450)
This commit contains a minor refactoring of the block context used within the test runners. --------- Signed-off-by: jsvisa <[email protected]>
1 parent b1f88ef commit dcc0b37

File tree

8 files changed

+37
-35
lines changed

8 files changed

+37
-35
lines changed

eth/tracers/internal/tracetest/calltrace_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,8 @@ type callTrace struct {
6565

6666
// callTracerTest defines a single test to check the call tracer against.
6767
type callTracerTest struct {
68-
Genesis *core.Genesis `json:"genesis"`
69-
Context *callContext `json:"context"`
70-
Input string `json:"input"`
71-
TracerConfig json.RawMessage `json:"tracerConfig"`
72-
Result *callTrace `json:"result"`
68+
tracerTestEnv
69+
Result *callTrace `json:"result"`
7370
}
7471

7572
// Iterates over all the input-output datasets in the tracer test harness and

eth/tracers/internal/tracetest/flat_calltrace_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,8 @@ type flatCallTraceResult struct {
7777

7878
// flatCallTracerTest defines a single test to check the call tracer against.
7979
type flatCallTracerTest struct {
80-
Genesis *core.Genesis `json:"genesis"`
81-
Context *callContext `json:"context"`
82-
Input string `json:"input"`
83-
TracerConfig json.RawMessage `json:"tracerConfig"`
84-
Result []flatCallTrace `json:"result"`
80+
tracerTestEnv
81+
Result []flatCallTrace `json:"result"`
8582
}
8683

8784
func flatCallTracerTestRunner(tracerName string, filename string, dirPath string, t testing.TB) error {

eth/tracers/internal/tracetest/makeTest.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ var makeTest = function(tx, traceConfig) {
3131
delete genesis.transactions;
3232
delete genesis.transactionsRoot;
3333
delete genesis.uncles;
34+
delete genesis.withdrawals;
35+
delete genesis.withdrawalsRoot;
36+
delete genesis.baseFeePerGas;
3437

3538
genesis.gasLimit = genesis.gasLimit.toString();
3639
genesis.number = genesis.number.toString();
@@ -60,11 +63,15 @@ var makeTest = function(tx, traceConfig) {
6063
context.baseFeePerGas = block.baseFeePerGas.toString();
6164
}
6265

63-
console.log(JSON.stringify({
66+
var data = {
6467
genesis: genesis,
6568
context: context,
66-
input: eth.getRawTransaction(tx),
67-
result: result,
68-
tracerConfig: traceConfig.tracerConfig,
69-
}, null, 2));
69+
input: eth.getRawTransaction(tx),
70+
result: result,
71+
};
72+
if (traceConfig && traceConfig.tracerConfig) {
73+
data.tracerConfig = traceConfig.tracerConfig;
74+
}
75+
76+
console.log(JSON.stringify(data, null, 2));
7077
}

eth/tracers/internal/tracetest/prestate_test.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,25 @@ type account struct {
4343
Storage map[common.Hash]common.Hash `json:"storage"`
4444
}
4545

46-
// testcase defines a single test to check the stateDiff tracer against.
47-
type testcase struct {
48-
Genesis *core.Genesis `json:"genesis"`
49-
Context *callContext `json:"context"`
50-
Input string `json:"input"`
51-
TracerConfig json.RawMessage `json:"tracerConfig"`
52-
Result interface{} `json:"result"`
46+
// prestateTracerTest defines a single test to check the stateDiff tracer against.
47+
type prestateTracerTest struct {
48+
tracerTestEnv
49+
Result interface{} `json:"result"`
5350
}
5451

5552
func TestPrestateTracerLegacy(t *testing.T) {
56-
testPrestateDiffTracer("prestateTracerLegacy", "prestate_tracer_legacy", t)
53+
testPrestateTracer("prestateTracerLegacy", "prestate_tracer_legacy", t)
5754
}
5855

5956
func TestPrestateTracer(t *testing.T) {
60-
testPrestateDiffTracer("prestateTracer", "prestate_tracer", t)
57+
testPrestateTracer("prestateTracer", "prestate_tracer", t)
6158
}
6259

6360
func TestPrestateWithDiffModeTracer(t *testing.T) {
64-
testPrestateDiffTracer("prestateTracer", "prestate_tracer_with_diff_mode", t)
61+
testPrestateTracer("prestateTracer", "prestate_tracer_with_diff_mode", t)
6562
}
6663

67-
func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
64+
func testPrestateTracer(tracerName string, dirPath string, t *testing.T) {
6865
files, err := os.ReadDir(filepath.Join("testdata", dirPath))
6966
if err != nil {
7067
t.Fatalf("failed to retrieve tracer test suite: %v", err)
@@ -77,7 +74,7 @@ func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
7774
t.Parallel()
7875

7976
var (
80-
test = new(testcase)
77+
test = new(prestateTracerTest)
8178
tx = new(types.Transaction)
8279
)
8380
// Call tracer test found, read if from disk

eth/tracers/internal/tracetest/testdata/call_tracer/blob_tx.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
1515
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a",
1616
"timestamp": "1709626771",
17-
"withdrawals": [],
18-
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
1917
"alloc": {
2018
"0x0000000000000000000000000000000000000000": {
2119
"balance": "0x272e0528"

eth/tracers/internal/tracetest/testdata/prestate_tracer/blob_tx.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
1515
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a",
1616
"timestamp": "1709626771",
17-
"withdrawals": [],
18-
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
1917
"alloc": {
2018
"0x0000000000000000000000000000000000000000": {
2119
"balance": "0x272e0528"

eth/tracers/internal/tracetest/testdata/prestate_tracer/create_create.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
"number": "1",
1212
"stateRoot": "0xd2ebe0a7f3572ffe3e5b4c78147376d3fca767f236e4dd23f9151acfec7cb0d1",
1313
"timestamp": "1699617692",
14-
"withdrawals": [],
15-
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
1614
"alloc": {
1715
"0x0000000000000000000000000000000000000000": {
1816
"balance": "0x5208"

eth/tracers/internal/tracetest/util.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package tracetest
1818

1919
import (
20+
"encoding/json"
2021
"math/big"
2122
"strings"
2223
"unicode"
@@ -42,7 +43,8 @@ func camel(str string) string {
4243
return strings.Join(pieces, "")
4344
}
4445

45-
type callContext struct {
46+
// traceContext defines a context used to construct the block context
47+
type traceContext struct {
4648
Number math.HexOrDecimal64 `json:"number"`
4749
Difficulty *math.HexOrDecimal256 `json:"difficulty"`
4850
Time math.HexOrDecimal64 `json:"timestamp"`
@@ -51,7 +53,7 @@ type callContext struct {
5153
BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"`
5254
}
5355

54-
func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
56+
func (c *traceContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
5557
context := vm.BlockContext{
5658
CanTransfer: core.CanTransfer,
5759
Transfer: core.Transfer,
@@ -77,3 +79,11 @@ func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
7779
}
7880
return context
7981
}
82+
83+
// tracerTestEnv defines a tracer test required fields
84+
type tracerTestEnv struct {
85+
Genesis *core.Genesis `json:"genesis"`
86+
Context *traceContext `json:"context"`
87+
Input string `json:"input"`
88+
TracerConfig json.RawMessage `json:"tracerConfig"`
89+
}

0 commit comments

Comments
 (0)