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.

91 lines
1.9 KiB

  1. package poseidon
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. const prime uint64 = 18446744069414584321
  7. func TestPoseidonHash(t *testing.T) {
  8. b0 := uint64(0)
  9. b1 := uint64(1)
  10. bm1 := prime - 1
  11. bM := prime
  12. h, err := Hash([NROUNDSF]uint64{b0, b0, b0, b0, b0, b0, b0, b0}, [CAPLEN]uint64{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([NROUNDSF]uint64{b1, b1, b1, b1, b1, b1, b1, b1}, [CAPLEN]uint64{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([NROUNDSF]uint64{b1, b1, b1, b1, b1, b1, b1, b1}, [CAPLEN]uint64{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([NROUNDSF]uint64{bm1, bm1, bm1, bm1, bm1, bm1, bm1, bm1}, [CAPLEN]uint64{bm1, bm1, bm1, bm1})
  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([NROUNDSF]uint64{bM, bM, bM, bM, bM, bM, bM, bM}, [CAPLEN]uint64{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([NROUNDSF]uint64{
  63. uint64(923978),
  64. uint64(235763497586),
  65. uint64(9827635653498),
  66. uint64(112870),
  67. uint64(289273673480943876),
  68. uint64(230295874986745876),
  69. uint64(6254867324987),
  70. uint64(2087),
  71. }, [CAPLEN]uint64{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. }