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.

39 lines
751 B

  1. package common
  2. import (
  3. "math/big"
  4. "testing"
  5. "github.com/iden3/go-iden3-crypto/babyjub"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestBJJCompressedTo256BigInt(t *testing.T) {
  9. var pkComp babyjub.PublicKeyComp
  10. r := BJJCompressedTo256BigInts(pkComp)
  11. zero := big.NewInt(0)
  12. for i := 0; i < 256; i++ {
  13. assert.Equal(t, zero, r[i])
  14. }
  15. pkComp[0] = 3
  16. r = BJJCompressedTo256BigInts(pkComp)
  17. one := big.NewInt(1)
  18. for i := 0; i < 256; i++ {
  19. if i != 0 && i != 1 {
  20. assert.Equal(t, zero, r[i])
  21. } else {
  22. assert.Equal(t, one, r[i])
  23. }
  24. }
  25. pkComp[31] = 4
  26. r = BJJCompressedTo256BigInts(pkComp)
  27. for i := 0; i < 256; i++ {
  28. if i != 0 && i != 1 && i != 250 {
  29. assert.Equal(t, zero, r[i])
  30. } else {
  31. assert.Equal(t, one, r[i])
  32. }
  33. }
  34. }