invoices/test: replace global testInvoice with constructor
For our relatively "static" test invoice, add a simple constructor using the globals defined, rather than having a global invoice which risks being mutated.
This commit is contained in:
2 files changed
+60
-43
No files matched your search
+31
-19
@@ -133,15 +133,6 @@ var (
|
||||
|
||||
var (
|
||||
testInvoiceAmt = lnwire.MilliSatoshi(100000)
|
||||
testInvoice = &invpkg.Invoice{
|
||||
Terms: invpkg.ContractTerm{
|
||||
PaymentPreimage: &testInvoicePreimage,
|
||||
Value: testInvoiceAmt,
|
||||
Expiry: time.Hour,
|
||||
Features: testFeatures,
|
||||
},
|
||||
CreationDate: testInvoiceCreationDate,
|
||||
}
|
||||
|
||||
testPayAddrReqInvoice = &invpkg.Invoice{
|
||||
Terms: invpkg.ContractTerm{
|
||||
@@ -174,16 +165,6 @@ var (
|
||||
},
|
||||
CreationDate: testInvoiceCreationDate,
|
||||
}
|
||||
|
||||
testHodlInvoice = &invpkg.Invoice{
|
||||
Terms: invpkg.ContractTerm{
|
||||
Value: testInvoiceAmt,
|
||||
Expiry: time.Hour,
|
||||
Features: testFeatures,
|
||||
},
|
||||
CreationDate: testInvoiceCreationDate,
|
||||
HodlInvoice: true,
|
||||
}
|
||||
)
|
||||
|
||||
func newTestChannelDB(t *testing.T, clock clock.Clock) (*channeldb.DB, error) {
|
||||
@@ -275,6 +256,37 @@ func getCircuitKey(htlcID uint64) invpkg.CircuitKey {
|
||||
}
|
||||
}
|
||||
|
||||
// newInvoice returns an invoice that can be used for testing, using the
|
||||
// constant values defined above (deep copied if necessary).
|
||||
//
|
||||
// Note that this invoice *does not* have a payment address set. It will
|
||||
// create a regular invoice with a preimage is hodl is false, and a hodl
|
||||
// invoice with no preimage otherwise.
|
||||
func newInvoice(t *testing.T, hodl bool) *invpkg.Invoice {
|
||||
invoice := &invpkg.Invoice{
|
||||
Terms: invpkg.ContractTerm{
|
||||
Value: testInvoiceAmt,
|
||||
Expiry: time.Hour,
|
||||
Features: testFeatures.Clone(),
|
||||
},
|
||||
CreationDate: testInvoiceCreationDate,
|
||||
}
|
||||
|
||||
// If creating a hodl invoice, we don't include a preimage.
|
||||
if hodl {
|
||||
invoice.HodlInvoice = true
|
||||
return invoice
|
||||
}
|
||||
|
||||
preimage, err := lntypes.MakePreimage(
|
||||
testInvoicePreimage[:],
|
||||
)
|
||||
require.NoError(t, err)
|
||||
invoice.Terms.PaymentPreimage = &preimage
|
||||
|
||||
return invoice
|
||||
}
|
||||
|
||||
// timeout implements a test level timeout.
|
||||
func timeout() func() {
|
||||
done := make(chan struct{})
|
||||
|
||||
Reference in new issue
Block a user