Add tests for pad function.
This brings the overall test coverage up to 99.88%.
This commit is contained in:
parent
8f8eeae962
commit
cc712827da
3 changed files with 83 additions and 10 deletions
|
@ -30,6 +30,11 @@ func (f *fieldVal) TstSetRawInts(raw [10]uint32) *fieldVal {
|
|||
return f
|
||||
}
|
||||
|
||||
// TstPad makes the internal pad function available to the test package.
|
||||
func TstPad(size int, b []byte) []byte {
|
||||
return pad(size, b)
|
||||
}
|
||||
|
||||
// TstFieldJacobianToBigAffine makes the internal fieldJacobianToBigAffine
|
||||
// function available to the test package.
|
||||
func (curve *KoblitzCurve) TstFieldJacobianToBigAffine(x, y, z *fieldVal) (*big.Int, *big.Int) {
|
||||
|
|
|
@ -266,3 +266,71 @@ func TestPubKeys(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPad(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string // Short name to describe the test.
|
||||
inSize int // The size to pad to.
|
||||
inBytes []byte // The input bytes to pad.
|
||||
expected []byte // The expected padded result.
|
||||
}{
|
||||
{
|
||||
name: "same size - no padding needed",
|
||||
inSize: 32,
|
||||
inBytes: []byte{
|
||||
0xce, 0x0b, 0x14, 0xfb, 0x84, 0x2b, 0x1b, 0xa5,
|
||||
0x49, 0xfd, 0xd6, 0x75, 0xc9, 0x80, 0x75, 0xf1,
|
||||
0x2e, 0x9c, 0x51, 0x0f, 0x8e, 0xf5, 0x2b, 0xd0,
|
||||
0x21, 0xa9, 0xa1, 0xf4, 0x80, 0x9d, 0x3b, 0x4d,
|
||||
},
|
||||
expected: []byte{
|
||||
0xce, 0x0b, 0x14, 0xfb, 0x84, 0x2b, 0x1b, 0xa5,
|
||||
0x49, 0xfd, 0xd6, 0x75, 0xc9, 0x80, 0x75, 0xf1,
|
||||
0x2e, 0x9c, 0x51, 0x0f, 0x8e, 0xf5, 0x2b, 0xd0,
|
||||
0x21, 0xa9, 0xa1, 0xf4, 0x80, 0x9d, 0x3b, 0x4d,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "short 1 byte",
|
||||
inSize: 32,
|
||||
inBytes: []byte{
|
||||
0x0b, 0x14, 0xfb, 0x84, 0x2b, 0x1b, 0xa5,
|
||||
0x49, 0xfd, 0xd6, 0x75, 0xc9, 0x80, 0x75, 0xf1,
|
||||
0x2e, 0x9c, 0x51, 0x0f, 0x8e, 0xf5, 0x2b, 0xd0,
|
||||
0x21, 0xa9, 0xa1, 0xf4, 0x80, 0x9d, 0x3b, 0x4d,
|
||||
},
|
||||
expected: []byte{
|
||||
0x00, 0x0b, 0x14, 0xfb, 0x84, 0x2b, 0x1b, 0xa5,
|
||||
0x49, 0xfd, 0xd6, 0x75, 0xc9, 0x80, 0x75, 0xf1,
|
||||
0x2e, 0x9c, 0x51, 0x0f, 0x8e, 0xf5, 0x2b, 0xd0,
|
||||
0x21, 0xa9, 0xa1, 0xf4, 0x80, 0x9d, 0x3b, 0x4d,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "more bytes than pad size",
|
||||
inSize: 31,
|
||||
inBytes: []byte{
|
||||
0xce, 0x0b, 0x14, 0xfb, 0x84, 0x2b, 0x1b, 0xa5,
|
||||
0x49, 0xfd, 0xd6, 0x75, 0xc9, 0x80, 0x75, 0xf1,
|
||||
0x2e, 0x9c, 0x51, 0x0f, 0x8e, 0xf5, 0x2b, 0xd0,
|
||||
0x21, 0xa9, 0xa1, 0xf4, 0x80, 0x9d, 0x3b, 0x4d,
|
||||
},
|
||||
expected: []byte{
|
||||
0xce, 0x0b, 0x14, 0xfb, 0x84, 0x2b, 0x1b, 0xa5,
|
||||
0x49, 0xfd, 0xd6, 0x75, 0xc9, 0x80, 0x75, 0xf1,
|
||||
0x2e, 0x9c, 0x51, 0x0f, 0x8e, 0xf5, 0x2b, 0xd0,
|
||||
0x21, 0xa9, 0xa1, 0xf4, 0x80, 0x9d, 0x3b, 0x4d,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
t.Logf("Running %d tests.", len(tests))
|
||||
for i, test := range tests {
|
||||
result := btcec.TstPad(test.inSize, test.inBytes)
|
||||
if !bytes.Equal(result, test.expected) {
|
||||
t.Errorf("pad #%d (%s) unexpected result:\n"+
|
||||
"got: %x\nwant: %x", i, test.name, result,
|
||||
test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,39 +21,39 @@ github.com/conformal/btcec/field.go fieldVal.NegateVal 100.00% (11/11)
|
|||
github.com/conformal/btcec/field.go fieldVal.SetBytes 100.00% (11/11)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.ScalarMult 100.00% (10/10)
|
||||
github.com/conformal/btcec/field.go fieldVal.Zero 100.00% (10/10)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.doubleJacobian 100.00% (9/9)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.Add 100.00% (9/9)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.doubleJacobian 100.00% (9/9)
|
||||
github.com/conformal/btcec/btcec.go initS256 100.00% (8/8)
|
||||
github.com/conformal/btcec/signature.go canonicalizeInt 100.00% (8/8)
|
||||
github.com/conformal/btcec/pubkey.go PublicKey.SerializeHybrid 100.00% (8/8)
|
||||
github.com/conformal/btcec/pubkey.go PublicKey.SerializeCompressed 100.00% (7/7)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.Double 100.00% (6/6)
|
||||
github.com/conformal/btcec/pubkey.go pad 100.00% (5/5)
|
||||
github.com/conformal/btcec/field.go fieldVal.SetByteSlice 100.00% (5/5)
|
||||
github.com/conformal/btcec/pubkey.go PublicKey.SerializeUncompressed 100.00% (5/5)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.bigAffineToField 100.00% (4/4)
|
||||
github.com/conformal/btcec/field.go fieldVal.SetHex 100.00% (4/4)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.IsOnCurve 100.00% (4/4)
|
||||
github.com/conformal/btcec/signature.go canonicalPadding 100.00% (4/4)
|
||||
github.com/conformal/btcec/field.go fieldVal.SetHex 100.00% (4/4)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.bigAffineToField 100.00% (4/4)
|
||||
github.com/conformal/btcec/field.go fieldVal.SetInt 100.00% (3/3)
|
||||
github.com/conformal/btcec/field.go fieldVal.Bytes 100.00% (3/3)
|
||||
github.com/conformal/btcec/field.go fieldVal.SetInt 100.00% (3/3)
|
||||
github.com/conformal/btcec/field.go fieldVal.String 100.00% (2/2)
|
||||
github.com/conformal/btcec/field.go fieldVal.Set 100.00% (2/2)
|
||||
github.com/conformal/btcec/btcec.go S256 100.00% (2/2)
|
||||
github.com/conformal/btcec/field.go fieldVal.IsZero 100.00% (2/2)
|
||||
github.com/conformal/btcec/field.go fieldVal.Equals 100.00% (2/2)
|
||||
github.com/conformal/btcec/field.go fieldVal.AddInt 100.00% (2/2)
|
||||
github.com/conformal/btcec/field.go fieldVal.Mul 100.00% (1/1)
|
||||
github.com/conformal/btcec/pubkey.go isOdd 100.00% (1/1)
|
||||
github.com/conformal/btcec/signature.go ParseDERSignature 100.00% (1/1)
|
||||
github.com/conformal/btcec/field.go fieldVal.IsOdd 100.00% (1/1)
|
||||
github.com/conformal/btcec/field.go fieldVal.Mul 100.00% (1/1)
|
||||
github.com/conformal/btcec/field.go fieldVal.Square 100.00% (1/1)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.Params 100.00% (1/1)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.ScalarBaseMult 100.00% (1/1)
|
||||
github.com/conformal/btcec/btcec.go KoblitzCurve.QPlus1Div4 100.00% (1/1)
|
||||
github.com/conformal/btcec/field.go fieldVal.Square 100.00% (1/1)
|
||||
github.com/conformal/btcec/field.go fieldVal.Negate 100.00% (1/1)
|
||||
github.com/conformal/btcec/btcec.go initAll 100.00% (1/1)
|
||||
github.com/conformal/btcec/signature.go ParseSignature 100.00% (1/1)
|
||||
github.com/conformal/btcec/signature.go ParseDERSignature 100.00% (1/1)
|
||||
github.com/conformal/btcec/field.go fieldVal.IsOdd 100.00% (1/1)
|
||||
github.com/conformal/btcec/pubkey.go ParsePubKey 96.88% (31/32)
|
||||
github.com/conformal/btcec/pubkey.go pad 80.00% (4/5)
|
||||
github.com/conformal/btcec ------------------------------------- 99.76% (843/845)
|
||||
github.com/conformal/btcec ------------------------------------- 99.88% (844/845)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue