mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 15:11:09 +02:00
channeldb/invoices: update AMP invoice htlcs
This commit is contained in:
@@ -1421,6 +1421,23 @@ func TestSetIDIndex(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, invoice, &dbInvoiceBySetID)
|
||||
|
||||
// Now settle the first htlc set, asserting that the two htlcs with set
|
||||
// id 2 get canceled as a result.
|
||||
dbInvoice, err = db.UpdateInvoice(ref, getUpdateInvoiceAMPSettle(setID))
|
||||
require.Nil(t, err)
|
||||
|
||||
invoice.State = ContractSettled
|
||||
invoice.SettleDate = dbInvoice.SettleDate
|
||||
invoice.SettleIndex = 1
|
||||
invoice.AmtPaid = amt
|
||||
invoice.Htlcs[CircuitKey{HtlcID: 0}].ResolveTime = time.Unix(1, 0)
|
||||
invoice.Htlcs[CircuitKey{HtlcID: 0}].State = HtlcStateSettled
|
||||
invoice.Htlcs[CircuitKey{HtlcID: 1}].ResolveTime = time.Unix(1, 0)
|
||||
invoice.Htlcs[CircuitKey{HtlcID: 1}].State = HtlcStateCanceled
|
||||
invoice.Htlcs[CircuitKey{HtlcID: 2}].ResolveTime = time.Unix(1, 0)
|
||||
invoice.Htlcs[CircuitKey{HtlcID: 2}].State = HtlcStateCanceled
|
||||
require.Equal(t, invoice, dbInvoice)
|
||||
|
||||
// Lastly, querying for an unknown set id should fail.
|
||||
refUnknownSetID := InvoiceRefBySetID([32]byte{})
|
||||
_, err = db.LookupInvoice(refUnknownSetID)
|
||||
@@ -1484,6 +1501,24 @@ func updateAcceptAMPHtlc(id uint64, amt lnwire.MilliSatoshi,
|
||||
}
|
||||
}
|
||||
|
||||
func getUpdateInvoiceAMPSettle(setID *[32]byte) InvoiceUpdateCallback {
|
||||
return func(invoice *Invoice) (*InvoiceUpdateDesc, error) {
|
||||
if invoice.State == ContractSettled {
|
||||
return nil, ErrInvoiceAlreadySettled
|
||||
}
|
||||
|
||||
update := &InvoiceUpdateDesc{
|
||||
State: &InvoiceStateUpdateDesc{
|
||||
Preimage: nil,
|
||||
NewState: ContractSettled,
|
||||
SetID: setID,
|
||||
},
|
||||
}
|
||||
|
||||
return update, nil
|
||||
}
|
||||
}
|
||||
|
||||
// TestDeleteInvoices tests that deleting a list of invoices will succeed
|
||||
// if all delete references are valid, or will fail otherwise.
|
||||
func TestDeleteInvoices(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user