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.

31 lines
720 B

  1. package sr25519_test
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. "github.com/tendermint/tendermint/crypto"
  7. "github.com/tendermint/tendermint/crypto/sr25519"
  8. )
  9. func TestSignAndValidateSr25519(t *testing.T) {
  10. privKey := sr25519.GenPrivKey()
  11. pubKey := privKey.PubKey()
  12. msg := crypto.CRandBytes(128)
  13. sig, err := privKey.Sign(msg)
  14. require.Nil(t, err)
  15. // Test the signature
  16. assert.True(t, pubKey.VerifyBytes(msg, sig))
  17. assert.True(t, pubKey.VerifyBytes(msg, sig))
  18. // Mutate the signature, just one bit.
  19. // TODO: Replace this with a much better fuzzer, tendermint/ed25519/issues/10
  20. sig[7] ^= byte(0x01)
  21. assert.False(t, pubKey.VerifyBytes(msg, sig))
  22. }