From 82753f091bcb0a0d7924c4bd0037c5690c11f17c Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Tue, 23 May 2023 10:16:34 -0500 Subject: [PATCH] zpay32: use message signer from unit tests The message signer from invoice_test.go is identical to the one created in the fuzz test. We're already using the private key from invoice_test.go, so we may as well use the complete message signer for simplicity. --- zpay32/fuzz_test.go | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/zpay32/fuzz_test.go b/zpay32/fuzz_test.go index f98af58d4..5b7897998 100644 --- a/zpay32/fuzz_test.go +++ b/zpay32/fuzz_test.go @@ -1,13 +1,9 @@ package zpay32 import ( - "fmt" "testing" - "github.com/btcsuite/btcd/btcec/v2" - "github.com/btcsuite/btcd/btcec/v2/ecdsa" "github.com/btcsuite/btcd/chaincfg" - "github.com/btcsuite/btcd/chaincfg/chainhash" ) func FuzzDecode(f *testing.F) { @@ -23,26 +19,7 @@ func FuzzEncode(f *testing.F) { return } - // Initialize the static key we will be using for this fuzz - // test. - testPrivKey, _ := btcec.PrivKeyFromBytes(testPrivKeyBytes) - - // Then, initialize the testMessageSigner so we can encode out - // invoices with this private key. - testMessageSigner := MessageSigner{ - SignCompact: func(msg []byte) ([]byte, error) { - hash := chainhash.HashB(msg) - sig, err := ecdsa.SignCompact(testPrivKey, hash, - true) - if err != nil { - return nil, - fmt.Errorf("can't sign the "+ - "message: %v", err) - } - - return sig, nil - }, - } + // Re-encode the invoice using our private key from unit tests. _, err = inv.Encode(testMessageSigner) if err != nil { return