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	qt "github.com/frankban/quicktest"
 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	c := qt.New(t)
20	c.Assert(hex.EncodeToString(h),
21		qt.Equals,
22		"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")
23}
24
25func TestHashPoseidon(t *testing.T) {
26	// Poseidon hash
27	hashFunc := &HashPoseidon{}
28	bLen := hashFunc.Len()
29	h, err := hashFunc.Hash(
30		BigIntToBytes(bLen, big.NewInt(1)),
31		BigIntToBytes(bLen, big.NewInt(2)))
32	if err != nil {
33		t.Fatal(err)
34	}
35	hBI := BytesToBigInt(h)
36	// value checked with circomlib
37	c := qt.New(t)
38	c.Assert(hBI.String(),
39		qt.Equals,
40		"7853200120776062878684798364095072458815029376092732009249414926327459813530")
41}
42
43func TestHashBlake2b(t *testing.T) {
44	// Blake2b hash
45	hashFunc := &HashBlake2b{}
46	b := []byte("test")
47	h, err := hashFunc.Hash(b)
48	if err != nil {
49		t.Fatal(err)
50	}
51	c := qt.New(t)
52	c.Assert(hex.EncodeToString(h),
53		qt.Equals,
54		"928b20366943e2afd11ebc0eae2e53a93bf177a4fcf35bcc64d503704e65e202")
55}