From 88d4a3815158db175047f9b4927f169d9628f0ae Mon Sep 17 00:00:00 2001 From: adiabat Date: Mon, 24 Jan 2022 16:13:13 -0500 Subject: [PATCH] add test condtions TestPollardNilSwap it does not trigger the problem in issue #337 though. It just swaps 1, 2 --- accumulator/pollard.go | 2 ++ accumulator/pollard_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/accumulator/pollard.go b/accumulator/pollard.go index 579eb832..d5fb466b 100644 --- a/accumulator/pollard.go +++ b/accumulator/pollard.go @@ -394,6 +394,8 @@ func (p *Pollard) swapNodes(s arrow, row uint8) (*hashableNode, error) { if bhn.sib.niece[0].data == empty || bhn.sib.niece[1].data == empty { bhn = nil // we can't perform this hash as we don't know the children } + + fmt.Printf("swap %d %d OK\n", s.from, s.to) return bhn, nil } diff --git a/accumulator/pollard_test.go b/accumulator/pollard_test.go index 89a83451..ca6a9e54 100644 --- a/accumulator/pollard_test.go +++ b/accumulator/pollard_test.go @@ -56,6 +56,36 @@ func TestPollardSimpleIngest(t *testing.T) { } } +func TestPollardNilSwap(t *testing.T) { + var p Pollard + adds := make([]Leaf, 8) + for i := 0; i < len(adds); i++ { + adds[i].Hash[0] = uint8(i) + adds[i].Hash[20] = 0xff + adds[i].Remember = true + } + + adds[6].Remember = false + adds[7].Remember = false + + p.Modify(adds, nil) + fmt.Println(p.ToString()) + + adds[6].Remember = true + adds[7].Remember = true + + p.Modify(adds, nil) + fmt.Println(p.ToString()) + + dels := []uint64{8, 9, 10, 11, 12, 13, 14, 15} + p.Modify(nil, dels) + fmt.Println(p.ToString()) + + dels = []uint64{1, 3, 4, 5} + p.Modify(nil, dels) + fmt.Println(p.ToString()) +} + func pollardRandomRemember(blocks int32) error { f := NewForest(RamForest, nil, "", 0)