Skip to content

Commit 6b991a5

Browse files
authored
Merge pull request #775 from lightninglabs/btc-only-htlcs
itest: add BTC-only keysend and invoice payments
2 parents 980ee93 + fe69fd1 commit 6b991a5

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ require (
2020
github.com/lightninglabs/loop/swapserverrpc v1.0.8
2121
github.com/lightninglabs/pool v0.6.5-beta.0.20240604070222-e121aadb3289
2222
github.com/lightninglabs/pool/auctioneerrpc v1.1.2
23-
github.com/lightninglabs/taproot-assets v0.3.3-0.20240609154533-2b3c60ae77a9
24-
github.com/lightningnetwork/lnd v0.18.0-beta.rc3.0.20240607141010-393d6829ca7d
23+
github.com/lightninglabs/taproot-assets v0.3.3-0.20240621151738-7a0a009cea0b
24+
github.com/lightningnetwork/lnd v0.18.0-beta.rc3.0.20240621142354-5fc4d4b1ec2b
2525
github.com/lightningnetwork/lnd/cert v1.2.2
2626
github.com/lightningnetwork/lnd/fn v1.0.8
2727
github.com/lightningnetwork/lnd/kvdb v1.4.8

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,12 +1172,12 @@ github.com/lightninglabs/pool/auctioneerrpc v1.1.2 h1:Dbg+9Z9jXnhimR27EN37foc4aB
11721172
github.com/lightninglabs/pool/auctioneerrpc v1.1.2/go.mod h1:1wKDzN2zEP8srOi0B9iySlEsPdoPhw6oo3Vbm1v4Mhw=
11731173
github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display h1:pRdza2wleRN1L2fJXd6ZoQ9ZegVFTAb2bOQfruJPKcY=
11741174
github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
1175-
github.com/lightninglabs/taproot-assets v0.3.3-0.20240609154533-2b3c60ae77a9 h1:A7GSIxahO2AaYnDaruiHh5kqmQ1ilEo2L76TGjU7B0o=
1176-
github.com/lightninglabs/taproot-assets v0.3.3-0.20240609154533-2b3c60ae77a9/go.mod h1:Km86kikQR/ZVPgK/bi9khZnt/FOoHEErx4itPiHi2i4=
1175+
github.com/lightninglabs/taproot-assets v0.3.3-0.20240621151738-7a0a009cea0b h1:VFDiq9WM8XuQ8/Q13gzvXE6MZ+bp4U3idTHCVFYG+YI=
1176+
github.com/lightninglabs/taproot-assets v0.3.3-0.20240621151738-7a0a009cea0b/go.mod h1:6pirBUx8UaalAug+XR2g+TsaivwT6+nVcQZwC571rl4=
11771177
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f h1:Pua7+5TcFEJXIIZ1I2YAUapmbcttmLj4TTi786bIi3s=
11781178
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
1179-
github.com/lightningnetwork/lnd v0.18.0-beta.rc3.0.20240607141010-393d6829ca7d h1:9tUVysV2TP6pAP4Mxcbm4TQwsMp6Vg6KiTG9ouSyACE=
1180-
github.com/lightningnetwork/lnd v0.18.0-beta.rc3.0.20240607141010-393d6829ca7d/go.mod h1:ZZ8c08GgxS6bbtPQv8hPZYB4m2SrhBQJa3N+JgnpR0o=
1179+
github.com/lightningnetwork/lnd v0.18.0-beta.rc3.0.20240621142354-5fc4d4b1ec2b h1:lXQjDLthlVKX2cR1cZzoRDhB/n1WsVm9FeiWv894d8U=
1180+
github.com/lightningnetwork/lnd v0.18.0-beta.rc3.0.20240621142354-5fc4d4b1ec2b/go.mod h1:ZZ8c08GgxS6bbtPQv8hPZYB4m2SrhBQJa3N+JgnpR0o=
11811181
github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf0d0Uy4qBjI=
11821182
github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U=
11831183
github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0=

itest/litd_custom_channels_test.go

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
377377
// Test case 1: Send a direct keysend payment from Charlie to Dave.
378378
// ------------
379379
const keySendAmount = 100
380-
sendKeySendPayment(t.t, charlie, dave, keySendAmount, assetID)
380+
sendAssetKeySendPayment(t.t, charlie, dave, keySendAmount, assetID)
381381
logBalance(t.t, nodes, assetID, "after keysend")
382382

383383
charlieAssetBalance -= keySendAmount
@@ -386,12 +386,16 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
386386
// We should be able to send the 100 assets back immediately, because
387387
// there is enough on-chain balance on Dave's side to be able to create
388388
// an HTLC.
389-
sendKeySendPayment(t.t, dave, charlie, keySendAmount, assetID)
389+
sendAssetKeySendPayment(t.t, dave, charlie, keySendAmount, assetID)
390390
logBalance(t.t, nodes, assetID, "after keysend back")
391391

392392
charlieAssetBalance += keySendAmount
393393
daveAssetBalance -= keySendAmount
394394

395+
// We should also be able to do a non-asset (BTC only) keysend payment.
396+
sendKeySendPayment(t.t, charlie, dave, 2000, nil)
397+
logBalance(t.t, nodes, assetID, "after BTC only keysend")
398+
395399
// ------------
396400
// Test case 2: Pay a normal invoice from Dave by Charlie, making it
397401
// a direct channel invoice payment with no RFQ SCID present in the
@@ -405,6 +409,11 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
405409
charlieAssetBalance -= paidAssetAmount
406410
daveAssetBalance += paidAssetAmount
407411

412+
// We should also be able to do a multi-hop BTC only payment, paying an
413+
// invoice from Erin by Charlie.
414+
createAndPayNormalInvoiceWithBtc(t.t, charlie, erin, 2000)
415+
logBalance(t.t, nodes, assetID, "after BTC only invoice")
416+
408417
// ------------
409418
// Test case 3: Pay an asset invoice from Dave by Charlie, making it
410419
// a direct channel invoice payment with an RFQ SCID present in the
@@ -861,7 +870,7 @@ func getAssetChannelBalance(t *testing.T, node *HarnessNode, assetID []byte,
861870
return localSum, remoteSum
862871
}
863872

864-
func sendKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
873+
func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
865874
assetID []byte) {
866875

867876
ctxb := context.Background()
@@ -886,9 +895,22 @@ func sendKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
886895
)
887896
require.NoError(t, err)
888897

