diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..7f26a2c --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,40 @@ +name: Go Tests + +on: + pull_request: + push: + branches: + - master + +concurrency: + group: ci-${{ github.ref }}-test + cancel-in-progress: true + +jobs: + test: + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + golang: ['1.13.15', '1.25.5'] + + runs-on: ${{ matrix.os }} + env: + DBGSYNCLOG: trace + DBGSYNCON: true + + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v5 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + + - name: Set up Go ${{ matrix.golang }} + uses: actions/setup-go@v6 + with: + go-version: ${{ matrix.golang }} + check-latest: false + + - name: Run tests + run: | + make test diff --git a/.gitignore b/.gitignore index d45bb56..4b514c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -*~ protobuf-fuzz.zip -workdir \ No newline at end of file +workdir +.idea/** diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8a20a91 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +tidy: + go mod tidy + +# Coding style static check. +lint: tidy + # keep this in sync with .github/workflows/golangci-lint.yml + go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.1 + go mod tidy + golangci-lint run + +test: tidy + export GOARCH='amd64' && go test ./... + export GOARCH='386' && go test ./... + +# target to run all the possible checks; it's a good habit to run it before +# pushing code +check: lint test + echo "check done" diff --git a/array_test.go b/array_test.go index d57c62f..9d69115 100644 --- a/array_test.go +++ b/array_test.go @@ -2,6 +2,7 @@ package protobuf import ( "encoding/hex" + "math" "reflect" "testing" @@ -26,7 +27,7 @@ type ArrayTest3 struct { func TestArray(t *testing.T) { // largest int32 is 2147483647 - var large int = 3147483647 + var large int = math.MaxInt32 - 1 a0 := ArrayTest0{[]int{1, 1, large}} a1 := ArrayTest1{[]int64{1, 1, 1}} diff --git a/encoding_test.go b/encoding_test.go index a65b2e4..4dcf1c0 100644 --- a/encoding_test.go +++ b/encoding_test.go @@ -227,7 +227,7 @@ func TestArrayKey(t *testing.T) { assert.False(t, t1.M[k3]) } -func TestInterface(t *testing.T) { +func TestPointInterface(t *testing.T) { type Points struct { P1 kyber.Point P2 kyber.Point @@ -254,6 +254,35 @@ func TestInterface(t *testing.T) { require.Equal(t, pp.P2.String(), dpp.P2.String()) } +func TestScalarInterface(t *testing.T) { + ed25519 := suites.MustFind("ed25519") + + RegisterInterface(func() interface{} { return ed25519.Scalar() }) + // RegisterInterface(func() interface{} { return ed25519.ScalarLen() }) + + type BasicSig struct { + C kyber.Scalar + R kyber.Scalar + } + + pseudoRand := ed25519.XOF([]byte("test scalar interface")) + + sig := BasicSig{ + C: ed25519.Scalar().Pick(pseudoRand), + R: ed25519.Scalar().Pick(pseudoRand), + } + + buf, err := Encode(&sig) + require.NoError(t, err) + + var dsig BasicSig + err = Decode(buf, &dsig) + require.NoError(t, err) + + require.Equal(t, sig.C.String(), dsig.C.String()) + require.Equal(t, sig.R.String(), dsig.R.String()) +} + type dummyInterface interface { String() string encoding.BinaryUnmarshaler diff --git a/go.sum b/go.sum index ccb5242..d283601 100644 --- a/go.sum +++ b/go.sum @@ -7,7 +7,6 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs= go.dedis.ch/fixbuf v1.0.3/go.mod h1:yzJMt34Wa5xD37V5RTdmp38cz3QhMagdGoem9anUalw= -go.dedis.ch/kyber/v3 v3.0.4 h1:FDuC/S3STkvwxZ0ooo3gcp56QkUKsN7Jy7cpzBxL+vQ= go.dedis.ch/kyber/v3 v3.0.4/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ= go.dedis.ch/kyber/v3 v3.0.9 h1:i0ZbOQocHUjfFasBiUql5zVeC7u/vahFd96DFA8UOWk= go.dedis.ch/kyber/v3 v3.0.9/go.mod h1:rhNjUUg6ahf8HEg5HUvVBYoWY4boAafX8tYxX+PS+qg=