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.

90 lines
2.0 KiB

  1. package poseidon
  2. import (
  3. "math/big"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestPoseidonHash(t *testing.T) {
  8. b0 := big.NewInt(0)
  9. b1 := big.NewInt(1)
  10. b_1 := big.NewInt(-1)
  11. bM := new(big.Int).SetUint64(18446744069414584321)
  12. h, err := Hash([]*big.Int{b0, b0, b0, b0, b0, b0, b0, b0}, []*big.Int{b0, b0, b0, b0})
  13. assert.Nil(t, err)
  14. assert.Equal(t,
  15. [CAPLEN]uint64{
  16. 4330397376401421145,
  17. 14124799381142128323,
  18. 8742572140681234676,
  19. 14345658006221440202,
  20. }, h,
  21. )
  22. h, err = Hash([]*big.Int{b1, b1, b1, b1, b1, b1, b1, b1}, []*big.Int{b1, b1, b1, b1})
  23. assert.Nil(t, err)
  24. assert.Equal(t,
  25. [CAPLEN]uint64{
  26. 16428316519797902711,
  27. 13351830238340666928,
  28. 682362844289978626,
  29. 12150588177266359240,
  30. }, h,
  31. )
  32. h, err = Hash([]*big.Int{b1, b1, b1, b1, b1, b1, b1, b1}, []*big.Int{b1, b1, b1, b1})
  33. assert.Nil(t, err)
  34. assert.Equal(t,
  35. [CAPLEN]uint64{
  36. 16428316519797902711,
  37. 13351830238340666928,
  38. 682362844289978626,
  39. 12150588177266359240,
  40. }, h,
  41. )
  42. h, err = Hash([]*big.Int{b_1, b_1, b_1, b_1, b_1, b_1, b_1, b_1}, []*big.Int{b_1, b_1, b_1, b_1})
  43. assert.Nil(t, err)
  44. assert.Equal(t,
  45. [CAPLEN]uint64{
  46. 13691089994624172887,
  47. 15662102337790434313,
  48. 14940024623104903507,
  49. 10772674582659927682,
  50. }, h,
  51. )
  52. h, err = Hash([]*big.Int{bM, bM, bM, bM, bM, bM, bM, bM}, []*big.Int{b0, b0, b0, b0})
  53. assert.Nil(t, err)
  54. assert.Equal(t,
  55. [CAPLEN]uint64{
  56. 4330397376401421145,
  57. 14124799381142128323,
  58. 8742572140681234676,
  59. 14345658006221440202,
  60. }, h,
  61. )
  62. h, err = Hash([]*big.Int{
  63. new(big.Int).SetUint64(923978),
  64. new(big.Int).SetUint64(235763497586),
  65. new(big.Int).SetUint64(9827635653498),
  66. new(big.Int).SetUint64(112870),
  67. new(big.Int).SetUint64(289273673480943876),
  68. new(big.Int).SetUint64(230295874986745876),
  69. new(big.Int).SetUint64(6254867324987),
  70. new(big.Int).SetUint64(2087),
  71. }, []*big.Int{b0, b0, b0, b0})
  72. assert.Nil(t, err)
  73. assert.Equal(t,
  74. [CAPLEN]uint64{
  75. 1892171027578617759,
  76. 984732815927439256,
  77. 7866041765487844082,
  78. 8161503938059336191,
  79. }, h,
  80. )
  81. }