From 10c1b945940074ff7bb2440369568376a9400ba7 Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Thu, 3 Feb 2022 09:35:13 -0500 Subject: [PATCH] Added more test cases, minor cleanup --- address_test.go | 4 ++++ hd_key.go | 8 ++++---- hd_key_test.go | 2 +- transaction.go | 1 + 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/address_test.go b/address_test.go index fa31ce8..6264fc4 100644 --- a/address_test.go +++ b/address_test.go @@ -109,6 +109,10 @@ func TestGetAddressFromPrivateKeyCompression(t *testing.T) { assert.NoError(t, err) assert.NotEqual(t, addressCompressed, addressUncompressed) + + addressCompressed, err = GetAddressFromPrivateKey(&bec.PrivateKey{}, true) + assert.Error(t, err) + assert.Equal(t, "", addressCompressed) } // ExampleGetAddressFromPrivateKey example using GetAddressFromPrivateKey() diff --git a/hd_key.go b/hd_key.go index 2cc8978..10371e3 100644 --- a/hd_key.go +++ b/hd_key.go @@ -25,7 +25,7 @@ const ( DefaultInternalChain = 1 ) -// GenerateHDKey will create a new master node for use in creating a hierarchical deterministic key chain +// GenerateHDKey will create a new master node for use in creating a hierarchical deterministic keychain func GenerateHDKey(seedLength uint8) (hdKey *bip32.ExtendedKey, err error) { // Missing or invalid seed length @@ -44,7 +44,7 @@ func GenerateHDKey(seedLength uint8) (hdKey *bip32.ExtendedKey, err error) { } // GenerateHDKeyFromString will create a new master node for use in creating a -// hierarchical deterministic key chain from an xPrivKey string +// hierarchical deterministic keychain from an xPrivKey string func GenerateHDKeyFromString(xPriv string) (hdKey *bip32.ExtendedKey, err error) { return bip32.NewKeyFromString(xPriv) } @@ -164,7 +164,7 @@ func GetPublicKeysForPath(hdKey *bip32.ExtendedKey, num uint32) (pubKeys []*bec. return } - // Get the external pubkey from m/0/x + // Get the external pubKey from m/0/x var pubKey *bec.PublicKey if pubKey, err = childM0x.ECPubKey(); err != nil { // Should never error since the previous method ensures a valid hdKey @@ -179,7 +179,7 @@ func GetPublicKeysForPath(hdKey *bip32.ExtendedKey, num uint32) (pubKeys []*bec. return } - // Get the internal pubkey from m/1/x + // Get the internal pubKey from m/1/x if pubKey, err = childM1x.ECPubKey(); err != nil { // Should never error since the previous method ensures a valid hdKey return diff --git a/hd_key_test.go b/hd_key_test.go index c72c51a..b651941 100644 --- a/hd_key_test.go +++ b/hd_key_test.go @@ -358,7 +358,7 @@ func TestGetHDKeyChild(t *testing.T) { expectedNil bool expectedError bool }{ - //{nil, 0, true, true}, + // {nil, 0, true, true}, {validKey, 0, false, false}, {validKey, 10, false, false}, {validKey, 100, false, false}, diff --git a/transaction.go b/transaction.go index d3973bb..2602cad 100644 --- a/transaction.go +++ b/transaction.go @@ -260,6 +260,7 @@ func CreateTx(utxos []*Utxo, addresses []*PayToAddress, // Sign the transaction if privateKey != nil { myAccount := &account{PrivateKey: privateKey} + // todo: support context (ctx) if err = tx.FillAllInputs(context.Background(), myAccount); err != nil { return nil, err }