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.
This commit is contained in:
Matt Morehouse 2023-05-23 10:16:34 -05:00
parent 4207be6e50
commit 82753f091b
No known key found for this signature in database
GPG key ID: CC8ECA224831C982

View file

@ -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