tendermint/account/signature_test.go

30 lines
654 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()
2014-12-17 01:37:13 -08:00
pubKey := privAccount.PubKey
privKey := privAccount.PrivKey
2014-10-03 17:59:54 -07:00
2014-10-04 19:16:49 -07:00
msg := CRandBytes(128)
2014-12-17 01:37:13 -08:00
sig := privKey.Sign(msg)
2014-10-03 17:59:54 -07:00
t.Logf("msg: %X, sig: %X", msg, sig)
// Test the signature
2014-12-17 01:37:13 -08:00
if !pubKey.VerifyBytes(msg, sig) {
2014-10-03 17:59:54 -07:00
t.Errorf("Account message signature verification failed")
}
// Mutate the signature, just one bit.
2014-12-17 01:37:13 -08:00
sig.(SignatureEd25519).Bytes[0] ^= byte(0x01)
2014-10-03 17:59:54 -07:00
2014-12-17 01:37:13 -08:00
if pubKey.VerifyBytes(msg, sig) {
2014-10-03 17:59:54 -07:00
t.Errorf("Account message signature verification should have failed but passed instead")
}
}