add signature test harness and try a valid signature for size.

error paths to come.
This commit is contained in:
Owain G. Ainsworth 2013-06-14 01:11:06 +01:00
parent 7cfebed976
commit 9cb1f47fb9
2 changed files with 53 additions and 2 deletions

51
signature_test.go Normal file
View file

@ -0,0 +1,51 @@
// Copyright (c) 2013 Conformal Systems LLC.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package btcec_test
import (
"github.com/conformal/btcec"
"testing"
)
type signatureTest struct {
name string
sig []byte
isValid bool
}
var signatureTests = []signatureTest{
// signatures from bitcoin blockchain tx
// 0437cd7f8525ceed2324359c2d0ba26006d92d85
signatureTest{
name: "valid signature.",
sig: []byte{0x30, 0x44, 0x02, 0x20, 0x4e, 0x45, 0xe1, 0x69,
0x32, 0xb8, 0xaf, 0x51, 0x49, 0x61, 0xa1, 0xd3, 0xa1,
0xa2, 0x5f, 0xdf, 0x3f, 0x4f, 0x77, 0x32, 0xe9, 0xd6,
0x24, 0xc6, 0xc6, 0x15, 0x48, 0xab, 0x5f, 0xb8, 0xcd,
0x41, 0x02, 0x20, 0x18, 0x15, 0x22, 0xec, 0x8e, 0xca,
0x07, 0xde, 0x48, 0x60, 0xa4, 0xac, 0xdd, 0x12, 0x90,
0x9d, 0x83, 0x1c, 0xc5, 0x6c, 0xbb, 0xac, 0x46, 0x22,
0x08, 0x22, 0x21, 0xa8, 0x76, 0x8d, 0x1d, 0x09, 0x01,
},
isValid: true,
},
}
func TestSignatures(t *testing.T) {
for _, test := range signatureTests {
_, err := btcec.ParseSignature(test.sig, btcec.S256())
if err != nil {
if test.isValid {
t.Errorf("%s signature failed when shouldn't %v",
test.name, err)
}
continue
}
if !test.isValid {
t.Errorf("%s counted as valid when it should fail",
test.name)
}
}
}

View file

@ -14,7 +14,7 @@ github.com/conformal/btcec/pubkey.go isOdd 100.00% (1/1)
github.com/conformal/btcec/pubkey.go ParsePubKey 96.88% (31/32)
github.com/conformal/btcec/btcec.go KoblitzCurve.addJacobian 91.67% (55/60)
github.com/conformal/btcec/btcec.go KoblitzCurve.affineFromJacobian 90.00% (9/10)
github.com/conformal/btcec/signature.go ParseSignature 0.00% (0/41)
github.com/conformal/btcec/signature.go ParseSignature 70.73% (29/41)
github.com/conformal/btcec/btcec.go KoblitzCurve.Double 0.00% (0/2)
github.com/conformal/btcec ------------------------------- 75.61% (155/205)
github.com/conformal/btcec ------------------------------- 89.76% (184/205)