Skip to content

Commit

Permalink
add test condtions TestPollardNilSwap
Browse files Browse the repository at this point in the history
it does not trigger the problem in issue #337 though.  It just swaps 1, 2
  • Loading branch information
adiabat committed Jan 24, 2022
1 parent 3f771bb commit 88d4a38
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions accumulator/pollard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
30 changes: 30 additions & 0 deletions accumulator/pollard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 88d4a38

Please sign in to comment.