tendermint/account/signature_test.go

29 lines
617 B
Go
Raw Normal View History

package account
2014-10-03 17:59:54 -07:00
import (
. "github.com/tendermint/tendermint/common"
"testing"
)
func TestSignAndValidate(t *testing.T) {
privAccount := GenPrivAccount()
account := &privAccount.Account
2014-10-04 19:16:49 -07:00
msg := CRandBytes(128)
2014-10-07 23:11:04 -07:00
sig := privAccount.SignBytes(msg)
2014-10-03 17:59:54 -07:00
t.Logf("msg: %X, sig: %X", msg, sig)
// Test the signature
2014-10-11 21:27:58 -07:00
if !account.VerifyBytes(msg, sig) {
2014-10-03 17:59:54 -07:00
t.Errorf("Account message signature verification failed")
}
// Mutate the signature, just one bit.
sig.Bytes[0] ^= byte(0x01)
2014-10-11 21:27:58 -07:00
if account.VerifyBytes(msg, sig) {
2014-10-03 17:59:54 -07:00
t.Errorf("Account message signature verification should have failed but passed instead")
}
}