From 158f8d6b7be7e021a40eda18b152565adf88cb3c Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Wed, 11 Nov 2020 09:34:35 -0500 Subject: [PATCH] Fixed tests, fixed method GetAddressFromPrivateKey --- address.go | 7 +- address_test.go | 55 ++++++++------- encryption_test.go | 30 ++++----- hd_key_test.go | 160 ++++++++++++++++++++++---------------------- private_key_test.go | 58 ++++++++-------- pubkey_test.go | 20 +++--- script_test.go | 6 +- sign_test.go | 6 +- transaction_test.go | 36 +++++----- verify_test.go | 4 +- 10 files changed, 190 insertions(+), 192 deletions(-) diff --git a/address.go b/address.go index 90ad02d..94f97f5 100644 --- a/address.go +++ b/address.go @@ -91,15 +91,10 @@ func ValidA58(a58 []byte) (bool, error) { // GetAddressFromPrivateKey takes a bsvec private key and returns a Bitcoin address func GetAddressFromPrivateKey(privateKey *bsvec.PrivateKey, compressed bool) (string, error) { - - rawKey, err := PrivateKeyFromString(fmt.Sprintf("%x", privateKey.Serialize())) + address, err := GetAddressFromPubKey(privateKey.PubKey(), compressed) if err != nil { return "", err } - var address *bsvutil.LegacyAddressPubKeyHash - if address, err = GetAddressFromPubKey(rawKey.PubKey(), compressed); err != nil { - return "", err - } return address.EncodeAddress(), nil } diff --git a/address_test.go b/address_test.go index eeca9aa..0d3ff27 100644 --- a/address_test.go +++ b/address_test.go @@ -33,13 +33,13 @@ func TestValidA58(t *testing.T) { // Run tests for _, test := range tests { if valid, err := ValidA58([]byte(test.input)); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) } else if valid && !test.expectedValid { - t.Errorf("%s Failed: [%s] inputted and was valid but should NOT be valid", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was valid but should NOT be valid", t.Name(), test.input) } else if !valid && test.expectedValid { - t.Errorf("%s Failed: [%s] inputted and was invalid but should be valid", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was invalid but should be valid", t.Name(), test.input) } } } @@ -88,34 +88,37 @@ func TestGetAddressFromPrivateKey(t *testing.T) { // Run tests for _, test := range tests { if address, err := GetAddressFromPrivateKeyString(test.input, test.compressed); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) } else if address != test.expectedAddress { - t.Errorf("%s Failed: [%s] inputted and [%s] expected, but got: %s", t.Name(), test.input, test.expectedAddress, address) + t.Fatalf("%s Failed: [%s] inputted and [%s] expected, but got: %s", t.Name(), test.input, test.expectedAddress, address) } } } +// TestGetAddressFromPrivateKeyCompression will test the method GetAddressFromPrivateKey() func TestGetAddressFromPrivateKeyCompression(t *testing.T) { privateKey, err := bsvec.NewPrivateKey(bsvec.S256()) if err != nil { - t.Error(err) + t.Fatal(err) } - addressUncompressed, err := GetAddressFromPrivateKey(privateKey, false) + var addressUncompressed string + addressUncompressed, err = GetAddressFromPrivateKey(privateKey, false) if err != nil { - t.Error(err) + t.Fatal(err) } - addressCompressed, err := GetAddressFromPrivateKey(privateKey, true) + var addressCompressed string + addressCompressed, err = GetAddressFromPrivateKey(privateKey, true) if err != nil { - t.Error(err) + t.Fatal(err) } if addressCompressed == addressUncompressed { - t.Errorf("Compressed and uncompressed addresses cannot match") + t.Fatalf("compressed and uncompressed addresses cannot match") } } @@ -169,15 +172,15 @@ func TestGetAddressFromPubKey(t *testing.T) { // Run tests for _, test := range tests { if rawKey, err := GetAddressFromPubKey(test.input, true); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) } else if rawKey == nil && !test.expectedNil { - t.Errorf("%s Failed: [%v] inputted and was nil but not expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and was nil but not expected", t.Name(), test.input) } else if rawKey != nil && test.expectedNil { - t.Errorf("%s Failed: [%v] inputted and was NOT nil but expected to be nil", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and was NOT nil but expected to be nil", t.Name(), test.input) } else if rawKey != nil && rawKey.EncodeAddress() != test.expectedAddress { - t.Errorf("%s Failed: [%v] inputted [%s] expected but failed comparison of addresses, got: %s", t.Name(), test.input, test.expectedAddress, rawKey.EncodeAddress()) + t.Fatalf("%s Failed: [%v] inputted [%s] expected but failed comparison of addresses, got: %s", t.Name(), test.input, test.expectedAddress, rawKey.EncodeAddress()) } } } @@ -227,11 +230,11 @@ func TestGetAddressFromScript(t *testing.T) { // Run tests for _, test := range tests { if address, err := GetAddressFromScript(test.inputScript); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.inputScript, err.Error()) + t.Fatalf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.inputScript, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error was expected", t.Name(), test.inputScript) + t.Fatalf("%s Failed: [%v] inputted and error was expected", t.Name(), test.inputScript) } else if address != test.expectedAddress { - t.Errorf("%s Failed: [%v] inputted [%s] expected but failed comparison of addresses, got: %s", t.Name(), test.inputScript, test.expectedAddress, address) + t.Fatalf("%s Failed: [%v] inputted [%s] expected but failed comparison of addresses, got: %s", t.Name(), test.inputScript, test.expectedAddress, address) } } } @@ -274,15 +277,15 @@ func TestGetAddressFromPubKeyString(t *testing.T) { // Run tests for _, test := range tests { if rawKey, err := GetAddressFromPubKeyString(test.input, true); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) } else if rawKey == nil && !test.expectedNil { - t.Errorf("%s Failed: [%v] inputted and was nil but not expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and was nil but not expected", t.Name(), test.input) } else if rawKey != nil && test.expectedNil { - t.Errorf("%s Failed: [%v] inputted and was NOT nil but expected to be nil", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and was NOT nil but expected to be nil", t.Name(), test.input) } else if rawKey != nil && rawKey.EncodeAddress() != test.expectedAddress { - t.Errorf("%s Failed: [%v] inputted [%s] expected but failed comparison of addresses, got: %s", t.Name(), test.input, test.expectedAddress, rawKey.EncodeAddress()) + t.Fatalf("%s Failed: [%v] inputted [%s] expected but failed comparison of addresses, got: %s", t.Name(), test.input, test.expectedAddress, rawKey.EncodeAddress()) } } } diff --git a/encryption_test.go b/encryption_test.go index 4b4b5ae..026f595 100644 --- a/encryption_test.go +++ b/encryption_test.go @@ -40,11 +40,11 @@ func TestEncryptWithPrivateKey(t *testing.T) { var encrypted string for _, test := range tests { if encrypted, err = EncryptWithPrivateKey(test.inputKey, test.inputData); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] [%s] inputted and error not expected but got: %s", t.Name(), test.inputKey, test.inputData, err.Error()) + t.Fatalf("%s Failed: [%s] [%s] inputted and error not expected but got: %s", t.Name(), test.inputKey, test.inputData, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] [%s] inputted and error was expected", t.Name(), test.inputKey, test.inputData) + t.Fatalf("%s Failed: [%s] [%s] inputted and error was expected", t.Name(), test.inputKey, test.inputData) } else if len(encrypted) == 0 { - t.Errorf("%s Failed: [%s] [%s] inputted and expected length > 0, but got: 0", t.Name(), test.inputKey, test.inputData) + t.Fatalf("%s Failed: [%s] [%s] inputted and expected length > 0, but got: 0", t.Name(), test.inputKey, test.inputData) } } } @@ -55,7 +55,7 @@ func TestEncryptWithPrivateKeyPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -129,11 +129,11 @@ func TestEncryptWithPrivateKeyString(t *testing.T) { var encrypted string for _, test := range tests { if encrypted, err = EncryptWithPrivateKeyString(test.inputKey, test.inputData); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] [%s] inputted and error not expected but got: %s", t.Name(), test.inputKey, test.inputData, err.Error()) + t.Fatalf("%s Failed: [%s] [%s] inputted and error not expected but got: %s", t.Name(), test.inputKey, test.inputData, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] [%s] inputted and error was expected", t.Name(), test.inputKey, test.inputData) + t.Fatalf("%s Failed: [%s] [%s] inputted and error was expected", t.Name(), test.inputKey, test.inputData) } else if err == nil && len(encrypted) == 0 { - t.Errorf("%s Failed: [%s] [%s] inputted and expected length > 0, but got: 0", t.Name(), test.inputKey, test.inputData) + t.Fatalf("%s Failed: [%s] [%s] inputted and expected length > 0, but got: 0", t.Name(), test.inputKey, test.inputData) } } } @@ -249,11 +249,11 @@ func TestDecryptWithPrivateKey(t *testing.T) { var decrypted string for _, test := range tests { if decrypted, err = DecryptWithPrivateKey(test.inputKey, test.inputEncrypted); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] [%s] inputted and error not expected but got: %s", t.Name(), test.inputKey, test.inputEncrypted, err.Error()) + t.Fatalf("%s Failed: [%s] [%s] inputted and error not expected but got: %s", t.Name(), test.inputKey, test.inputEncrypted, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] [%s] inputted and error was expected", t.Name(), test.inputKey, test.inputEncrypted) + t.Fatalf("%s Failed: [%s] [%s] inputted and error was expected", t.Name(), test.inputKey, test.inputEncrypted) } else if decrypted != test.expectedData { - t.Errorf("%s Failed: [%s] [%s] inputted and [%s] expected, but got: %s", t.Name(), test.inputKey, test.inputEncrypted, test.expectedData, decrypted) + t.Fatalf("%s Failed: [%s] [%s] inputted and [%s] expected, but got: %s", t.Name(), test.inputKey, test.inputEncrypted, test.expectedData, decrypted) } } } @@ -375,11 +375,11 @@ func TestDecryptWithPrivateKeyString(t *testing.T) { // Run tests for _, test := range tests { if decrypted, err := DecryptWithPrivateKeyString(test.inputKey, test.inputEncrypted); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] [%s] inputted and error not expected but got: %s", t.Name(), test.inputKey, test.inputEncrypted, err.Error()) + t.Fatalf("%s Failed: [%s] [%s] inputted and error not expected but got: %s", t.Name(), test.inputKey, test.inputEncrypted, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] [%s] inputted and error was expected", t.Name(), test.inputKey, test.inputEncrypted) + t.Fatalf("%s Failed: [%s] [%s] inputted and error was expected", t.Name(), test.inputKey, test.inputEncrypted) } else if decrypted != test.expectedData { - t.Errorf("%s Failed: [%s] [%s] inputted and [%s] expected, but got: %s", t.Name(), test.inputKey, test.inputEncrypted, test.expectedData, decrypted) + t.Fatalf("%s Failed: [%s] [%s] inputted and [%s] expected, but got: %s", t.Name(), test.inputKey, test.inputEncrypted, test.expectedData, decrypted) } } } @@ -454,7 +454,7 @@ func TestEncryptSharedPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -512,7 +512,7 @@ func TestEncryptSharedStringPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() diff --git a/hd_key_test.go b/hd_key_test.go index 7456333..b2b826c 100644 --- a/hd_key_test.go +++ b/hd_key_test.go @@ -32,13 +32,13 @@ func TestGenerateHDKey(t *testing.T) { // Run tests for _, test := range tests { if hdKey, err := GenerateHDKey(test.inputSeed); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%d] inputted and error not expected but got: %s", t.Name(), test.inputSeed, err.Error()) + t.Fatalf("%s Failed: [%d] inputted and error not expected but got: %s", t.Name(), test.inputSeed, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%d] inputted and error was expected", t.Name(), test.inputSeed) + t.Fatalf("%s Failed: [%d] inputted and error was expected", t.Name(), test.inputSeed) } else if hdKey == nil && !test.expectedNil { - t.Errorf("%s Failed: [%d] inputted and was nil but not expected", t.Name(), test.inputSeed) + t.Fatalf("%s Failed: [%d] inputted and was nil but not expected", t.Name(), test.inputSeed) } else if hdKey != nil && test.expectedNil { - t.Errorf("%s Failed: [%d] inputted and was NOT nil but expected to be nil", t.Name(), test.inputSeed) + t.Fatalf("%s Failed: [%d] inputted and was NOT nil but expected to be nil", t.Name(), test.inputSeed) } } } @@ -91,13 +91,13 @@ func TestGenerateHDKeyPair(t *testing.T) { // Run tests for _, test := range tests { if privateKey, publicKey, err := GenerateHDKeyPair(test.inputSeed); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%d] inputted and error not expected but got: %s", t.Name(), test.inputSeed, err.Error()) + t.Fatalf("%s Failed: [%d] inputted and error not expected but got: %s", t.Name(), test.inputSeed, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%d] inputted and error was expected", t.Name(), test.inputSeed) + t.Fatalf("%s Failed: [%d] inputted and error was expected", t.Name(), test.inputSeed) } else if err == nil && len(privateKey) == 0 { - t.Errorf("%s Failed: [%d] inputted and private key was empty", t.Name(), test.inputSeed) + t.Fatalf("%s Failed: [%d] inputted and private key was empty", t.Name(), test.inputSeed) } else if err == nil && len(publicKey) == 0 { - t.Errorf("%s Failed: [%d] inputted and pubic key was empty", t.Name(), test.inputSeed) + t.Fatalf("%s Failed: [%d] inputted and pubic key was empty", t.Name(), test.inputSeed) } } } @@ -167,15 +167,15 @@ func TestGetPrivateKeyByPath(t *testing.T) { var privateKey *bsvec.PrivateKey for _, test := range tests { if privateKey, err = GetPrivateKeyByPath(test.inputHDKey, test.inputChain, test.inputNum); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] [%d] [%d] inputted and error not expected but got: %s", t.Name(), test.inputHDKey, test.inputChain, test.inputNum, err.Error()) + t.Fatalf("%s Failed: [%v] [%d] [%d] inputted and error not expected but got: %s", t.Name(), test.inputHDKey, test.inputChain, test.inputNum, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] [%d] [%d] inputted and error was expected", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] [%d] inputted and error was expected", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) } else if privateKey == nil && !test.expectedNil { - t.Errorf("%s Failed: [%v] [%d] [%d] inputted and was nil but not expected", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] [%d] inputted and was nil but not expected", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) } else if privateKey != nil && test.expectedNil { - t.Errorf("%s Failed: [%v] [%d] [%d] inputted and was NOT nil but expected to be nil", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] [%d] inputted and was NOT nil but expected to be nil", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) } else if privateKey != nil && len(hex.EncodeToString(privateKey.Serialize())) == 0 { - t.Errorf("%s Failed: [%v] [%d] [%d] inputted and should not be empty", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] [%d] inputted and should not be empty", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) } } } @@ -186,7 +186,7 @@ func TestGetPrivateKeyByPathPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -279,15 +279,15 @@ func TestGetHDKeyByPath(t *testing.T) { // Run tests for _, test := range tests { if hdKey, err := GetHDKeyByPath(test.inputHDKey, test.inputChain, test.inputNum); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] [%d] [%d] inputted and error not expected but got: %s", t.Name(), test.inputHDKey, test.inputChain, test.inputNum, err.Error()) + t.Fatalf("%s Failed: [%v] [%d] [%d] inputted and error not expected but got: %s", t.Name(), test.inputHDKey, test.inputChain, test.inputNum, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] [%d] [%d] inputted and error was expected", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] [%d] inputted and error was expected", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) } else if hdKey == nil && !test.expectedNil { - t.Errorf("%s Failed: [%v] [%d] [%d] inputted and was nil but not expected", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] [%d] inputted and was nil but not expected", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) } else if hdKey != nil && test.expectedNil { - t.Errorf("%s Failed: [%v] [%d] [%d] inputted and was NOT nil but expected to be nil", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] [%d] inputted and was NOT nil but expected to be nil", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) } else if hdKey != nil && len(hdKey.String()) == 0 { - t.Errorf("%s Failed: [%v] [%d] [%d] inputted and should not be empty", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] [%d] inputted and should not be empty", t.Name(), test.inputHDKey, test.inputChain, test.inputNum) } } } @@ -298,7 +298,7 @@ func TestGetHDKeyByPathPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -397,15 +397,15 @@ func TestGetHDKeyChild(t *testing.T) { // Run tests for _, test := range tests { if hdKey, err := GetHDKeyChild(test.inputHDKey, test.inputNum); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] [%d] inputted and error not expected but got: %s", t.Name(), test.inputHDKey, test.inputNum, err.Error()) + t.Fatalf("%s Failed: [%v] [%d] inputted and error not expected but got: %s", t.Name(), test.inputHDKey, test.inputNum, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] [%d] inputted and error was expected", t.Name(), test.inputHDKey, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] inputted and error was expected", t.Name(), test.inputHDKey, test.inputNum) } else if hdKey == nil && !test.expectedNil { - t.Errorf("%s Failed: [%v] [%d] inputted and was nil but not expected", t.Name(), test.inputHDKey, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] inputted and was nil but not expected", t.Name(), test.inputHDKey, test.inputNum) } else if hdKey != nil && test.expectedNil { - t.Errorf("%s Failed: [%v] [%d] inputted and was NOT nil but expected to be nil", t.Name(), test.inputHDKey, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] inputted and was NOT nil but expected to be nil", t.Name(), test.inputHDKey, test.inputNum) } else if hdKey != nil && len(hdKey.String()) == 0 { - t.Errorf("%s Failed: [%v] [%d] inputted and should not be empty", t.Name(), test.inputHDKey, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] inputted and should not be empty", t.Name(), test.inputHDKey, test.inputNum) } } } @@ -416,7 +416,7 @@ func TestGetHDKeyChildPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -475,15 +475,15 @@ func TestGenerateHDKeyFromString(t *testing.T) { // Run tests for _, test := range tests { if hdKey, err := GenerateHDKeyFromString(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) } else if hdKey == nil && !test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.input) } else if hdKey != nil && test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.input) } else if hdKey != nil && hdKey.String() != test.input { - t.Errorf("%s Failed: [%s] inputted [%s] expected but got: %s", t.Name(), test.input, test.input, hdKey.String()) + t.Fatalf("%s Failed: [%s] inputted [%s] expected but got: %s", t.Name(), test.input, test.input, hdKey.String()) } } } @@ -532,15 +532,15 @@ func TestGetPrivateKeyFromHDKey(t *testing.T) { // Run tests for _, test := range tests { if privateKey, err := GetPrivateKeyFromHDKey(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) } else if privateKey == nil && !test.expectedNil { - t.Errorf("%s Failed: [%v] inputted and was nil but not expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and was nil but not expected", t.Name(), test.input) } else if privateKey != nil && test.expectedNil { - t.Errorf("%s Failed: [%v] inputted and was NOT nil but expected to be nil", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and was NOT nil but expected to be nil", t.Name(), test.input) } else if privateKey != nil && hex.EncodeToString(privateKey.Serialize()) != test.expectedKey { - t.Errorf("%s Failed: [%v] inputted [%s] expected but got: %s", t.Name(), test.input, test.expectedKey, hex.EncodeToString(privateKey.Serialize())) + t.Fatalf("%s Failed: [%v] inputted [%s] expected but got: %s", t.Name(), test.input, test.expectedKey, hex.EncodeToString(privateKey.Serialize())) } } } @@ -551,7 +551,7 @@ func TestGetPrivateKeyFromHDKeyPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -611,11 +611,11 @@ func TestGetPrivateKeyStringFromHDKey(t *testing.T) { var privateKey string for _, test := range tests { if privateKey, err = GetPrivateKeyStringFromHDKey(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) } else if privateKey != test.expectedKey { - t.Errorf("%s Failed: [%v] inputted [%s] expected but got: %s", t.Name(), test.input, test.expectedKey, privateKey) + t.Fatalf("%s Failed: [%v] inputted [%s] expected but got: %s", t.Name(), test.input, test.expectedKey, privateKey) } } } @@ -626,7 +626,7 @@ func TestGetPrivateKeyStringFromHDKeyPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -687,15 +687,15 @@ func TestGetPublicKeyFromHDKey(t *testing.T) { var publicKey *bsvec.PublicKey for _, test := range tests { if publicKey, err = GetPublicKeyFromHDKey(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) } else if publicKey == nil && !test.expectedNil { - t.Errorf("%s Failed: [%v] inputted and was nil but not expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and was nil but not expected", t.Name(), test.input) } else if publicKey != nil && test.expectedNil { - t.Errorf("%s Failed: [%v] inputted and was NOT nil but expected to be nil", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and was NOT nil but expected to be nil", t.Name(), test.input) } else if publicKey != nil && hex.EncodeToString(publicKey.SerializeCompressed()) != test.expectedKey { - t.Errorf("%s Failed: [%v] inputted [%s] expected but got: %s", t.Name(), test.input, test.expectedKey, hex.EncodeToString(publicKey.SerializeCompressed())) + t.Fatalf("%s Failed: [%v] inputted [%s] expected but got: %s", t.Name(), test.input, test.expectedKey, hex.EncodeToString(publicKey.SerializeCompressed())) } } } @@ -706,7 +706,7 @@ func TestGetPublicKeyFromHDKeyPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -767,15 +767,15 @@ func TestGetAddressFromHDKey(t *testing.T) { var address *bsvutil.LegacyAddressPubKeyHash for _, test := range tests { if address, err = GetAddressFromHDKey(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) } else if address == nil && !test.expectedNil { - t.Errorf("%s Failed: [%v] inputted and was nil but not expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and was nil but not expected", t.Name(), test.input) } else if address != nil && test.expectedNil { - t.Errorf("%s Failed: [%v] inputted and was NOT nil but expected to be nil", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and was NOT nil but expected to be nil", t.Name(), test.input) } else if address != nil && address.String() != test.expectedAddress { - t.Errorf("%s Failed: [%v] inputted [%s] expected but got: %s", t.Name(), test.input, test.expectedAddress, address.String()) + t.Fatalf("%s Failed: [%v] inputted [%s] expected but got: %s", t.Name(), test.input, test.expectedAddress, address.String()) } } } @@ -786,7 +786,7 @@ func TestGetAddressFromHDKeyPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -846,11 +846,11 @@ func TestGetAddressStringFromHDKey(t *testing.T) { var address string for _, test := range tests { if address, err = GetAddressStringFromHDKey(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) } else if address != test.expectedAddress { - t.Errorf("%s Failed: [%v] inputted [%s] expected but got: %s", t.Name(), test.input, test.expectedAddress, address) + t.Fatalf("%s Failed: [%v] inputted [%s] expected but got: %s", t.Name(), test.input, test.expectedAddress, address) } } } @@ -861,7 +861,7 @@ func TestGetAddressStringFromHDKeyPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -927,17 +927,17 @@ func TestGetPublicKeysForPath(t *testing.T) { var pubKeys []*bsvec.PublicKey for _, test := range tests { if pubKeys, err = GetPublicKeysForPath(test.input, test.inputNum); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] [%d] inputted and error not expected but got: %s", t.Name(), test.input, test.inputNum, err.Error()) + t.Fatalf("%s Failed: [%v] [%d] inputted and error not expected but got: %s", t.Name(), test.input, test.inputNum, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] [%d] inputted and error was expected", t.Name(), test.input, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] inputted and error was expected", t.Name(), test.input, test.inputNum) } else if pubKeys == nil && !test.expectedNil { - t.Errorf("%s Failed: [%v] [%d] inputted and was nil but not expected", t.Name(), test.input, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] inputted and was nil but not expected", t.Name(), test.input, test.inputNum) } else if pubKeys != nil && test.expectedNil { - t.Errorf("%s Failed: [%v] [%d] inputted and was NOT nil but expected to be nil", t.Name(), test.input, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] inputted and was NOT nil but expected to be nil", t.Name(), test.input, test.inputNum) } else if pubKeys != nil && hex.EncodeToString(pubKeys[0].SerializeCompressed()) != test.expectedPubKey1 { - t.Errorf("%s Failed: [%v] [%d] inputted key 1 [%s] expected but got: %s", t.Name(), test.input, test.inputNum, test.expectedPubKey1, hex.EncodeToString(pubKeys[0].SerializeCompressed())) + t.Fatalf("%s Failed: [%v] [%d] inputted key 1 [%s] expected but got: %s", t.Name(), test.input, test.inputNum, test.expectedPubKey1, hex.EncodeToString(pubKeys[0].SerializeCompressed())) } else if pubKeys != nil && hex.EncodeToString(pubKeys[1].SerializeCompressed()) != test.expectedPubKey2 { - t.Errorf("%s Failed: [%v] [%d] inputted key 2 [%s] expected but got: %s", t.Name(), test.input, test.inputNum, test.expectedPubKey2, hex.EncodeToString(pubKeys[1].SerializeCompressed())) + t.Fatalf("%s Failed: [%v] [%d] inputted key 2 [%s] expected but got: %s", t.Name(), test.input, test.inputNum, test.expectedPubKey2, hex.EncodeToString(pubKeys[1].SerializeCompressed())) } } } @@ -948,7 +948,7 @@ func TestGetPublicKeysForPathPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -1013,17 +1013,17 @@ func TestGetAddressesForPath(t *testing.T) { var addresses []string for _, test := range tests { if addresses, err = GetAddressesForPath(test.input, test.inputNum); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] [%d] inputted and error not expected but got: %s", t.Name(), test.input, test.inputNum, err.Error()) + t.Fatalf("%s Failed: [%v] [%d] inputted and error not expected but got: %s", t.Name(), test.input, test.inputNum, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] [%d] inputted and error was expected", t.Name(), test.input, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] inputted and error was expected", t.Name(), test.input, test.inputNum) } else if addresses == nil && !test.expectedNil { - t.Errorf("%s Failed: [%v] [%d] inputted and was nil but not expected", t.Name(), test.input, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] inputted and was nil but not expected", t.Name(), test.input, test.inputNum) } else if addresses != nil && test.expectedNil { - t.Errorf("%s Failed: [%v] [%d] inputted and was NOT nil but expected to be nil", t.Name(), test.input, test.inputNum) + t.Fatalf("%s Failed: [%v] [%d] inputted and was NOT nil but expected to be nil", t.Name(), test.input, test.inputNum) } else if addresses != nil && addresses[0] != test.expectedAddress1 { - t.Errorf("%s Failed: [%v] [%d] inputted address 1 [%s] expected but got: %s", t.Name(), test.input, test.inputNum, test.expectedAddress1, addresses[0]) + t.Fatalf("%s Failed: [%v] [%d] inputted address 1 [%s] expected but got: %s", t.Name(), test.input, test.inputNum, test.expectedAddress1, addresses[0]) } else if addresses != nil && addresses[1] != test.expectedAddress2 { - t.Errorf("%s Failed: [%v] [%d] inputted address 2 [%s] expected but got: %s", t.Name(), test.input, test.inputNum, test.expectedAddress2, addresses[1]) + t.Fatalf("%s Failed: [%v] [%d] inputted address 2 [%s] expected but got: %s", t.Name(), test.input, test.inputNum, test.expectedAddress2, addresses[1]) } } } @@ -1034,7 +1034,7 @@ func TestGetAddressesForPathPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -1093,11 +1093,11 @@ func TestGetExtendedPublicKey(t *testing.T) { var xPub string for _, test := range tests { if xPub, err = GetExtendedPublicKey(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%v] inputted and error was expected", t.Name(), test.input) } else if xPub != test.expectedKey { - t.Errorf("%s Failed: [%v] inputted and [%s] expected but got: %s", t.Name(), test.input, test.expectedKey, xPub) + t.Fatalf("%s Failed: [%v] inputted and [%s] expected but got: %s", t.Name(), test.input, test.expectedKey, xPub) } } } @@ -1108,7 +1108,7 @@ func TestGetExtendedPublicKeyPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -1184,15 +1184,15 @@ func TestGetHDKeyFromExtendedPublicKey(t *testing.T) { // Run tests for _, test := range tests { if xPub, err := GetHDKeyFromExtendedPublicKey(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) } else if xPub == nil && !test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.input) } else if xPub != nil && test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.input) } else if xPub != nil && xPub.String() != test.expectedKey { - t.Errorf("%s Failed: [%s] inputted and [%s] expected but got: %s", t.Name(), test.input, test.expectedKey, xPub) + t.Fatalf("%s Failed: [%s] inputted and [%s] expected but got: %s", t.Name(), test.input, test.expectedKey, xPub) } } } diff --git a/private_key_test.go b/private_key_test.go index 9fe4c18..7ec5e17 100644 --- a/private_key_test.go +++ b/private_key_test.go @@ -25,7 +25,7 @@ func TestGenerateSharedKeyPair(t *testing.T) { // encrypt something with the shared public key encryptTest, err := bsvec.Encrypt(user1SharedPubKey, []byte(testEncryptionMessage)) if err != nil { - t.Errorf("Failed to encrypt test data %s", err) + t.Fatalf("Failed to encrypt test data %s", err) } // user 2 decrypts it @@ -34,11 +34,11 @@ func TestGenerateSharedKeyPair(t *testing.T) { var decryptedTestData []byte decryptedTestData, err = bsvec.Decrypt(user2SharedPrivKey, encryptTest) if err != nil { - t.Errorf("Failed to decrypt test data %s", err) + t.Fatalf("Failed to decrypt test data %s", err) } if string(decryptedTestData) != testEncryptionMessage { - t.Errorf("Decrypted string doesnt match %s", decryptedTestData) + t.Fatalf("Decrypted string doesnt match %s", decryptedTestData) } } @@ -133,15 +133,15 @@ func TestPrivateKeyFromString(t *testing.T) { // Run tests for _, test := range tests { if rawKey, err := PrivateKeyFromString(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) } else if rawKey == nil && !test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.input) } else if rawKey != nil && test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.input) } else if rawKey != nil && hex.EncodeToString(rawKey.Serialize()) != test.expectedKey { - t.Errorf("%s Failed: [%s] inputted [%s] expected but failed comparison of keys, got: %s", t.Name(), test.input, test.expectedKey, hex.EncodeToString(rawKey.Serialize())) + t.Fatalf("%s Failed: [%s] inputted [%s] expected but failed comparison of keys, got: %s", t.Name(), test.input, test.expectedKey, hex.EncodeToString(rawKey.Serialize())) } } } @@ -188,15 +188,15 @@ func TestPrivateAndPublicKeys(t *testing.T) { // Run tests for _, test := range tests { if privateKey, publicKey, err := PrivateAndPublicKeys(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) } else if (privateKey == nil || publicKey == nil) && !test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.input) } else if (privateKey != nil || publicKey != nil) && test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.input) } else if privateKey != nil && hex.EncodeToString(privateKey.Serialize()) != test.expectedPrivateKey { - t.Errorf("%s Failed: [%s] inputted [%s] expected but failed comparison of keys, got: %s", t.Name(), test.input, test.expectedPrivateKey, hex.EncodeToString(privateKey.Serialize())) + t.Fatalf("%s Failed: [%s] inputted [%s] expected but failed comparison of keys, got: %s", t.Name(), test.input, test.expectedPrivateKey, hex.EncodeToString(privateKey.Serialize())) } } } @@ -244,15 +244,15 @@ func TestPrivateKeyToWif(t *testing.T) { // Run tests for _, test := range tests { if wif, err := PrivateKeyToWif(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) } else if wif == nil && !test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.input) } else if wif != nil && test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.input) } else if wif != nil && wif.String() != test.expectedWif { - t.Errorf("%s Failed: [%s] inputted [%s] expected but failed comparison of keys, got: %s", t.Name(), test.input, test.expectedWif, wif.String()) + t.Fatalf("%s Failed: [%s] inputted [%s] expected but failed comparison of keys, got: %s", t.Name(), test.input, test.expectedWif, wif.String()) } } @@ -300,11 +300,11 @@ func TestPrivateKeyToWifString(t *testing.T) { // Run tests for _, test := range tests { if wif, err := PrivateKeyToWifString(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) } else if wif != test.expectedWif { - t.Errorf("%s Failed: [%s] inputted [%s] expected but failed comparison of keys, got: %s", t.Name(), test.input, test.expectedWif, wif) + t.Fatalf("%s Failed: [%s] inputted [%s] expected but failed comparison of keys, got: %s", t.Name(), test.input, test.expectedWif, wif) } } @@ -352,15 +352,15 @@ func TestWifToPrivateKey(t *testing.T) { // Run tests for _, test := range tests { if privateKey, err := WifToPrivateKey(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) } else if privateKey == nil && !test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.input) } else if privateKey != nil && test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.input) } else if privateKey != nil && hex.EncodeToString(privateKey.Serialize()) != test.expectedKey { - t.Errorf("%s Failed: [%s] inputted [%s] expected but failed comparison of keys, got: %s", t.Name(), test.input, test.expectedKey, hex.EncodeToString(privateKey.Serialize())) + t.Fatalf("%s Failed: [%s] inputted [%s] expected but failed comparison of keys, got: %s", t.Name(), test.input, test.expectedKey, hex.EncodeToString(privateKey.Serialize())) } } } @@ -405,11 +405,11 @@ func TestWifToPrivateKeyString(t *testing.T) { // Run tests for _, test := range tests { if privateKey, err := WifToPrivateKeyString(test.input); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) + t.Fatalf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.input, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) + t.Fatalf("%s Failed: [%s] inputted and error was expected", t.Name(), test.input) } else if privateKey != test.expectedKey { - t.Errorf("%s Failed: [%s] inputted [%s] expected but failed comparison of keys, got: %s", t.Name(), test.input, test.expectedKey, privateKey) + t.Fatalf("%s Failed: [%s] inputted [%s] expected but failed comparison of keys, got: %s", t.Name(), test.input, test.expectedKey, privateKey) } } } diff --git a/pubkey_test.go b/pubkey_test.go index 9cecf55..05e38a9 100644 --- a/pubkey_test.go +++ b/pubkey_test.go @@ -26,11 +26,11 @@ func TestPubKeyFromPrivateKeyString(t *testing.T) { // Run tests for _, test := range tests { if pubKey, err := PubKeyFromPrivateKeyString(test.inputKey, true); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.inputKey, err.Error()) + t.Fatalf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.inputKey, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error was expected", t.Name(), test.inputKey) + t.Fatalf("%s Failed: [%s] inputted and error was expected", t.Name(), test.inputKey) } else if pubKey != test.expectedPubKey { - t.Errorf("%s Failed: [%s] inputted and [%s] expected, but got: %s", t.Name(), test.inputKey, test.expectedPubKey, pubKey) + t.Fatalf("%s Failed: [%s] inputted and [%s] expected, but got: %s", t.Name(), test.inputKey, test.expectedPubKey, pubKey) } } } @@ -75,7 +75,7 @@ func TestPubKeyFromPrivateKey(t *testing.T) { // Run tests for _, test := range tests { if pubKey := PubKeyFromPrivateKey(test.inputKey, true); pubKey != test.expectedPubKey { - t.Errorf("%s Failed: [%v] inputted and [%s] expected, but got: %s", t.Name(), test.inputKey, test.expectedPubKey, pubKey) + t.Fatalf("%s Failed: [%v] inputted and [%s] expected, but got: %s", t.Name(), test.inputKey, test.expectedPubKey, pubKey) } } } @@ -86,7 +86,7 @@ func TestPubKeyFromPrivateKeyPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -138,15 +138,15 @@ func TestPubKeyFromString(t *testing.T) { // Run tests for _, test := range tests { if pubKey, err := PubKeyFromString(test.inputKey); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.inputKey, err.Error()) + t.Fatalf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.inputKey, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error was expected", t.Name(), test.inputKey) + t.Fatalf("%s Failed: [%s] inputted and error was expected", t.Name(), test.inputKey) } else if pubKey != nil && test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and nil was expected", t.Name(), test.inputKey) + t.Fatalf("%s Failed: [%s] inputted and nil was expected", t.Name(), test.inputKey) } else if pubKey == nil && !test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and nil was NOT expected", t.Name(), test.inputKey) + t.Fatalf("%s Failed: [%s] inputted and nil was NOT expected", t.Name(), test.inputKey) } else if pubKey != nil && hex.EncodeToString(pubKey.SerializeCompressed()) != test.expectedPubKey { - t.Errorf("%s Failed: [%s] inputted and [%s] expected, but got: %s", t.Name(), test.inputKey, test.expectedPubKey, hex.EncodeToString(pubKey.SerializeCompressed())) + t.Fatalf("%s Failed: [%s] inputted and [%s] expected, but got: %s", t.Name(), test.inputKey, test.expectedPubKey, hex.EncodeToString(pubKey.SerializeCompressed())) } } } diff --git a/script_test.go b/script_test.go index 4ef806f..f58c714 100644 --- a/script_test.go +++ b/script_test.go @@ -25,11 +25,11 @@ func TestScriptFromAddress(t *testing.T) { // Run tests for _, test := range tests { if script, err := ScriptFromAddress(test.inputAddress); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.inputAddress, err.Error()) + t.Fatalf("%s Failed: [%v] inputted and error not expected but got: %s", t.Name(), test.inputAddress, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] inputted and error was expected", t.Name(), test.inputAddress) + t.Fatalf("%s Failed: [%v] inputted and error was expected", t.Name(), test.inputAddress) } else if script != test.expectedScript { - t.Errorf("%s Failed: [%v] inputted [%s] expected but failed comparison of scripts, got: %s", t.Name(), test.inputAddress, test.expectedScript, script) + t.Fatalf("%s Failed: [%v] inputted [%s] expected but failed comparison of scripts, got: %s", t.Name(), test.inputAddress, test.expectedScript, script) } } } diff --git a/sign_test.go b/sign_test.go index b287ab1..f36c1ea 100644 --- a/sign_test.go +++ b/sign_test.go @@ -88,11 +88,11 @@ func TestSignMessage(t *testing.T) { // Run tests for idx, test := range tests { if signature, err := SignMessage(test.inputKey, test.inputMessage); err != nil && !test.expectedError { - t.Errorf("%d %s Failed: [%s] [%s] inputted and error not expected but got: %s", idx, t.Name(), test.inputKey, test.inputMessage, err.Error()) + t.Fatalf("%d %s Failed: [%s] [%s] inputted and error not expected but got: %s", idx, t.Name(), test.inputKey, test.inputMessage, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%d %s Failed: [%s] [%s] inputted and error was expected", idx, t.Name(), test.inputKey, test.inputMessage) + t.Fatalf("%d %s Failed: [%s] [%s] inputted and error was expected", idx, t.Name(), test.inputKey, test.inputMessage) } else if signature != test.expectedSignature { - t.Errorf("%d %s Failed: [%s] [%s] inputted [%s] expected but got: %s", idx, t.Name(), test.inputKey, test.inputMessage, test.expectedSignature, signature) + t.Fatalf("%d %s Failed: [%s] [%s] inputted [%s] expected but got: %s", idx, t.Name(), test.inputKey, test.inputMessage, test.expectedSignature, signature) } } } diff --git a/transaction_test.go b/transaction_test.go index 5f6a1e3..22fc376 100644 --- a/transaction_test.go +++ b/transaction_test.go @@ -28,15 +28,15 @@ func TestTxFromHex(t *testing.T) { // Run tests for _, test := range tests { if rawTx, err := TxFromHex(test.inputHex); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.inputHex, err.Error()) + t.Fatalf("%s Failed: [%s] inputted and error not expected but got: %s", t.Name(), test.inputHex, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] inputted and error was expected", t.Name(), test.inputHex) + t.Fatalf("%s Failed: [%s] inputted and error was expected", t.Name(), test.inputHex) } else if rawTx == nil && !test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.inputHex) + t.Fatalf("%s Failed: [%s] inputted and was nil but not expected", t.Name(), test.inputHex) } else if rawTx != nil && test.expectedNil { - t.Errorf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.inputHex) + t.Fatalf("%s Failed: [%s] inputted and was NOT nil but expected to be nil", t.Name(), test.inputHex) } else if rawTx != nil && rawTx.GetTxID() != test.expectedTxID { - t.Errorf("%s Failed: [%s] inputted [%s] expected but failed comparison of txIDs, got: %s", t.Name(), test.inputHex, test.expectedTxID, rawTx.GetTxID()) + t.Fatalf("%s Failed: [%s] inputted [%s] expected but failed comparison of txIDs, got: %s", t.Name(), test.inputHex, test.expectedTxID, rawTx.GetTxID()) } } } @@ -316,15 +316,15 @@ func TestCreateTxErrors(t *testing.T) { } if rawTx, err := CreateTx(test.inputUtxos, test.inputAddresses, test.inputOpReturns, privateKey); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] [%v] [%v] [%s] inputted and error not expected but got: %s", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif, err.Error()) + t.Fatalf("%s Failed: [%v] [%v] [%v] [%s] inputted and error not expected but got: %s", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] [%v] [%v] [%s] inputted and error was expected", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif) + t.Fatalf("%s Failed: [%v] [%v] [%v] [%s] inputted and error was expected", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif) } else if rawTx == nil && !test.expectedNil { - t.Errorf("%s Failed: [%v] [%v] [%v] [%s] inputted and nil was not expected", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif) + t.Fatalf("%s Failed: [%v] [%v] [%v] [%s] inputted and nil was not expected", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif) } else if rawTx != nil && test.expectedNil { - t.Errorf("%s Failed: [%v] [%v] [%v] [%s] inputted and nil was expected", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif) + t.Fatalf("%s Failed: [%v] [%v] [%v] [%s] inputted and nil was expected", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif) } else if rawTx != nil && rawTx.ToString() != test.expectedRawTx { - t.Errorf("%s Failed: [%v] [%v] [%v] [%s] inputted [%s] expected but failed comparison of scripts, got: %s", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif, test.expectedRawTx, rawTx.ToString()) + t.Fatalf("%s Failed: [%v] [%v] [%v] [%s] inputted [%s] expected but failed comparison of scripts, got: %s", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif, test.expectedRawTx, rawTx.ToString()) } } } @@ -577,9 +577,9 @@ func TestCalculateFeeForTxVariousTxs(t *testing.T) { // Test the function if satoshis = CalculateFeeForTx(tx, test.inputStandardRate, test.inputDataRate); satoshis != test.expectedSatoshis { t.Log("tx size: ", len(tx.ToBytes())) - t.Errorf("%s Failed: [%s] [%v] [%v] inputted [%d] expected but got: %d", t.Name(), test.inputHex, test.inputStandardRate, test.inputDataRate, test.expectedSatoshis, satoshis) + t.Fatalf("%s Failed: [%s] [%v] [%v] inputted [%d] expected but got: %d", t.Name(), test.inputHex, test.inputStandardRate, test.inputDataRate, test.expectedSatoshis, satoshis) } else if tx.GetTxID() != test.expectedTxID { - t.Errorf("%s Failed: [%s] [%v] [%v] inputted [%s] expected but got: %s", t.Name(), test.inputHex, test.inputStandardRate, test.inputDataRate, test.expectedTxID, tx.GetTxID()) + t.Fatalf("%s Failed: [%s] [%v] [%v] inputted [%s] expected but got: %s", t.Name(), test.inputHex, test.inputStandardRate, test.inputDataRate, test.expectedTxID, tx.GetTxID()) } } } @@ -639,7 +639,7 @@ func TestCalculateFeeForTxPanic(t *testing.T) { defer func() { if r := recover(); r == nil { - t.Errorf("the code did not panic") + t.Fatalf("the code did not panic") } }() @@ -916,15 +916,15 @@ func TestCreateTxWithChangeErrors(t *testing.T) { } if rawTx, err = CreateTxWithChange(test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputChangeAddress, test.inputStandardRate, test.inputDataRate, privateKey); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%v] [%v] [%v] [%s] inputted and error not expected but got: %s", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif, err.Error()) + t.Fatalf("%s Failed: [%v] [%v] [%v] [%s] inputted and error not expected but got: %s", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%v] [%v] [%v] [%s] inputted and error was expected", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif) + t.Fatalf("%s Failed: [%v] [%v] [%v] [%s] inputted and error was expected", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif) } else if rawTx == nil && !test.expectedNil { - t.Errorf("%s Failed: [%v] [%v] [%v] [%s] inputted and nil was not expected", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif) + t.Fatalf("%s Failed: [%v] [%v] [%v] [%s] inputted and nil was not expected", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif) } else if rawTx != nil && test.expectedNil { - t.Errorf("%s Failed: [%v] [%v] [%v] [%s] inputted and nil was expected", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif) + t.Fatalf("%s Failed: [%v] [%v] [%v] [%s] inputted and nil was expected", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif) } else if rawTx != nil && rawTx.ToString() != test.expectedRawTx { - t.Errorf("%s Failed: [%v] [%v] [%v] [%s] inputted [%s] expected but failed comparison of scripts, got: %s", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif, test.expectedRawTx, rawTx.ToString()) + t.Fatalf("%s Failed: [%v] [%v] [%v] [%s] inputted [%s] expected but failed comparison of scripts, got: %s", t.Name(), test.inputUtxos, test.inputAddresses, test.inputOpReturns, test.inputWif, test.expectedRawTx, rawTx.ToString()) } } } diff --git a/verify_test.go b/verify_test.go index d22fcf6..11d7942 100644 --- a/verify_test.go +++ b/verify_test.go @@ -94,9 +94,9 @@ func TestVerifyMessage(t *testing.T) { // Run tests for _, test := range tests { if err := VerifyMessage(test.inputAddress, test.inputSignature, test.inputData); err != nil && !test.expectedError { - t.Errorf("%s Failed: [%s] [%s] [%s] inputted and error not expected but got: %s", t.Name(), test.inputAddress, test.inputSignature, test.inputData, err.Error()) + t.Fatalf("%s Failed: [%s] [%s] [%s] inputted and error not expected but got: %s", t.Name(), test.inputAddress, test.inputSignature, test.inputData, err.Error()) } else if err == nil && test.expectedError { - t.Errorf("%s Failed: [%s] [%s] [%s] inputted and error was expected", t.Name(), test.inputAddress, test.inputSignature, test.inputData) + t.Fatalf("%s Failed: [%s] [%s] [%s] inputted and error was expected", t.Name(), test.inputAddress, test.inputSignature, test.inputData) } }