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.

55 lines
1.1 KiB

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