go-iden3-crypto/poseidon/poseidon_test.go
poseidon/poseidon_test.goRaw
1package poseidon
2
3import (
4 "encoding/hex"
5 "math/big"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9 "golang.org/x/crypto/blake2b"
10)
11
12func TestBlake2bVersion(t *testing.T) {
13 h := blake2b.Sum256([]byte("poseidon_constants"))
14 assert.Equal(t, "e57ba154fb2c47811dc1a2369b27e25a44915b4e4ece4eb8ec74850cb78e01b1", hex.EncodeToString(h[:]))
15}
16
17func TestPoseidon(t *testing.T) {
18 b1 := big.NewInt(int64(1))
19 b2 := big.NewInt(int64(2))
20 h, err := Hash([]*big.Int{b1, b2})
21 assert.Nil(t, err)
22 assert.Equal(t, "12242166908188651009877250812424843524687801523336557272219921456462821518061", h.String())
23
24 b3 := big.NewInt(int64(3))
25 b4 := big.NewInt(int64(4))
26 h, err = Hash([]*big.Int{b3, b4})
27 assert.Nil(t, err)
28 assert.Equal(t, "17185195740979599334254027721507328033796809509313949281114643312710535000993", h.String())
29}