You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
767 B

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