@@ -1059,6 +1059,74 @@ func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
10591059 require .InDelta (t , assetAmount , totalAssetAmount , 1 )
10601060}
10611061
1062+ type assetHodlInvoice struct {
1063+ preimage lntypes.Preimage
1064+ payReq string
1065+ }
1066+
1067+ func createAssetHodlInvoice (t * testing.T , dstRfqPeer , dst * HarnessNode ,
1068+ assetAmount uint64 , assetID []byte ) assetHodlInvoice {
1069+
1070+ ctxb := context .Background ()
1071+ ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
1072+ defer cancel ()
1073+
1074+ timeoutSeconds := int64 (rfq .DefaultInvoiceExpiry .Seconds ())
1075+
1076+ t .Logf ("Asking peer %x for quote to buy assets to receive for " +
1077+ "invoice over %d units; waiting up to %ds" ,
1078+ dstRfqPeer .PubKey [:], assetAmount , timeoutSeconds )
1079+
1080+ dstTapd := newTapClient (t , dst )
1081+
1082+ // As this is a hodl invoice, we'll also need to create a preimage external
1083+ // to lnd.
1084+ var preimage lntypes.Preimage
1085+ _ , err := rand .Read (preimage [:])
1086+ require .NoError (t , err )
1087+
1088+ payHash := preimage .Hash ()
1089+
1090+ resp , err := dstTapd .AddInvoice (ctxt , & tchrpc.AddInvoiceRequest {
1091+ AssetId : assetID ,
1092+ AssetAmount : assetAmount ,
1093+ PeerPubkey : dstRfqPeer .PubKey [:],
1094+ InvoiceRequest : & lnrpc.Invoice {
1095+ Memo : fmt .Sprintf ("this is an asset invoice over " +
1096+ "%d units" , assetAmount ),
1097+ Expiry : timeoutSeconds ,
1098+ },
1099+ HodlInvoice : & tchrpc.HodlInvoice {
1100+ PaymentHash : payHash [:],
1101+ },
1102+ })
1103+ require .NoError (t , err )
1104+
1105+ decodedInvoice , err := dst .DecodePayReq (ctxt , & lnrpc.PayReqString {
1106+ PayReq : resp .InvoiceResult .PaymentRequest ,
1107+ })
1108+ require .NoError (t , err )
1109+
1110+ rpcRate := resp .AcceptedBuyQuote .AskAssetRate
1111+ rate , err := rfqrpc .UnmarshalFixedPoint (rpcRate )
1112+ require .NoError (t , err )
1113+
1114+ assetUnits := rfqmath .NewBigIntFixedPoint (assetAmount , 0 )
1115+ numMSats := rfqmath .UnitsToMilliSatoshi (assetUnits , * rate )
1116+ mSatPerUnit := float64 (decodedInvoice .NumMsat ) / float64 (assetAmount )
1117+
1118+ require .EqualValues (t , uint64 (numMSats ), uint64 (decodedInvoice .NumMsat ))
1119+
1120+ t .Logf ("Got quote for %d sats at %v msat/unit from peer %x with SCID " +
1121+ "%d" , decodedInvoice .NumMsat , mSatPerUnit , dstRfqPeer .PubKey [:],
1122+ resp .AcceptedBuyQuote .Scid )
1123+
1124+ return assetHodlInvoice {
1125+ preimage : preimage ,
1126+ payReq : resp .InvoiceResult .PaymentRequest ,
1127+ }
1128+ }
1129+
10621130func waitForSendEvent (t * testing.T ,
10631131 sendEvents taprpc.TaprootAssets_SubscribeSendEventsClient ,
10641132 expectedState tapfreighter.SendState ) {
0 commit comments