mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
eth/tracers/logger: testcase for output of structlogres
This commit is contained in:
parent
2f5c06c4ac
commit
bf5d9ff88c
1 changed files with 30 additions and 7 deletions
|
|
@ -80,18 +80,33 @@ func TestStoreCapture(t *testing.T) {
|
||||||
// logs bloat and confusion. See https://github.com/ethereum/go-ethereum/issues/24487
|
// logs bloat and confusion. See https://github.com/ethereum/go-ethereum/issues/24487
|
||||||
func TestStructLogMarshalingOmitEmpty(t *testing.T) {
|
func TestStructLogMarshalingOmitEmpty(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
log *StructLog
|
log *StructLog
|
||||||
want string
|
want string
|
||||||
|
wantLegacy string
|
||||||
}{
|
}{
|
||||||
{"empty err and no fields", &StructLog{},
|
{"empty err and no fields", &StructLog{},
|
||||||
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`},
|
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`,
|
||||||
|
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0}`,
|
||||||
|
},
|
||||||
{"with err", &StructLog{Err: errors.New("this failed")},
|
{"with err", &StructLog{Err: errors.New("this failed")},
|
||||||
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP","error":"this failed"}`},
|
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP","error":"this failed"}`,
|
||||||
|
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0,"error":"this failed"}`},
|
||||||
{"with mem", &StructLog{Memory: make([]byte, 2), MemorySize: 2},
|
{"with mem", &StructLog{Memory: make([]byte, 2), MemorySize: 2},
|
||||||
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memory":"0x0000","memSize":2,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`},
|
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memory":"0x0000","memSize":2,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`,
|
||||||
|
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0,"memory":[]}`},
|
||||||
{"with 0-size mem", &StructLog{Memory: make([]byte, 0)},
|
{"with 0-size mem", &StructLog{Memory: make([]byte, 0)},
|
||||||
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`},
|
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`,
|
||||||
|
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0,"memory":[]}`},
|
||||||
|
{"with stack mem", &StructLog{Memory: make([]byte, 0), Stack: make([]uint256.Int, 0)},
|
||||||
|
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":[],"depth":0,"refund":0,"opName":"STOP"}`,
|
||||||
|
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0,"stack":[],"memory":[]}`},
|
||||||
|
{"with empty storage", &StructLog{Memory: make([]byte, 32), Storage: make(map[common.Hash]common.Hash)},
|
||||||
|
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memory":"0x0000000000000000000000000000000000000000000000000000000000000000","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`,
|
||||||
|
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0,"memory":["0000000000000000000000000000000000000000000000000000000000000000"],"storage":{}}`},
|
||||||
|
{"with storage", &StructLog{Storage: map[common.Hash]common.Hash{common.HexToHash("0x1234"): common.HexToHash("0xaabb")}},
|
||||||
|
`{"pc":0,"op":0,"gas":"0x0","gasCost":"0x0","memSize":0,"stack":null,"depth":0,"refund":0,"opName":"STOP"}`,
|
||||||
|
`{"pc":0,"op":"STOP","gas":0,"gasCost":0,"depth":0,"storage":{"0000000000000000000000000000000000000000000000000000000000001234":"000000000000000000000000000000000000000000000000000000000000aabb"}}`},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
@ -103,6 +118,14 @@ func TestStructLogMarshalingOmitEmpty(t *testing.T) {
|
||||||
if have, want := string(blob), tt.want; have != want {
|
if have, want := string(blob), tt.want; have != want {
|
||||||
t.Fatalf("mismatched results\n\thave: %v\n\twant: %v", have, want)
|
t.Fatalf("mismatched results\n\thave: %v\n\twant: %v", have, want)
|
||||||
}
|
}
|
||||||
|
// now check the legacy rpc output too
|
||||||
|
blob, err = json.Marshal((formatLogs([]StructLog{*tt.log}))[0])
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if have, want := string(blob), tt.wantLegacy; have != want {
|
||||||
|
t.Fatalf("mismatched results\n\thave: %v\n\twant: %v", have, want)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue