...

Source file src/github.com/transparency-dev/merkle/compact/node_fuzz_test.go

Documentation: github.com/transparency-dev/merkle/compact

     1  //go:build go1.18
     2  
     3  package compact
     4  
     5  import (
     6  	"testing"
     7  )
     8  
     9  // Test that RangeNodes returns a slice of nodes with contiguous coverage.
    10  // https://github.com/transparency-dev/merkle/blob/main/docs/compact_ranges.md#definition
    11  func FuzzRangeNodes(f *testing.F) {
    12  	for begin := 0; begin <= 10; begin++ {
    13  		for end := begin; end <= 20; end++ {
    14  			f.Add(uint64(end), uint64(end))
    15  		}
    16  	}
    17  	f.Fuzz(func(t *testing.T, begin, end uint64) {
    18  		if begin > end {
    19  			return
    20  		}
    21  		t.Logf("begin=%d, end=%d", begin, end)
    22  		nodes := RangeNodes(begin, end, nil)
    23  		t.Logf("nodes=%v", nodes)
    24  
    25  		// Nodes should be contiguous covering begin to end
    26  		previousEnd := begin
    27  		for _, node := range nodes {
    28  			b, e := node.Coverage()
    29  			if b != previousEnd {
    30  				t.Errorf("got=%d, want=%d", b, previousEnd)
    31  			}
    32  			previousEnd = e
    33  		}
    34  		if previousEnd != end {
    35  			t.Errorf("got=%d, want=%d", previousEnd, end)
    36  		}
    37  	})
    38  }
    39  

View as plain text