Skip to content

Commit 6ae83f6

Browse files
committed
eth/tracers/logger: testcase for output of structlogres
1 parent 941ae33 commit 6ae83f6

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

eth/tracers/logger/logger_test.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,33 @@ func TestStoreCapture(t *testing.T) {
8080
// logs bloat and confusion. See https://github.com/ethereum/go-ethereum/issues/24487
8181
func TestStructLogMarshalingOmitEmpty(t *testing.T) {
8282
tests := []struct {
83-
name string
84-
log *StructLog
85-
want string
83+
name string
84+
log *StructLog
85+
want string
86+
wantLegacy string
8687
}{
8788
{"empty err and no fields", &StructLog{},
88-
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`},
89+
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`,
90+
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0}`,
91+
},
8992
{"with err", &StructLog{Err: errors.New("this failed")},
90-
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP","error":"this failed"}`},
93+
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP","error":"this failed"}`,
94+
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0,"error":"this failed"}`},
9195
{"with mem", &StructLog{Memory: make([]byte, 2), MemorySize: 2},
92-
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memory":"0x0000","memSize":2,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`},
96+
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memory":"0x0000","memSize":2,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`,
97+
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0,"memory":[]}`},
9398
{"with 0-size mem", &StructLog{Memory: make([]byte, 0)},
94-
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`},
99+
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`,
100+
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0,"memory":[]}`},
101+
{"with stack mem", &StructLog{Memory: make([]byte, 0), Stack: make([]uint256.Int, 0)},
102+
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":[],"depth":0,"refund":0,"opName":"STOP"}`,
103+
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0,"stack":[],"memory":[]}`},
104+
{"with empty storage", &StructLog{Memory: make([]byte, 32), Storage: make(map[common.Hash]common.Hash)},
105+
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memory":"0x0000000000000000000000000000000000000000000000000000000000000000","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`,
106+
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0,"memory":["0000000000000000000000000000000000000000000000000000000000000000"],"storage":{}}`},
107+
{"with storage", &StructLog{Storage: map[common.Hash]common.Hash{common.HexToHash("0x1234"): common.HexToHash("0xaabb")}},
108+
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`,
109+
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0,"storage":{"0000000000000000000000000000000000000000000000000000000000001234":"000000000000000000000000000000000000000000000000000000000000aabb"}}`},
95110
}
96111

97112
for _, tt := range tests {
@@ -103,6 +118,14 @@ func TestStructLogMarshalingOmitEmpty(t *testing.T) {
103118
if have, want := string(blob), tt.want; have != want {
104119
t.Fatalf("mismatched results\n\thave: %v\n\twant: %v", have, want)
105120
}
121+
// now check the legacy rpc output too
122+
blob, err = json.Marshal((formatLogs([]StructLog{*tt.log}))[0])
123+
if err != nil {
124+
t.Fatal(err)
125+
}
126+
if have, want := string(blob), tt.wantLegacy; have != want {
127+
t.Fatalf("mismatched results\n\thave: %v\n\twant: %v", have, want)
128+
}
106129
})
107130
}
108131
}

0 commit comments

Comments
 (0)