From c5a8a1be2f3f88a3e027f8d93f20a6ab6c01f43d Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Sat, 19 Apr 2025 23:28:56 +0200 Subject: [PATCH] compare mismatched results --- cmd/workload/filtertestfuzz.go | 42 ++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/cmd/workload/filtertestfuzz.go b/cmd/workload/filtertestfuzz.go index af5b1f2e8f..606241c32d 100644 --- a/cmd/workload/filtertestfuzz.go +++ b/cmd/workload/filtertestfuzz.go @@ -162,8 +162,10 @@ mainLoop: } if !reflect.DeepEqual(query.results, results) { fmt.Println("Results mismatch from:", query.FromBlock, "to:", query.ToBlock, "addresses:", query.Address, "topics:", query.Topics) - fmt.Println(" getLogs:", query.results) - fmt.Println(" receipts:", results) + resShared, resGetLogs, resReceipts := compareResults(query.results, results) + fmt.Println(" shared:", len(resShared)) + fmt.Println(" only from getLogs:", resGetLogs) + fmt.Println(" only from receipts:", resReceipts) continue mainLoop } fmt.Println("Successful query from:", query.FromBlock, "to:", query.ToBlock, "results:", len(query.results)) @@ -172,6 +174,42 @@ mainLoop: } } +func compareResults(a, b []types.Log) (shared, onlya, onlyb []types.Log) { + for len(a) > 0 && len(b) > 0 { + if reflect.DeepEqual(a[0], b[0]) { + shared = append(shared, a[0]) + a = a[1:] + b = b[1:] + } else { + for i := 1; ; i++ { + if i >= len(a) { // b[0] not found in a + onlyb = append(onlyb, b[0]) + b = b[1:] + break + } + if i >= len(b) { // a[0] not found in b + onlya = append(onlya, a[0]) + a = a[1:] + break + } + if reflect.DeepEqual(b[0], a[i]) { // a[:i] not found in b + onlya = append(onlya, a[:i]...) + a = a[i:] + break + } + if reflect.DeepEqual(a[0], b[i]) { // b[:i] not found in a + onlyb = append(onlyb, b[:i]...) + b = b[i:] + break + } + } + } + } + onlya = append(onlya, a...) + onlyb = append(onlyb, b...) + return +} + func getLatestHeader(client *client) (*types.Header, error) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel()