From 7dac4d3aada3929a50f5c8241c4716ec19d959ce Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 6 Dec 2017 12:44:57 +0100 Subject: [PATCH] crypto: add test cases --- crypto/signature_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crypto/signature_test.go b/crypto/signature_test.go index eaf83c3341..abcab425b5 100644 --- a/crypto/signature_test.go +++ b/crypto/signature_test.go @@ -20,6 +20,7 @@ import ( "bytes" "testing" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" ) @@ -58,6 +59,12 @@ func TestVerifySignature(t *testing.T) { if VerifySignature(testpubkey, testmsg, nil) { t.Errorf("nil signature valid") } + if VerifySignature(testpubkey, testmsg, append(common.CopyBytes(sig), 1, 2, 3)) { + t.Errorf("signature valid with extra bytes at the end") + } + if VerifySignature(testpubkey, testmsg, sig[:len(sig)-2]) { + t.Errorf("signature valid even though it's incomplete") + } } func TestDecompressPubkey(t *testing.T) { @@ -68,6 +75,15 @@ func TestDecompressPubkey(t *testing.T) { if uncompressed := FromECDSAPub(key); !bytes.Equal(uncompressed, testpubkey) { t.Errorf("wrong public key result: got %x, want %x", uncompressed, testpubkey) } + if _, err := DecompressPubkey(nil); err == nil { + t.Errorf("no error for nil pubkey") + } + if _, err := DecompressPubkey(testpubkeyc[:5]); err == nil { + t.Errorf("no error for incomplete pubkey") + } + if _, err := DecompressPubkey(append(common.CopyBytes(testpubkeyc), 1, 2, 3)); err == nil { + t.Errorf("no error for pubkey with extra bytes at the end") + } } func BenchmarkEcrecoverSignature(b *testing.B) {