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.

60 lines
1.2 KiB

  1. package crypto_test
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/tendermint/tendermint/crypto"
  6. )
  7. func TestGeneratePrivKey(t *testing.T) {
  8. testPriv := crypto.GenPrivKeyEd25519()
  9. testGenerate := testPriv.Generate(1)
  10. signBytes := []byte("something to sign")
  11. pub := testGenerate.PubKey()
  12. sig, err := testGenerate.Sign(signBytes)
  13. assert.NoError(t, err)
  14. assert.True(t, pub.VerifyBytes(signBytes, sig))
  15. }
  16. /*
  17. type BadKey struct {
  18. PrivKeyEd25519
  19. }
  20. func TestReadPrivKey(t *testing.T) {
  21. assert, require := assert.New(t), require.New(t)
  22. // garbage in, garbage out
  23. garbage := []byte("hjgewugfbiewgofwgewr")
  24. XXX This test wants to register BadKey globally to crypto,
  25. but we don't want to support that.
  26. _, err := PrivKeyFromBytes(garbage)
  27. require.Error(err)
  28. edKey := GenPrivKeyEd25519()
  29. badKey := BadKey{edKey}
  30. cases := []struct {
  31. key PrivKey
  32. valid bool
  33. }{
  34. {edKey, true},
  35. {badKey, false},
  36. }
  37. for i, tc := range cases {
  38. data := tc.key.Bytes()
  39. fmt.Println(">>>", data)
  40. key, err := PrivKeyFromBytes(data)
  41. fmt.Printf("!!! %#v\n", key, err)
  42. if tc.valid {
  43. assert.NoError(err, "%d", i)
  44. assert.Equal(tc.key, key, "%d", i)
  45. } else {
  46. assert.Error(err, "%d: %#v", i, key)
  47. }
  48. }
  49. }
  50. */