Skip to content

Commit bf1cd57

Browse files
committed
Added a test case and error case
1 parent 868b8f2 commit bf1cd57

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

private_key.go

+4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ package bitcoin
33
import (
44
"crypto/ecdsa"
55
"encoding/hex"
6+
"errors"
67
"math/big"
78

89
"github.com/bitcoinsv/bsvd/bsvec"
910
)
1011

1112
// PrivateKeyFromString turns a private key (hex encoded string) into an bsvec.PrivateKey
1213
func PrivateKeyFromString(privateKey string) (*bsvec.PrivateKey, error) {
14+
if len(privateKey) == 0 {
15+
return nil, errors.New("privateKey is missing")
16+
}
1317
privateKeyBytes, err := hex.DecodeString(privateKey)
1418
if err != nil {
1519
return nil, err

private_key_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func TestPrivateKeyFromString(t *testing.T) {
8989
{"E83385AF76B2B1997326B567461FB73DD9C27EAB9E1E86D26779F", "", true, true},
9090
{"1234567", "", true, true},
9191
{"0", "", true, true},
92+
{"", "", true, true},
9293
}
9394

9495
// Run tests

0 commit comments

Comments
 (0)