From 0a3bf01a8fa0deab91bdb998181a4dda7b1dee62 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 14 May 2024 13:38:52 +0300 Subject: [PATCH] scripts: dump diff for OnPersist and PostPersist applog Related to #3424. Signed-off-by: Anna Shaleva --- scripts/compare-states/compare-states.go | 52 ++++++++++++++---------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/scripts/compare-states/compare-states.go b/scripts/compare-states/compare-states.go index 7e0e6ad7a..ec95d3fdf 100644 --- a/scripts/compare-states/compare-states.go +++ b/scripts/compare-states/compare-states.go @@ -118,32 +118,42 @@ func cliMain(c *cli.Context) error { return err } fmt.Printf("state differs at %d, block %s\n", h, blk.Hash().StringLE()) + dumpApplogDiff(true, blk.Hash(), a, b, ca, cb) for _, t := range blk.Transactions { - fmt.Printf("transaction %s:\n", t.Hash().StringLE()) - la, err := ca.GetApplicationLog(t.Hash(), nil) - if err != nil { - return err - } - lb, err := cb.GetApplicationLog(t.Hash(), nil) - if err != nil { - return err - } - da := spew.Sdump(la) - db := spew.Sdump(lb) - diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{ - A: difflib.SplitLines(da), - B: difflib.SplitLines(db), - FromFile: a, - FromDate: "", - ToFile: b, - ToDate: "", - Context: 1, - }) - fmt.Println(diff) + dumpApplogDiff(false, t.Hash(), a, b, ca, cb) } return errors.New("different state found") } +func dumpApplogDiff(isBlock bool, container util.Uint256, a string, b string, ca *rpcclient.Client, cb *rpcclient.Client) error { + if isBlock { + fmt.Printf("block %s:\n", container.StringLE()) + } else { + fmt.Printf("transaction %s:\n", container.StringLE()) + } + la, err := ca.GetApplicationLog(container, nil) + if err != nil { + return err + } + lb, err := cb.GetApplicationLog(container, nil) + if err != nil { + return err + } + da := spew.Sdump(la) + db := spew.Sdump(lb) + diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{ + A: difflib.SplitLines(da), + B: difflib.SplitLines(db), + FromFile: a, + FromDate: "", + ToFile: b, + ToDate: "", + Context: 1, + }) + fmt.Println(diff) + return nil +} + func main() { ctl := cli.NewApp() ctl.Name = "compare-states"