arnaucube
arnaucube/arboPublic Self-hosted repository
arbo/hash_test.go
hash_test.goRaw
 1package arbo
 2
 3import (
 4	"encoding/hex"
 5	"math/big"
 6	"testing"
 7
 8	"github.com/stretchr/testify/assert"
 9)
10
11func TestHashSha256(t *testing.T) {
12	// Sha256 hash
13	hashFunc := &HashSha256{}
14	b := []byte("test")
15	h, err := hashFunc.Hash(b)
16	if err != nil {
17		t.Fatal(err)
18	}
19	assert.Equal(t,
20		"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
21		hex.EncodeToString(h))
22}
23
24func TestHashPoseidon(t *testing.T) {
25	// Poseidon hash
26	hashFunc := &HashPoseidon{}
27	h, err := hashFunc.Hash(
28		BigIntToBytes(big.NewInt(1)),
29		BigIntToBytes(big.NewInt(2)))
30	if err != nil {
31		t.Fatal(err)
32	}
33	hBI := BytesToBigInt(h)
34	// value checked with circomlib
35	assert.Equal(t,
36		"7853200120776062878684798364095072458815029376092732009249414926327459813530",
37		hBI.String())
38}