From 008469a292e4f955643cb6bb7bef31ae7299f1a8 Mon Sep 17 00:00:00 2001 From: hickford Date: Mon, 18 Jul 2022 15:58:17 +0100 Subject: [PATCH 1/6] Fuzz test for RangeNodes --- compact/nodes_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/compact/nodes_test.go b/compact/nodes_test.go index c9981ef..4805612 100644 --- a/compact/nodes_test.go +++ b/compact/nodes_test.go @@ -118,3 +118,30 @@ func refRangeNodes(root NodeID, begin, end uint64) []NodeID { refRangeNodes(NewNodeID(root.Level-1, root.Index*2), begin, end), refRangeNodes(NewNodeID(root.Level-1, root.Index*2+1), begin, end)...) } + +// Test that RangeNodes returns a slice of nodes with contiguous coverage. +// https://github.com/transparency-dev/merkle/blob/main/docs/compact_ranges.md#definition +func FuzzRangeNodes(f *testing.F) { + f.Fuzz(func(t *testing.T, begin, end uint64) { + if begin > end { + return + } + t.Logf("begin=%d, end=%d", begin, end) + ids := make([]NodeID, 0) + nodes := RangeNodes(begin, end, ids) + t.Logf("nodes=%v", nodes) + + // Nodes should be contiguous covering begin to end + previousEnd := begin + for _, node := range nodes { + b, e := node.Coverage() + if b != previousEnd { + t.Errorf("got=%d, want=%d", b, previousEnd) + } + previousEnd = e + } + if previousEnd != end { + t.Errorf("got=%d, want=%d", previousEnd, end) + } + }) +} From 6f63f32d71c9bf4a7de4c46edef2568d02fb3447 Mon Sep 17 00:00:00 2001 From: hickford Date: Mon, 18 Jul 2022 16:32:37 +0100 Subject: [PATCH 2/6] Address code review comment --- compact/nodes_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compact/nodes_test.go b/compact/nodes_test.go index 4805612..ef10b57 100644 --- a/compact/nodes_test.go +++ b/compact/nodes_test.go @@ -127,8 +127,7 @@ func FuzzRangeNodes(f *testing.F) { return } t.Logf("begin=%d, end=%d", begin, end) - ids := make([]NodeID, 0) - nodes := RangeNodes(begin, end, ids) + nodes := RangeNodes(begin, end, nil) t.Logf("nodes=%v", nodes) // Nodes should be contiguous covering begin to end From 3bd2834734753f5e45709921fcab70a30c995ae2 Mon Sep 17 00:00:00 2001 From: hickford Date: Mon, 18 Jul 2022 16:33:02 +0100 Subject: [PATCH 3/6] Bump go version to 1.18 --- .github/workflows/go_test.yml | 2 +- .github/workflows/golangci-lint.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go_test.yml b/.github/workflows/go_test.yml index e567f41..0cd4d1b 100644 --- a/.github/workflows/go_test.yml +++ b/.github/workflows/go_test.yml @@ -4,7 +4,7 @@ jobs: test: strategy: matrix: - go-version: [1.17.x, 1.18.x] + go-version: [1.18.x] os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 16a7b0b..7b0c3c9 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/setup-go@v3 with: - go-version: 1.17 + go-version: 1.18 - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 From c3aa56b0693594c56ef6daf3e63881b6a1d32cb6 Mon Sep 17 00:00:00 2001 From: Al Cutter Date: Wed, 20 Jul 2022 15:41:06 +0000 Subject: [PATCH 4/6] Move fuzz test into a build-tag protected file --- compact/node_fuzz_test.go | 33 +++++++++++++++++++++++++++++++++ compact/nodes_test.go | 26 -------------------------- 2 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 compact/node_fuzz_test.go diff --git a/compact/node_fuzz_test.go b/compact/node_fuzz_test.go new file mode 100644 index 0000000..a5a135b --- /dev/null +++ b/compact/node_fuzz_test.go @@ -0,0 +1,33 @@ +//go:build go1.18 + +package compact + +import ( + "testing" +) + +// Test that RangeNodes returns a slice of nodes with contiguous coverage. +// https://github.com/transparency-dev/merkle/blob/main/docs/compact_ranges.md#definition +func FuzzRangeNodes(f *testing.F) { + f.Fuzz(func(t *testing.T, begin, end uint64) { + if begin > end { + return + } + t.Logf("begin=%d, end=%d", begin, end) + nodes := RangeNodes(begin, end, nil) + t.Logf("nodes=%v", nodes) + + // Nodes should be contiguous covering begin to end + previousEnd := begin + for _, node := range nodes { + b, e := node.Coverage() + if b != previousEnd { + t.Errorf("got=%d, want=%d", b, previousEnd) + } + previousEnd = e + } + if previousEnd != end { + t.Errorf("got=%d, want=%d", previousEnd, end) + } + }) +} diff --git a/compact/nodes_test.go b/compact/nodes_test.go index ef10b57..c9981ef 100644 --- a/compact/nodes_test.go +++ b/compact/nodes_test.go @@ -118,29 +118,3 @@ func refRangeNodes(root NodeID, begin, end uint64) []NodeID { refRangeNodes(NewNodeID(root.Level-1, root.Index*2), begin, end), refRangeNodes(NewNodeID(root.Level-1, root.Index*2+1), begin, end)...) } - -// Test that RangeNodes returns a slice of nodes with contiguous coverage. -// https://github.com/transparency-dev/merkle/blob/main/docs/compact_ranges.md#definition -func FuzzRangeNodes(f *testing.F) { - f.Fuzz(func(t *testing.T, begin, end uint64) { - if begin > end { - return - } - t.Logf("begin=%d, end=%d", begin, end) - nodes := RangeNodes(begin, end, nil) - t.Logf("nodes=%v", nodes) - - // Nodes should be contiguous covering begin to end - previousEnd := begin - for _, node := range nodes { - b, e := node.Coverage() - if b != previousEnd { - t.Errorf("got=%d, want=%d", b, previousEnd) - } - previousEnd = e - } - if previousEnd != end { - t.Errorf("got=%d, want=%d", previousEnd, end) - } - }) -} From 93a317504d23dbda417c8ab98bf8a42c70b2987f Mon Sep 17 00:00:00 2001 From: Al Cutter Date: Wed, 20 Jul 2022 15:43:47 +0000 Subject: [PATCH 5/6] Rollback changes to presubmit test configs --- .github/workflows/go_test.yml | 2 +- .github/workflows/golangci-lint.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go_test.yml b/.github/workflows/go_test.yml index 0cd4d1b..e567f41 100644 --- a/.github/workflows/go_test.yml +++ b/.github/workflows/go_test.yml @@ -4,7 +4,7 @@ jobs: test: strategy: matrix: - go-version: [1.18.x] + go-version: [1.17.x, 1.18.x] os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 7b0c3c9..16a7b0b 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: 1.17 - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 From 0186e479b6575c14ab2141d8493617c8573717b4 Mon Sep 17 00:00:00 2001 From: Al Cutter Date: Wed, 20 Jul 2022 15:48:48 +0000 Subject: [PATCH 6/6] Open up, tell me what you really think --- .github/workflows/go_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go_test.yml b/.github/workflows/go_test.yml index e567f41..9c70486 100644 --- a/.github/workflows/go_test.yml +++ b/.github/workflows/go_test.yml @@ -12,5 +12,5 @@ jobs: with: go-version: ${{ matrix.go-version }} - uses: actions/checkout@v3 - - run: go test -race -covermode=atomic -coverprofile=coverage.out ./... + - run: go test -v -race -covermode=atomic -coverprofile=coverage.out ./... - uses: codecov/codecov-action@v2