Skip to content

Commit 0381304

Browse files
committed
itest: extend liquidity edge cases for rfq htlc tracking
1 parent a69202f commit 0381304

File tree

3 files changed

+240
-53
lines changed

3 files changed

+240
-53
lines changed

itest/assets_test.go

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ const (
5656
DefaultPushSat int64 = 1062
5757
)
5858

59+
var (
60+
NoRfqIDOpt = fn.None[rfqmsg.ID]()
61+
)
62+
5963
// createTestAssetNetwork sends asset funds from Charlie to Dave and Erin, so
6064
// they can fund asset channels with Yara and Fabia, respectively. So the asset
6165
// channels created are Charlie->Dave, Dave->Yara, Erin->Fabia. The channels
@@ -714,6 +718,9 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
714718

715719
result, err := getAssetPaymentResult(stream, false)
716720
require.NoError(t, err)
721+
if result.Status == lnrpc.Payment_FAILED {
722+
t.Logf("Failure reason: %v", result.FailureReason)
723+
}
717724
require.Equal(t, expectedStatus, result.Status)
718725

719726
expectedReason := failReason.UnwrapOr(
@@ -772,7 +779,9 @@ func createAndPayNormalInvoiceWithBtc(t *testing.T, src, dst *HarnessNode,
772779
})
773780
require.NoError(t, err)
774781

775-
payInvoiceWithSatoshi(t, src, invoiceResp, lnrpc.Payment_SUCCEEDED)
782+
payInvoiceWithSatoshi(
783+
t, src, invoiceResp, lnrpc.Payment_SUCCEEDED, false,
784+
)
776785
}
777786

