99 "time"
1010
1111 "github.com/btcsuite/btcd/btcutil"
12+ "github.com/lightninglabs/taproot-assets/asset"
13+ "github.com/lightninglabs/taproot-assets/fn"
1214 "github.com/lightninglabs/taproot-assets/rfqmsg"
1315 "github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
1416 "github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
@@ -19,6 +21,7 @@ import (
1921 "github.com/lightningnetwork/lnd/lntest/node"
2022 "github.com/lightningnetwork/lnd/lntest/wait"
2123 "github.com/lightningnetwork/lnd/lnwire"
24+ "github.com/lightningnetwork/lnd/tlv"
2225 "github.com/stretchr/testify/require"
2326)
2427
@@ -190,8 +193,8 @@ func testRfqAssetBuyHtlcIntercept(t *harnessTest) {
190193 t .Log ("Alice payment sent" )
191194
192195 // At this point Bob should have received a HTLC with the asset transfer
193- // specific scid. We'll wait for Bob to publish an accept HTLC event and
194- // then validate it against the accepted quote .
196+ // specific scid. We'll wait for Bob to validate the HTLC against the
197+ // accepted quote and publish a HTLC accept event .
195198 BeforeTimeout (t .t , func () {
196199 t .Log ("Waiting for Bob to receive HTLC" )
197200
@@ -229,7 +232,11 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
229232 t .t , t .lndHarness .Miner ().Client , ts .AliceTapd ,
230233 []* mintrpc.MintAssetRequest {issuableAssets [0 ]},
231234 )
232- mintedAssetId := rpcAssets [0 ].AssetGenesis .AssetId
235+ mintedAssetIdBytes := rpcAssets [0 ].AssetGenesis .AssetId
236+
237+ // Type convert the asset ID bytes to an `asset.ID`.
238+ var mintedAssetId asset.ID
239+ copy (mintedAssetId [:], mintedAssetIdBytes [:])
233240
234241 ctxb := context .Background ()
235242 ctxt , cancel := context .WithTimeout (ctxb , defaultWaitTimeout )
@@ -241,7 +248,7 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
241248 ctxt , & rfqrpc.AddAssetBuyOfferRequest {
242249 AssetSpecifier : & rfqrpc.AssetSpecifier {
243250 Id : & rfqrpc.AssetSpecifier_AssetId {
244- AssetId : mintedAssetId ,
251+ AssetId : mintedAssetIdBytes ,
245252 },
246253 },
247254 MaxUnits : 1000 ,
@@ -257,20 +264,18 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
257264
258265 // Alice sends a sell order to Bob for some amount of the newly minted
259266 // asset.
260- purchaseAssetAmt := uint64 (200 )
261267 askAmt := uint64 (42000 )
262268 sellOrderExpiry := uint64 (time .Now ().Add (24 * time .Hour ).Unix ())
263269
264270 _ , err = ts .AliceTapd .AddAssetSellOrder (
265271 ctxt , & rfqrpc.AddAssetSellOrderRequest {
266272 AssetSpecifier : & rfqrpc.AssetSpecifier {
267273 Id : & rfqrpc.AssetSpecifier_AssetId {
268- AssetId : mintedAssetId ,
274+ AssetId : mintedAssetIdBytes ,
269275 },
270276 },
271- MaxAssetAmount : purchaseAssetAmt ,
272- MinAsk : askAmt ,
273- Expiry : sellOrderExpiry ,
277+ PaymentMaxAmt : askAmt ,
278+ Expiry : sellOrderExpiry ,
274279
275280 // Here we explicitly specify Bob as the destination
276281 // peer for the sell order. This will prompt Alice's
@@ -303,6 +308,10 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
303308
304309 acceptedQuote := acceptedQuotes .SellQuotes [0 ]
305310
311+ // Type cast the accepted quote ID bytes to an `rfqmsg.ID`.
312+ var acceptedQuoteId rfqmsg.ID
313+ copy (acceptedQuoteId [:], acceptedQuote .Id [:])
314+
306315 // Register to receive RFQ events from Bob's tapd node. We'll use this
307316 // to wait for Bob to receive the HTLC with the asset transfer specific
308317 // scid.
@@ -337,19 +346,40 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
337346
338347 // Send the payment to the route.
339348 t .Log ("Alice paying invoice" )
340- var htlcRfqIDTlvType rfqmsg.HtlcRfqIDType
349+
350+ // Construct first hop custom records for payment.
351+ //
352+ // The custom records will contain the accepted quote ID and the asset
353+ // amounts that Alice will pay to Bob.
354+ //
355+ // We select an asset amount which is sufficient to cover the invoice
356+ // amount.
357+ paymentAssetAmount := uint64 (42 )
358+ assetAmounts := []* rfqmsg.AssetBalance {
359+ rfqmsg .NewAssetBalance (mintedAssetId , paymentAssetAmount ),
360+ }
361+
362+ htlcCustomRecords := rfqmsg .NewHtlc (
363+ assetAmounts , fn .Some (acceptedQuoteId ),
364+ )
365+
366+ // Convert the custom records to a TLV map for inclusion in
367+ // SendToRouteRequest.
368+ firstHopCustomRecords , err := tlv .RecordsToMap (
369+ htlcCustomRecords .Records (),
370+ )
371+ require .NoError (t .t , err )
372+
341373 routeReq := routerrpc.SendToRouteRequest {
342- PaymentHash : invoice .RHash ,
343- Route : routeBuildResp .Route ,
344- FirstHopCustomRecords : map [uint64 ][]byte {
345- uint64 (htlcRfqIDTlvType .TypeVal ()): acceptedQuote .Id [:],
346- },
374+ PaymentHash : invoice .RHash ,
375+ Route : routeBuildResp .Route ,
376+ FirstHopCustomRecords : firstHopCustomRecords ,
347377 }
348378 sendAttempt := ts .AliceLnd .RPC .SendToRouteV2 (& routeReq )
349379
350- // The payment will fail since it doesn't transport the correct amount
351- // of the asset .
352- require .Equal (t .t , lnrpc .HTLCAttempt_FAILED , sendAttempt .Status )
380+ // The payment will succeed since it the asset amount transport is
381+ // sufficient to cover the invoice amount .
382+ require .Equal (t .t , lnrpc .HTLCAttempt_SUCCEEDED , sendAttempt .Status )
353383
354384 // At this point Bob should have received a HTLC with the asset transfer
355385 // specific scid. We'll wait for Bob to publish an accept HTLC event and
@@ -365,7 +395,7 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
365395
366396 // Confirm that Carol receives the lightning payment from Alice via Bob.
367397 invoice = ts .CarolLnd .RPC .LookupInvoice (addInvoiceResp .RHash )
368- require .Equal (t .t , invoice . State , lnrpc . Invoice_OPEN )
398+ require .Equal (t .t , lnrpc . Invoice_SETTLED , invoice . State )
369399
370400 // Close event notification streams.
371401 err = aliceEventNtfns .CloseSend ()
0 commit comments