@@ -80,18 +80,33 @@ func TestStoreCapture(t *testing.T) {
80
80
// logs bloat and confusion. See https://github.com/ethereum/go-ethereum/issues/24487
81
81
func TestStructLogMarshalingOmitEmpty (t * testing.T ) {
82
82
tests := []struct {
83
- name string
84
- log * StructLog
85
- want string
83
+ name string
84
+ log * StructLog
85
+ want string
86
+ wantLegacy string
86
87
}{
87
88
{"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
+ },
89
92
{"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"}` },
91
95
{"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":[]}` },
93
98
{"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"}}` },
95
110
}
96
111
97
112
for _ , tt := range tests {
@@ -103,6 +118,14 @@ func TestStructLogMarshalingOmitEmpty(t *testing.T) {
103
118
if have , want := string (blob ), tt .want ; have != want {
104
119
t .Fatalf ("mismatched results\n \t have: %v\n \t want: %v" , have , want )
105
120
}
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 \t have: %v\n \t want: %v" , have , want )
128
+ }
106
129
})
107
130
}
108
131
}
0 commit comments