From 893960a9e425c345b8f2f24f8ffdac89f3900a27 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 28 Aug 2023 16:33:42 -0400 Subject: [PATCH 1/2] chore: bump to Go 1.21 --- .github/workflows/go.yml | 4 ++-- README.md | 2 +- go.mod | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index bb4edb4..4bd20fb 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -12,10 +12,10 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.x + - name: Set up Go 1.21 uses: actions/setup-go@v2 with: - go-version: ^1.19 + go-version: 1.21 id: go - name: Check out code into the Go module directory diff --git a/README.md b/README.md index 7c2ab5a..5f72a1c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Namespaced Merkle Tree (NMT) -![Go version](https://img.shields.io/badge/go-1.19-blue.svg) +![Go version](https://img.shields.io/badge/go-1.21-blue.svg) [![API Reference](https://camo.githubusercontent.com/915b7be44ada53c290eb157634330494ebe3e30a/68747470733a2f2f676f646f632e6f72672f6769746875622e636f6d2f676f6c616e672f6764646f3f7374617475732e737667)](https://pkg.go.dev/github.com/celestiaorg/nmt) ![golangci-lint](https://github.com/celestiaorg/nmt/workflows/golangci-lint/badge.svg?branch=master) ![Go](https://github.com/celestiaorg/nmt/workflows/Go/badge.svg) diff --git a/go.mod b/go.mod index 54d7bab..e7e72fb 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,16 @@ module github.com/celestiaorg/nmt -go 1.19 +go 1.21 require ( github.com/google/gofuzz v1.2.0 github.com/stretchr/testify v1.8.1 + github.com/tidwall/gjson v1.14.4 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/tidwall/gjson v1.14.4 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect From a0f47dff0012afebdf2c1281d2707631ce511a01 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 28 Aug 2023 16:46:10 -0400 Subject: [PATCH 2/2] fix: lint --- nmt_test.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/nmt_test.go b/nmt_test.go index c4907b5..61da458 100644 --- a/nmt_test.go +++ b/nmt_test.go @@ -3,12 +3,12 @@ package nmt import ( "bytes" "crypto" + "crypto/rand" "crypto/sha256" "encoding/binary" "errors" "fmt" "math" - "math/rand" "reflect" "sort" "sync" @@ -534,7 +534,8 @@ func TestNodeVisitor(t *testing.T) { nodeHashes = append(nodeHashes, hash) } - data := generateRandNamespacedRawData(numLeaves, nidSize, leafSize) + data, err := generateRandNamespacedRawData(numLeaves, nidSize, leafSize) + require.NoError(t, err) n := New(sha256.New(), NamespaceIDSize(nidSize), NodeVisitor(collectNodeHashes)) for j := 0; j < numLeaves; j++ { if err := n.Push(data[j]); err != nil { @@ -706,7 +707,8 @@ func BenchmarkComputeRoot(b *testing.B) { } for _, tt := range tests { - data := generateRandNamespacedRawData(tt.numLeaves, tt.nidSize, tt.dataSize) + data, err := generateRandNamespacedRawData(tt.numLeaves, tt.nidSize, tt.dataSize) + require.NoError(b, err) b.ResetTimer() b.Run(tt.name, func(b *testing.B) { for i := 0; i < b.N; i++ { @@ -786,21 +788,27 @@ func repeat(data []namespaceDataPair, num int) []namespaceDataPair { return res } -func generateRandNamespacedRawData(total int, nidSize int, leafSize int) [][]byte { +func generateRandNamespacedRawData(total int, nidSize int, leafSize int) ([][]byte, error) { data := make([][]byte, total) for i := 0; i < total; i++ { nid := make([]byte, nidSize) - rand.Read(nid) + _, err := rand.Read(nid) + if err != nil { + return nil, err + } data[i] = nid } sortByteArrays(data) for i := 0; i < total; i++ { d := make([]byte, leafSize) - rand.Read(d) + _, err := rand.Read(d) + if err != nil { + return nil, err + } data[i] = append(data[i], d...) } - return data + return data, nil } func sortByteArrays(src [][]byte) {