898+
const htlcCarrierAmt = 500
899+
sendKeySendPayment(
900+
t, src, dst, htlcCarrierAmt, encodeResp.CustomRecords,
901+
)
902+
}
903+
904+
func sendKeySendPayment(t *testing.T, src, dst *HarnessNode, amt btcutil.Amount,
905+
firstHopCustomRecords map[uint64][]byte) {
906+
907+
ctxb := context.Background()
908+
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
909+
defer cancel()
910+
889911
// Read out the custom preimage for the keysend payment.
890912
var preimage lntypes.Preimage
891-
_, err = rand.Read(preimage[:])
913+
_, err := rand.Read(preimage[:])
892914
require.NoError(t, err)
893915

894916
hash := preimage.Hash()
@@ -898,12 +920,11 @@ func sendKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
898920
customRecords := make(map[uint64][]byte)
899921
customRecords[record.KeySendType] = preimage[:]
900922

901-
const htlcCarrierAmt = 500
902923
req := &routerrpc.SendPaymentRequest{
903924
Dest: dst.PubKey[:],
904-
Amt: htlcCarrierAmt,
925+
Amt: int64(amt),
905926
DestCustomRecords: customRecords,
906-
FirstHopCustomRecords: encodeResp.CustomRecords,
927+
FirstHopCustomRecords: firstHopCustomRecords,
907928
PaymentHash: hash[:],
908929
TimeoutSeconds: 3,
909930
}
@@ -918,6 +939,24 @@ func sendKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
918939
require.Equal(t, lnrpc.Payment_SUCCEEDED, result.Status)
919940
}
920941

942+
func createAndPayNormalInvoiceWithBtc(t *testing.T, src, dst *HarnessNode,
943+
amountSat btcutil.Amount) {
944+
945+
ctxb := context.Background()
946+
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
947+
defer cancel()
948+
949+
expirySeconds := 10
950+
invoiceResp, err := dst.AddInvoice(ctxt, &lnrpc.Invoice{
951+
Value: int64(amountSat),
952+
Memo: "normal invoice",
953+
Expiry: int64(expirySeconds),
954+
})
955+
require.NoError(t, err)
956+
957+
payInvoiceWithSatoshi(t, src, invoiceResp)
958+
}
959+
921960
func createAndPayNormalInvoice(t *testing.T, src, rfqPeer, dst *HarnessNode,
922961
amountSat btcutil.Amount, assetID []byte) uint64 {
923962

0 commit comments

Comments
 (0)