778787
func createAndPayNormalInvoice(t *testing.T, src, rfqPeer, dst *HarnessNode,
@@ -792,15 +801,15 @@ func createAndPayNormalInvoice(t *testing.T, src, rfqPeer, dst *HarnessNode,
792801

793802
numUnits, _ := payInvoiceWithAssets(
794803
t, src, rfqPeer, invoiceResp.PaymentRequest, assetID, smallShards,
795-
fn.None[lnrpc.Payment_PaymentStatus](),
804+
fn.None[lnrpc.Payment_PaymentStatus](), NoRfqIDOpt,
796805
)
797806

798807
return numUnits
799808
}
800809

801810
func payInvoiceWithSatoshi(t *testing.T, payer *HarnessNode,
802811
invoice *lnrpc.AddInvoiceResponse,
803-
expectedStatus lnrpc.Payment_PaymentStatus) {
812+
expectedStatus lnrpc.Payment_PaymentStatus, expectTimeout bool) {
804813

805814
ctxb := context.Background()
806815
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -816,8 +825,12 @@ func payInvoiceWithSatoshi(t *testing.T, payer *HarnessNode,
816825
require.NoError(t, err)
817826

818827
result, err := getPaymentResult(stream)
819-
require.NoError(t, err)
820-
require.Equal(t, expectedStatus, result.Status)
828+
if expectTimeout {
829+
require.ErrorContains(t, err, "context deadline exceeded")
830+
} else {
831+
require.NoError(t, err)
832+
require.Equal(t, expectedStatus, result.Status)
833+
}
821834
}
822835

823836
func payInvoiceWithSatoshiLastHop(t *testing.T, payer *HarnessNode,
@@ -858,7 +871,8 @@ func payInvoiceWithSatoshiLastHop(t *testing.T, payer *HarnessNode,
858871

859872
func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
860873
payReq string, assetID []byte, smallShards bool,
861-
expectedPayStatus fn.Option[lnrpc.Payment_PaymentStatus]) (uint64,
874+
expectedPayStatus fn.Option[lnrpc.Payment_PaymentStatus],
875+
manualRfq fn.Option[rfqmsg.ID]) (uint64,
862876
rfqmath.BigIntFixedPoint) {
863877

864878
ctxb := context.Background()
@@ -882,44 +896,62 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
882896
sendReq.MaxShardSizeMsat = 80_000_000
883897
}
884898

899+
var rfqBytes []byte
900+
manualRfq.WhenSome(func(i rfqmsg.ID) {
901+
rfq := manualRfq.UnsafeFromSome()
902+
copy(rfqBytes, rfq[:])
903+
})
904+
885905
stream, err := payerTapd.SendPayment(ctxt, &tchrpc.SendPaymentRequest{
886906
AssetId: assetID,
887907
PeerPubkey: rfqPeer.PubKey[:],
888908
PaymentRequest: sendReq,
909+
RfqId: rfqBytes,
889910
})
890911
require.NoError(t, err)
891912

892-
// We want to receive the accepted quote message first, so we know how
893-
// many assets we're going to pay.
894-
quoteMsg, err := stream.Recv()
895-
require.NoError(t, err)
896-
acceptedQuote := quoteMsg.GetAcceptedSellOrder()
897-
require.NotNil(t, acceptedQuote)
913+
var (
914+
numUnits uint64
915+
rateVal rfqmath.FixedPoint[rfqmath.BigInt]
916+
)
898917

899-
peerPubKey := acceptedQuote.Peer
900-
require.Equal(t, peerPubKey, rfqPeer.PubKeyStr)
918+
if manualRfq.IsNone() {
919+
// We want to receive the accepted quote message first, so we know how
920+
// many assets we're going to pay.
921+
quoteMsg, err := stream.Recv()
922+
require.NoError(t, err)
923+
acceptedQuote := quoteMsg.GetAcceptedSellOrder()
924+
require.NotNil(t, acceptedQuote)
901925

902-
rpcRate := acceptedQuote.BidAssetRate
903-
rate, err := rfqrpc.UnmarshalFixedPoint(rpcRate)
904-
require.NoError(t, err)
926+
peerPubKey := acceptedQuote.Peer
927+
require.Equal(t, peerPubKey, rfqPeer.PubKeyStr)
905928

906-
t.Logf("Got quote for %v asset units per BTC", rate)
929+
rpcRate := acceptedQuote.BidAssetRate
930+
rate, err := rfqrpc.UnmarshalFixedPoint(rpcRate)
931+
require.NoError(t, err)
932+
933+
rateVal = *rate
907934

908-
amountMsat := lnwire.MilliSatoshi(decodedInvoice.NumMsat)
909-
milliSatsFP := rfqmath.MilliSatoshiToUnits(amountMsat, *rate)
910-
numUnits := milliSatsFP.ScaleTo(0).ToUint64()
911-
msatPerUnit := float64(decodedInvoice.NumMsat) / float64(numUnits)
912-
t.Logf("Got quote for %v asset units at %3f msat/unit from peer %s "+
913-
"with SCID %d", numUnits, msatPerUnit, peerPubKey,
914-
acceptedQuote.Scid)
935+
t.Logf("Got quote for %v asset units per BTC", rate)
936+
937+
amountMsat := lnwire.MilliSatoshi(decodedInvoice.NumMsat)
938+
milliSatsFP := rfqmath.MilliSatoshiToUnits(amountMsat, *rate)
939+
numUnits = milliSatsFP.ScaleTo(0).ToUint64()
940+
msatPerUnit := float64(decodedInvoice.NumMsat) / float64(numUnits)
941+
t.Logf("Got quote for %v asset units at %3f msat/unit from peer %s "+
942+
"with SCID %d", numUnits, msatPerUnit, peerPubKey,
943+
acceptedQuote.Scid)
944+
}
915945

916946
expectedStatus := expectedPayStatus.UnwrapOr(lnrpc.Payment_SUCCEEDED)
917947

918-
result, err := getAssetPaymentResult(stream, expectedPayStatus.IsSome())
948+
result, err := getAssetPaymentResult(
949+
stream, expectedStatus == lnrpc.Payment_IN_FLIGHT,
950+
)
919951
require.NoError(t, err)
920952
require.Equal(t, expectedStatus, result.Status)
921953

922-
return numUnits, *rate
954+
return numUnits, rateVal
923955
}
924956

925957
func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,

itest/litd_accounts_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,13 @@ func getAssetPaymentResult(
451451
return nil, err
452452
}
453453

454+
// Ignore RFQ quote acceptance messages read from the send
455+
// payment stream, as they are not relevant.
456+
quote := msg.GetAcceptedSellOrder()
457+
if quote != nil {
458+
continue
459+
}
460+
454461
payment := msg.GetPaymentResult()
455462
if payment == nil {
456463
return nil, fmt.Errorf("unexpected message: %v", msg)

0 commit comments

Comments
 (0)