itest/test: assert expired hold invoice updated correctly

This commit is contained in:
carla 2021-05-11 08:45:32 +02:00
parent b7d1ed0cbb
commit 8066ff7047
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91
2 changed files with 9 additions and 21 deletions

@ -178,8 +178,8 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
err = waitForNumChannelPendingForceClose(ctxt, bob, 0, nil) err = waitForNumChannelPendingForceClose(ctxt, bob, 0, nil)
require.NoError(t.t, err) require.NoError(t.t, err)
// While we're here, we demonstrate some bugs in our handling of // While we're here, we assert that our expired invoice's state is
// invoices that timeout on chain. // correctly updated, and can no longer be settled.
assertOnChainInvoiceState(ctxb, t, carol, preimage) assertOnChainInvoiceState(ctxb, t, carol, preimage)
// We'll close out the test by closing the channel from Alice to Bob, // We'll close out the test by closing the channel from Alice to Bob,
@ -191,12 +191,8 @@ func testMultiHopRemoteForceCloseOnChainHtlcTimeout(net *lntest.NetworkHarness,
) )
} }
// assertOnChainInvoiceState asserts that we have some bugs with how we handle // assertOnChainInvoiceState asserts that we have the correct state for a hold
// hold invoices that are expired on-chain. // invoice that has expired on chain, and that it can't be settled.
// - htlcs accepted: despite being timed out, our htlcs are still in accepted
// state
// - can settle: our invoice that has expired on-chain can still be settled
// even though we don't claim any htlcs.
func assertOnChainInvoiceState(ctx context.Context, t *harnessTest, func assertOnChainInvoiceState(ctx context.Context, t *harnessTest,
node *lntest.HarnessNode, preimage lntypes.Preimage) { node *lntest.HarnessNode, preimage lntypes.Preimage) {
@ -207,22 +203,12 @@ func assertOnChainInvoiceState(ctx context.Context, t *harnessTest,
require.NoError(t.t, err) require.NoError(t.t, err)
for _, htlc := range inv.Htlcs { for _, htlc := range inv.Htlcs {
require.Equal(t.t, lnrpc.InvoiceHTLCState_ACCEPTED, htlc.State) require.Equal(t.t, lnrpc.InvoiceHTLCState_CANCELED, htlc.State)
} }
require.Equal(t.t, lnrpc.Invoice_CANCELED, inv.State)
_, err = node.SettleInvoice(ctx, &invoicesrpc.SettleInvoiceMsg{ _, err = node.SettleInvoice(ctx, &invoicesrpc.SettleInvoiceMsg{
Preimage: preimage[:], Preimage: preimage[:],
}) })
require.NoError(t.t, err, "expected erroneous invoice settle") require.Error(t.t, err, "should not be able to settle invoice")
inv, err = node.LookupInvoice(ctx, &lnrpc.PaymentHash{
RHash: hash[:],
})
require.NoError(t.t, err)
require.True(t.t, inv.Settled, "expected erroneously settled invoice") // nolint:staticcheck
for _, htlc := range inv.Htlcs {
require.Equal(t.t, lnrpc.InvoiceHTLCState_SETTLED, htlc.State,
"expected htlcs to be erroneously settled")
}
} }

@ -279,3 +279,5 @@
<time> [ERR] RPCS: [/lnrpc.State/SubscribeState]: context canceled <time> [ERR] RPCS: [/lnrpc.State/SubscribeState]: context canceled
<time> [ERR] NTFN: Failed to update rescan progress: database not open <time> [ERR] NTFN: Failed to update rescan progress: database not open
<time> [ERR] HSWC: ChannelLink(<chan>): failing link: process hodl queue: unable to update commitment: link shutting down with error: internal error <time> [ERR] HSWC: ChannelLink(<chan>): failing link: process hodl queue: unable to update commitment: link shutting down with error: internal error
<time> [ERR] INVC: SettleHodlInvoice with preimage <hex>: invoice already canceled
<time> [ERR] RPCS: [/invoicesrpc.Invoices/SettleInvoice]: invoice already canceled