From bf1cd5734e3d69e85a1788a7c8e42cfbd863fe71 Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Wed, 30 Sep 2020 19:23:19 -0400 Subject: [PATCH] Added a test case and error case --- private_key.go | 4 ++++ private_key_test.go | 1 + 2 files changed, 5 insertions(+) diff --git a/private_key.go b/private_key.go index 607024b..e049104 100644 --- a/private_key.go +++ b/private_key.go @@ -3,6 +3,7 @@ package bitcoin import ( "crypto/ecdsa" "encoding/hex" + "errors" "math/big" "github.com/bitcoinsv/bsvd/bsvec" @@ -10,6 +11,9 @@ import ( // PrivateKeyFromString turns a private key (hex encoded string) into an bsvec.PrivateKey func PrivateKeyFromString(privateKey string) (*bsvec.PrivateKey, error) { + if len(privateKey) == 0 { + return nil, errors.New("privateKey is missing") + } privateKeyBytes, err := hex.DecodeString(privateKey) if err != nil { return nil, err diff --git a/private_key_test.go b/private_key_test.go index 7eb4100..1286ca5 100644 --- a/private_key_test.go +++ b/private_key_test.go @@ -89,6 +89,7 @@ func TestPrivateKeyFromString(t *testing.T) { {"E83385AF76B2B1997326B567461FB73DD9C27EAB9E1E86D26779F", "", true, true}, {"1234567", "", true, true}, {"0", "", true, true}, + {"", "", true, true}, } // Run tests