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.

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