99 "time"
1010
1111 "github.com/btcsuite/btcd/btcutil"
12- "github.com/btcsuite/btcd/wire"
1312 "github.com/lightninglabs/taproot-assets/rfqmsg"
1413 "github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
1514 "github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
@@ -23,6 +22,11 @@ import (
2322 "github.com/stretchr/testify/require"
2423)
2524
25+ var (
26+ // rfqTimeout is the timeout used for RFQ related operations.
27+ rfqTimeout = 5 * time .Second
28+ )
29+
2630// testRfqAssetBuyHtlcIntercept tests RFQ negotiation, HTLC interception, and
2731// validation between three peers. The RFQ negotiation is initiated by an asset
2832// buy request.
@@ -97,7 +101,7 @@ func testRfqAssetBuyHtlcIntercept(t *harnessTest) {
97101 // node.
98102 PeerPubKey : ts .BobLnd .PubKey [:],
99103
100- TimeoutSeconds : 5 ,
104+ TimeoutSeconds : uint32 ( rfqTimeout . Seconds ()) ,
101105 },
102106 )
103107 require .NoError (t .t , err , "unable to upsert asset buy order" )
@@ -110,7 +114,7 @@ func testRfqAssetBuyHtlcIntercept(t *harnessTest) {
110114
111115 _ , ok := event .Event .(* rfqrpc.RfqEvent_PeerAcceptedBuyQuote )
112116 require .True (t .t , ok , "unexpected event: %v" , event )
113- }, defaultWaitTimeout )
117+ }, rfqTimeout )
114118
115119 // Carol should have received an accepted quote from Bob. This accepted
116120 // quote can be used by Carol to make a payment to Bob.
@@ -203,7 +207,7 @@ func testRfqAssetBuyHtlcIntercept(t *harnessTest) {
203207 t .t , acceptedQuote .Scid , acceptHtlc .AcceptHtlc .Scid ,
204208 )
205209 t .Log ("Bob has accepted the HTLC" )
206- }, defaultWaitTimeout )
210+ }, rfqTimeout )
207211
208212 // Close event streams.
209213 err = carolEventNtfns .CloseSend ()
@@ -273,6 +277,8 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
273277 // tapd node to send a request for quote message to
274278 // Bob's node.
275279 PeerPubKey : ts .BobLnd .PubKey [:],
280+
281+ TimeoutSeconds : uint32 (rfqTimeout .Seconds ()),
276282 },
277283 )
278284 require .NoError (t .t , err , "unable to upsert asset sell order" )
@@ -285,7 +291,7 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
285291
286292 _ , ok := event .Event .(* rfqrpc.RfqEvent_PeerAcceptedSellQuote )
287293 require .True (t .t , ok , "unexpected event: %v" , event )
288- }, defaultWaitTimeout )
294+ }, rfqTimeout )
289295
290296 // Alice should have received an accepted quote from Bob. This accepted
291297 // quote can be used by Alice to make a payment to Bob.
@@ -329,28 +335,21 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
329335 }
330336 routeBuildResp := ts .AliceLnd .RPC .BuildRoute (& routeBuildRequest )
331337
332- // Add the accepted quote ID as a record to the custom records field of
333- // the route's first hop.
334- aliceBobHop := routeBuildResp .Route .Hops [0 ]
335- if aliceBobHop .CustomRecords == nil {
336- aliceBobHop .CustomRecords = make (map [uint64 ][]byte )
337- }
338-
339- var htlcRfqIDTlvType rfqmsg.HtlcRfqIDType
340- aliceBobHop .CustomRecords [uint64 (htlcRfqIDTlvType .TypeVal ())] =
341- acceptedQuote .Id [:]
342-
343- // Update the route with the modified first hop.
344- routeBuildResp .Route .Hops [0 ] = aliceBobHop
345-
346338 // Send the payment to the route.
347339 t .Log ("Alice paying invoice" )
340+ var htlcRfqIDTlvType rfqmsg.HtlcRfqIDType
348341 routeReq := routerrpc.SendToRouteRequest {
349342 PaymentHash : invoice .RHash ,
350343 Route : routeBuildResp .Route ,
344+ FirstHopCustomRecords : map [uint64 ][]byte {
345+ uint64 (htlcRfqIDTlvType .TypeVal ()): acceptedQuote .Id [:],
346+ },
351347 }
352348 sendAttempt := ts .AliceLnd .RPC .SendToRouteV2 (& routeReq )
353- require .Equal (t .t , lnrpc .HTLCAttempt_SUCCEEDED , sendAttempt .Status )
349+
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 )
354353
355354 // At this point Bob should have received a HTLC with the asset transfer
356355 // specific scid. We'll wait for Bob to publish an accept HTLC event and
@@ -362,11 +361,11 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
362361
363362 _ , ok := event .Event .(* rfqrpc.RfqEvent_AcceptHtlc )
364363 require .True (t .t , ok , "unexpected event: %v" , event )
365- }, defaultWaitTimeout )
364+ }, rfqTimeout )
366365
367366 // Confirm that Carol receives the lightning payment from Alice via Bob.
368367 invoice = ts .CarolLnd .RPC .LookupInvoice (addInvoiceResp .RHash )
369- require .Equal (t .t , invoice .State , lnrpc .Invoice_SETTLED )
368+ require .Equal (t .t , invoice .State , lnrpc .Invoice_OPEN )
370369
371370 // Close event notification streams.
372371 err = aliceEventNtfns .CloseSend ()
@@ -376,44 +375,6 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
376375 require .NoError (t .t , err )
377376}
378377
379- // newLndNode creates a new lnd node with the given name and funds its wallet
380- // with the specified outputs.
381- func newLndNode (name string , outputFunds []btcutil.Amount ,
382- ht * lntest.HarnessTest ) * node.HarnessNode {
383-
384- newNode := ht .NewNode (name , nil )
385-
386- // Fund node wallet with specified outputs.
387- totalTxes := len (outputFunds )
388- const (
389- numBlocksSendOutput = 2
390- minerFeeRate = btcutil .Amount (7500 )
391- )
392-
393- for i := range outputFunds {
394- amt := outputFunds [i ]
395-
396- resp := newNode .RPC .NewAddress (& lnrpc.NewAddressRequest {
397- Type : lnrpc .AddressType_WITNESS_PUBKEY_HASH },
398- )
399- addr := ht .DecodeAddress (resp .Address )
400- addrScript := ht .PayToAddrScript (addr )
401-
402- output := & wire.TxOut {
403- PkScript : addrScript ,
404- Value : int64 (amt ),
405- }
406- ht .Miner ().SendOutput (output , minerFeeRate )
407- }
408-
409- // Mine any funding transactions.
410- if totalTxes > 0 {
411- ht .MineBlocksAndAssertNumTxes (numBlocksSendOutput , totalTxes )
412- }
413-
414- return newNode
415- }
416-
417378// rfqTestScenario is a struct which holds test scenario helper infra.
418379type rfqTestScenario struct {
419380 testHarness * harnessTest
@@ -438,42 +399,43 @@ type rfqTestScenario struct {
438399// It also creates new tapd nodes for each of the LND nodes.
439400func newRfqTestScenario (t * harnessTest ) * rfqTestScenario {
440401 // Specify wallet outputs to fund the wallets of the new nodes.
441- const (
442- fundAmount = 1 * btcutil .SatoshiPerBitcoin
443- numOutputs = 100
444- totalAmount = fundAmount * numOutputs
445- )
446-
447- var outputFunds [numOutputs ]btcutil.Amount
448- for i := range outputFunds {
449- outputFunds [i ] = fundAmount
450- }
402+ const fundAmount = 1 * btcutil .SatoshiPerBitcoin
451403
452404 // Generate a unique name for each new node.
453405 aliceName := genRandomNodeName ("AliceLnd" )
454406 bobName := genRandomNodeName ("BobLnd" )
455407 carolName := genRandomNodeName ("CarolLnd" )
456408
409+ scidAliasArgs := []string {
410+ "--protocol.option-scid-alias" ,
411+ "--protocol.anchors" ,
412+ }
413+
457414 // Create three new nodes.
458- aliceLnd := newLndNode (aliceName , outputFunds [:], t .lndHarness )
459- bobLnd := newLndNode (bobName , outputFunds [:], t .lndHarness )
460- carolLnd := newLndNode (carolName , outputFunds [:], t .lndHarness )
415+ aliceLnd := t .lndHarness .NewNode (aliceName , scidAliasArgs )
416+ t .lndHarness .FundCoins (fundAmount , aliceLnd )
417+
418+ bobLnd := t .lndHarness .NewNode (bobName , scidAliasArgs )
419+ t .lndHarness .FundCoins (fundAmount , bobLnd )
420+
421+ carolLnd := t .lndHarness .NewNode (carolName , scidAliasArgs )
422+ t .lndHarness .FundCoins (fundAmount , carolLnd )
461423
462424 // Now we want to wait for the nodes to catch up.
463425 t .lndHarness .WaitForBlockchainSync (aliceLnd )
464426 t .lndHarness .WaitForBlockchainSync (bobLnd )
465427 t .lndHarness .WaitForBlockchainSync (carolLnd )
466428
467429 // Now block until both wallets have fully synced up.
468- t .lndHarness .WaitForBalanceConfirmed (aliceLnd , totalAmount )
469- t .lndHarness .WaitForBalanceConfirmed (bobLnd , totalAmount )
470- t .lndHarness .WaitForBalanceConfirmed (carolLnd , totalAmount )
430+ t .lndHarness .WaitForBalanceConfirmed (aliceLnd , fundAmount )
431+ t .lndHarness .WaitForBalanceConfirmed (bobLnd , fundAmount )
432+ t .lndHarness .WaitForBalanceConfirmed (carolLnd , fundAmount )
471433
472434 // Connect the nodes.
473435 t .lndHarness .EnsureConnected (aliceLnd , bobLnd )
474436 t .lndHarness .EnsureConnected (bobLnd , carolLnd )
475437
476- // Open channels between the nodes: Alice -> Bob -> Carol
438+ // Open channels between the nodes: Alice -> Bob -> Carol.
477439 const chanAmt = btcutil .Amount (300000 )
478440 p := lntest.OpenChannelParams {Amt : chanAmt }
479441 reqs := []* lntest.OpenChannelRequest {
@@ -486,6 +448,9 @@ func newRfqTestScenario(t *harnessTest) *rfqTestScenario {
486448 // Make sure Alice is aware of channel Bob -> Carol.
487449 t .lndHarness .AssertTopologyChannelOpen (aliceLnd , bobCarolChannel )
488450
451+ // Make sure Carol is aware of channel Alice -> Bob.
452+ t .lndHarness .AssertTopologyChannelOpen (carolLnd , aliceBobChannel )
453+
489454 // Create tapd nodes.
490455 aliceTapd := setupTapdHarness (t .t , t , aliceLnd , t .universeServer )
491456 bobTapd := setupTapdHarness (t .t , t , bobLnd , t .universeServer )
0 commit comments