From 5e9d05b9afd3c541c01aeb8eb76765e063b4cb24 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 12 Feb 2021 19:24:11 +0300 Subject: [PATCH] scripts: ignore ledger items while comparing dumps --- scripts/compare-dumps.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/scripts/compare-dumps.go b/scripts/compare-dumps.go index f3ca4e48c..d18897d29 100644 --- a/scripts/compare-dumps.go +++ b/scripts/compare-dumps.go @@ -1,6 +1,9 @@ package main import ( + "bytes" + "encoding/base64" + "encoding/binary" "encoding/json" "errors" "fmt" @@ -12,6 +15,8 @@ import ( "github.com/urfave/cli" ) +var ledgerContractID = -2 + type dump []blockDump type blockDump struct { @@ -39,15 +44,27 @@ func readFile(path string) (dump, error) { } func (d dump) normalize() { + ledgerIDBytes := make([]byte, 4) + binary.LittleEndian.PutUint32(ledgerIDBytes, uint32(ledgerContractID)) for i := range d { + var newStorage []storageOp for j := range d[i].Storage { + keyBytes, err := base64.StdEncoding.DecodeString(d[i].Storage[j].Key) + if err != nil { + panic(fmt.Errorf("invalid key encoding: %w", err)) + } + if bytes.HasPrefix(keyBytes, ledgerIDBytes) { + continue + } if d[i].Storage[j].State == "Changed" { d[i].Storage[j].State = "Added" } + newStorage = append(newStorage, d[i].Storage[j]) } - sort.Slice(d[i].Storage, func(k, l int) bool { - return d[i].Storage[k].Key < d[i].Storage[l].Key + sort.Slice(newStorage, func(k, l int) bool { + return newStorage[k].Key < newStorage[l].Key }) + d[i].Storage = newStorage } // assume that d is already sorted by Block } @@ -72,9 +89,6 @@ func compare(a, b string) error { if blockA.Block != blockB.Block { return fmt.Errorf("block number mismatch: %d vs %d", blockA.Block, blockB.Block) } - if blockA.Size != blockB.Size { - return fmt.Errorf("block %d, changes number mismatch: %d vs %d", blockA.Block, blockA.Size, blockB.Size) - } if len(blockA.Storage) != len(blockB.Storage) { return fmt.Errorf("block %d, changes length mismatch: %d vs %d", blockA.Block, len(blockA.Storage), len(blockB.Storage)) }