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.

29 lines
654 B

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. package account
  2. import (
  3. . "github.com/tendermint/tendermint/common"
  4. "testing"
  5. )
  6. func TestSignAndValidate(t *testing.T) {
  7. privAccount := GenPrivAccount()
  8. pubKey := privAccount.PubKey
  9. privKey := privAccount.PrivKey
  10. msg := CRandBytes(128)
  11. sig := privKey.Sign(msg)
  12. t.Logf("msg: %X, sig: %X", msg, sig)
  13. // Test the signature
  14. if !pubKey.VerifyBytes(msg, sig) {
  15. t.Errorf("Account message signature verification failed")
  16. }
  17. // Mutate the signature, just one bit.
  18. sig.(SignatureEd25519).Bytes[0] ^= byte(0x01)
  19. if pubKey.VerifyBytes(msg, sig) {
  20. t.Errorf("Account message signature verification should have failed but passed instead")
  21. }
  22. }