forked from TrueCloudLab/tzhash
parent
d5efd8bdce
commit
6b644651fa
4 changed files with 41 additions and 72 deletions
2
go.mod
2
go.mod
|
@ -1,3 +1,3 @@
|
|||
module github.com/nspcc-dev/tzhash
|
||||
|
||||
require github.com/onsi/gomega v1.4.2
|
||||
require github.com/stretchr/testify v1.3.0
|
||||
|
|
34
go.sum
34
go.sum
|
@ -1,26 +1,8 @@
|
|||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
|
||||
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"math/rand"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestHash(t *testing.T) {
|
||||
|
@ -15,14 +15,12 @@ func TestHash(t *testing.T) {
|
|||
err error
|
||||
h, h1, h2 [hashSize]byte
|
||||
b []byte
|
||||
|
||||
g = NewGomegaWithT(t)
|
||||
)
|
||||
|
||||
b = make([]byte, 64)
|
||||
n, err = rand.Read(b)
|
||||
g.Expect(n).To(Equal(64))
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
require.Equal(t, 64, n)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Test if our hashing is really homomorphic
|
||||
h = Sum(b)
|
||||
|
@ -30,13 +28,12 @@ func TestHash(t *testing.T) {
|
|||
h2 = Sum(b[32:])
|
||||
|
||||
err = c1.UnmarshalBinary(h1[:])
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
require.NoError(t, err)
|
||||
err = c2.UnmarshalBinary(h2[:])
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
require.NoError(t, err)
|
||||
|
||||
c1.Mul(&c1, &c2)
|
||||
g.Expect(c1.ByteArray()).To(Equal(h))
|
||||
require.Equal(t, h, c1.ByteArray())
|
||||
}
|
||||
|
||||
var testCases = []struct {
|
||||
|
@ -60,26 +57,24 @@ var testCases = []struct {
|
|||
|
||||
func TestConcat(t *testing.T) {
|
||||
var (
|
||||
got, expected []byte
|
||||
ps [][]byte
|
||||
err error
|
||||
|
||||
g = NewGomegaWithT(t)
|
||||
actual, expect []byte
|
||||
ps [][]byte
|
||||
err error
|
||||
)
|
||||
|
||||
for _, tc := range testCases {
|
||||
expected, err = hex.DecodeString(tc.Hash)
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
expect, err = hex.DecodeString(tc.Hash)
|
||||
require.NoError(t, err)
|
||||
|
||||
ps = make([][]byte, len(tc.Parts))
|
||||
for j := 0; j < len(tc.Parts); j++ {
|
||||
ps[j], err = hex.DecodeString(tc.Parts[j])
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
got, err = Concat(ps)
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
g.Expect(got).To(Equal(expected))
|
||||
actual, err = Concat(ps)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expect, actual)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,21 +86,19 @@ func TestValidate(t *testing.T) {
|
|||
err error
|
||||
)
|
||||
|
||||
g := NewGomegaWithT(t)
|
||||
|
||||
for _, tc := range testCases {
|
||||
hash, _ = hex.DecodeString(tc.Hash)
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
require.NoError(t, err)
|
||||
|
||||
ps = make([][]byte, len(tc.Parts))
|
||||
for j := 0; j < len(tc.Parts); j++ {
|
||||
ps[j], _ = hex.DecodeString(tc.Parts[j])
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
got, err = Validate(hash, ps)
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
g.Expect(got).To(Equal(true))
|
||||
require.NoError(t, err)
|
||||
require.True(t, got)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,26 +121,24 @@ func TestSubtract(t *testing.T) {
|
|||
var (
|
||||
a, b, c, r []byte
|
||||
err error
|
||||
|
||||
g = NewGomegaWithT(t)
|
||||
)
|
||||
|
||||
for _, tc := range testCasesSubtract {
|
||||
a, err = hex.DecodeString(tc.first)
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
require.NoError(t, err)
|
||||
|
||||
b, err = hex.DecodeString(tc.second)
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
require.NoError(t, err)
|
||||
|
||||
c, err = hex.DecodeString(tc.result)
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
require.NoError(t, err)
|
||||
|
||||
r, err = SubtractR(c, b)
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
g.Expect(r).To(Equal(a))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, a, r)
|
||||
|
||||
r, err = SubtractL(c, a)
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
g.Expect(r).To(Equal(b))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, b, r)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/nspcc-dev/tzhash/gf127"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -35,23 +35,19 @@ func TestSL2_MarshalBinary(t *testing.T) {
|
|||
var (
|
||||
a = random()
|
||||
b = new(sl2)
|
||||
g = NewGomegaWithT(t)
|
||||
)
|
||||
|
||||
data, err := a.MarshalBinary()
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
require.NoError(t, err)
|
||||
|
||||
err = b.UnmarshalBinary(data)
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
require.NoError(t, err)
|
||||
|
||||
g.Expect(a).To(Equal(b))
|
||||
require.Equal(t, a, b)
|
||||
}
|
||||
|
||||
func TestInv(t *testing.T) {
|
||||
var (
|
||||
a, b, c *sl2
|
||||
g = NewGomegaWithT(t)
|
||||
)
|
||||
var a, b, c *sl2
|
||||
|
||||
c = new(sl2)
|
||||
for i := 0; i < 5; i++ {
|
||||
|
@ -59,6 +55,6 @@ func TestInv(t *testing.T) {
|
|||
b = Inv(a)
|
||||
c = c.Mul(a, b)
|
||||
|
||||
g.Expect(*c).To(Equal(id))
|
||||
require.Equal(t, id, *c)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue