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.

40 lines
978 B

  1. // +build libsecp256k1
  2. package secp256k1
  3. import (
  4. "testing"
  5. "github.com/magiconair/properties/assert"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestPrivKeySecp256k1SignVerify(t *testing.T) {
  9. msg := []byte("A.1.2 ECC Key Pair Generation by Testing Candidates")
  10. priv := GenPrivKey()
  11. tests := []struct {
  12. name string
  13. privKey PrivKey
  14. wantSignErr bool
  15. wantVerifyPasses bool
  16. }{
  17. {name: "valid sign-verify round", privKey: priv, wantSignErr: false, wantVerifyPasses: true},
  18. {name: "invalid private key", privKey: [32]byte{}, wantSignErr: true, wantVerifyPasses: false},
  19. }
  20. for _, tt := range tests {
  21. t.Run(tt.name, func(t *testing.T) {
  22. got, err := tt.privKey.Sign(msg)
  23. if tt.wantSignErr {
  24. require.Error(t, err)
  25. t.Logf("Got error: %s", err)
  26. return
  27. }
  28. require.NoError(t, err)
  29. require.NotNil(t, got)
  30. pub := tt.privKey.PubKey()
  31. assert.Equal(t, tt.wantVerifyPasses, pub.VerifyBytes(msg, got))
  32. })
  33. }
  34. }