Skip to content

Commit 3a8f1f6

Browse files
GeorgeTsagkguggero
authored andcommitted
itest: test custom channel strict forwarding
1 parent 6e8592e commit 3a8f1f6

File tree

2 files changed

+71
-5
lines changed

2 files changed

+71
-5
lines changed

itest/assets_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,42 @@ func payInvoiceWithSatoshi(t *testing.T, payer *HarnessNode,
812812
require.Equal(t, expectedStatus, result.Status)
813813
}
814814

815+
func payInvoiceWithSatoshiLastHop(t *testing.T, payer *HarnessNode,
816+
invoice *lnrpc.AddInvoiceResponse, hopPub []byte,
817+
expectedStatus lnrpc.Payment_PaymentStatus) {
818+
819+
ctxb := context.Background()
820+
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
821+
defer cancel()
822+
823+
routeRes, err := payer.RouterClient.BuildRoute(
824+
ctxb, &routerrpc.BuildRouteRequest{
825+
AmtMsat: 17800,
826+
FinalCltvDelta: 80,
827+
PaymentAddr: invoice.PaymentAddr,
828+
HopPubkeys: [][]byte{hopPub},
829+
},
830+
)
831+
require.NoError(t, err)
832+
833+
res, err := payer.RouterClient.SendToRouteV2(
834+
ctxt, &routerrpc.SendToRouteRequest{
835+
PaymentHash: invoice.RHash,
836+
Route: routeRes.Route,
837+
},
838+
)
839+
840+
switch expectedStatus {
841+
case lnrpc.Payment_FAILED:
842+
require.NoError(t, err)
843+
require.Equal(t, lnrpc.HTLCAttempt_FAILED, res.Status)
844+
require.Nil(t, res.Preimage)
845+
846+
case lnrpc.Payment_SUCCEEDED:
847+
require.Equal(t, lnrpc.HTLCAttempt_SUCCEEDED, res.Status)
848+
}
849+
}
850+
815851
func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
816852
invoice *lnrpc.AddInvoiceResponse, assetID []byte,
817853
smallShards bool) (uint64, rfqmath.BigIntFixedPoint) {

itest/litd_custom_channels_test.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/lightninglabs/taproot-assets/tapscript"
2424
"github.com/lightningnetwork/lnd/fn"
2525
"github.com/lightningnetwork/lnd/lnrpc"
26+
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
2627
"github.com/lightningnetwork/lnd/lntest"
2728
"github.com/lightningnetwork/lnd/lntest/port"
2829
"github.com/lightningnetwork/lnd/lntest/wait"
@@ -499,18 +500,20 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
499500

500501
// ------------
501502
// Test case 3.5: Pay an asset invoice from Dave by Charlie with normal
502-
// payment flow.
503+
// satoshi payment flow. We expect that payment to fail, since it's a
504+
// direct channel payment and the invoice is for assets, not sats. So
505+
// without a conversion, it is rejected by the receiver.
503506
// ------------
504507
invoiceResp = createAssetInvoice(
505508
t.t, charlie, dave, daveInvoiceAssetAmount, assetID,
506509
)
507510
payInvoiceWithSatoshi(
508-
t.t, charlie, invoiceResp, lnrpc.Payment_SUCCEEDED,
511+
t.t, charlie, invoiceResp, lnrpc.Payment_FAILED,
509512
)
510513
logBalance(t.t, nodes, assetID, "after asset invoice paid with sats")
511514

512515
// We don't need to update the asset balances of Charlie and Dave here
513-
// as the invoice was paid with sats.
516+
// as the invoice payment failed.
514517

515518
// ------------
516519
// Test case 4: Pay a normal invoice from Erin by Charlie.
@@ -1937,13 +1940,13 @@ func testCustomChannelsLiquidityEdgeCases(_ context.Context,
19371940
logBalance(t.t, nodes, assetID, "after big asset payment (btc "+
19381941
"invoice, direct)")
19391942

1940-
// Dave sends 200k assets and 2k sats to Yara.
1943+
// Dave sends 200k assets and 5k sats to Yara.
19411944
sendAssetKeySendPayment(
19421945
t.t, dave, yara, 2*bigAssetAmount, assetID,
19431946
fn.None[int64](), lnrpc.Payment_SUCCEEDED,
19441947
fn.None[lnrpc.PaymentFailureReason](),
19451948
)
1946-
sendKeySendPayment(t.t, dave, yara, 2000)
1949+
sendKeySendPayment(t.t, dave, yara, 5_000)
19471950

19481951
logBalance(t.t, nodes, assetID, "after 200k assets to Yara")
19491952

@@ -1969,6 +1972,33 @@ func testCustomChannelsLiquidityEdgeCases(_ context.Context,
19691972

19701973
logBalance(t.t, nodes, assetID, "after small payment (asset "+
19711974
"invoice, <354sats)")
1975+
1976+
// Edge case: Now Charlie creates an asset invoice to be paid for by
1977+
// Yara with satoshi. For the last hop we try to settle the invoice in
1978+
// satoshi, where we will check whether Charlie's strict forwarding
1979+
// works as expected.
1980+
invoiceResp = createAssetInvoice(
1981+
t.t, charlie, dave, 1, assetID,
1982+
)
1983+
1984+
ctxb := context.Background()
1985+
stream, err := dave.InvoicesClient.SubscribeSingleInvoice(
1986+
ctxb, &invoicesrpc.SubscribeSingleInvoiceRequest{
1987+
RHash: invoiceResp.RHash,
1988+
},
1989+
)
1990+
require.NoError(t.t, err)
1991+
1992+
// Yara pays Dave with enough satoshis, but Charlie will not settle as
1993+
// he expects assets.
1994+
payInvoiceWithSatoshiLastHop(
1995+
t.t, yara, invoiceResp, dave.PubKey[:], lnrpc.Payment_FAILED,
1996+
)
1997+
1998+
t.lndHarness.LNDHarness.AssertInvoiceState(stream, lnrpc.Invoice_OPEN)
1999+
2000+
logBalance(t.t, nodes, assetID, "after failed payment (asset "+
2001+
"invoice, strict forwarding)")
19722002
}
19732003

19742004
// testCustomChannelsBalanceConsistency is a test that test the balance of nodes

0 commit comments

Comments
 (0)