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 h, err := hashFunc.Hash(
29 BigIntToBytes(big.NewInt(1)),
30 BigIntToBytes(big.NewInt(2)))
31 if err != nil {
32 t.Fatal(err)
33 }
34 hBI := BytesToBigInt(h)
35 // value checked with circomlib
36 c := qt.New(t)
37 c.Assert(hBI.String(),
38 qt.Equals,
39 "7853200120776062878684798364095072458815029376092732009249414926327459813530")
40}