9
9
"time"
10
10
11
11
"github.com/btcsuite/btcd/btcutil"
12
- "github.com/btcsuite/btcd/wire"
13
12
"github.com/lightninglabs/taproot-assets/rfqmsg"
14
13
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
15
14
"github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
@@ -23,6 +22,11 @@ import (
23
22
"github.com/stretchr/testify/require"
24
23
)
25
24
25
+ var (
26
+ // rfqTimeout is the timeout used for RFQ related operations.
27
+ rfqTimeout = 5 * time .Second
28
+ )
29
+
26
30
// testRfqAssetBuyHtlcIntercept tests RFQ negotiation, HTLC interception, and
27
31
// validation between three peers. The RFQ negotiation is initiated by an asset
28
32
// buy request.
@@ -97,7 +101,7 @@ func testRfqAssetBuyHtlcIntercept(t *harnessTest) {
97
101
// node.
98
102
PeerPubKey : ts .BobLnd .PubKey [:],
99
103
100
- TimeoutSeconds : 5 ,
104
+ TimeoutSeconds : uint32 ( rfqTimeout . Seconds ()) ,
101
105
},
102
106
)
103
107
require .NoError (t .t , err , "unable to upsert asset buy order" )
@@ -110,7 +114,7 @@ func testRfqAssetBuyHtlcIntercept(t *harnessTest) {
110
114
111
115
_ , ok := event .Event .(* rfqrpc.RfqEvent_PeerAcceptedBuyQuote )
112
116
require .True (t .t , ok , "unexpected event: %v" , event )
113
- }, defaultWaitTimeout )
117
+ }, rfqTimeout )
114
118
115
119
// Carol should have received an accepted quote from Bob. This accepted
116
120
// quote can be used by Carol to make a payment to Bob.
@@ -203,7 +207,7 @@ func testRfqAssetBuyHtlcIntercept(t *harnessTest) {
203
207
t .t , acceptedQuote .Scid , acceptHtlc .AcceptHtlc .Scid ,
204
208
)
205
209
t .Log ("Bob has accepted the HTLC" )
206
- }, defaultWaitTimeout )
210
+ }, rfqTimeout )
207
211
208
212
// Close event streams.
209
213
err = carolEventNtfns .CloseSend ()
@@ -273,6 +277,8 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
273
277
// tapd node to send a request for quote message to
274
278
// Bob's node.
275
279
PeerPubKey : ts .BobLnd .PubKey [:],
280
+
281
+ TimeoutSeconds : uint32 (rfqTimeout .Seconds ()),
276
282
},
277
283
)
278
284
require .NoError (t .t , err , "unable to upsert asset sell order" )
@@ -285,7 +291,7 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
285
291
286
292
_ , ok := event .Event .(* rfqrpc.RfqEvent_PeerAcceptedSellQuote )
287
293
require .True (t .t , ok , "unexpected event: %v" , event )
288
- }, defaultWaitTimeout )
294
+ }, rfqTimeout )
289
295
290
296
// Alice should have received an accepted quote from Bob. This accepted
291
297
// quote can be used by Alice to make a payment to Bob.
@@ -329,28 +335,21 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
329
335
}
330
336
routeBuildResp := ts .AliceLnd .RPC .BuildRoute (& routeBuildRequest )
331
337
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
-
346
338
// Send the payment to the route.
347
339
t .Log ("Alice paying invoice" )
340
+ var htlcRfqIDTlvType rfqmsg.HtlcRfqIDType
348
341
routeReq := routerrpc.SendToRouteRequest {
349
342
PaymentHash : invoice .RHash ,
350
343
Route : routeBuildResp .Route ,
344
+ FirstHopCustomRecords : map [uint64 ][]byte {
345
+ uint64 (htlcRfqIDTlvType .TypeVal ()): acceptedQuote .Id [:],
346
+ },
351
347
}
352
348
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 )
354
353
355
354
// At this point Bob should have received a HTLC with the asset transfer
356
355
// specific scid. We'll wait for Bob to publish an accept HTLC event and
@@ -362,11 +361,11 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
362
361
363
362
_ , ok := event .Event .(* rfqrpc.RfqEvent_AcceptHtlc )
364
363
require .True (t .t , ok , "unexpected event: %v" , event )
365
- }, defaultWaitTimeout )
364
+ }, rfqTimeout )
366
365
367
366
// Confirm that Carol receives the lightning payment from Alice via Bob.
368
367
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 )
370
369
371
370
// Close event notification streams.
372
371
err = aliceEventNtfns .CloseSend ()
@@ -376,44 +375,6 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
376
375
require .NoError (t .t , err )
377
376
}
378
377
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
-
417
378
// rfqTestScenario is a struct which holds test scenario helper infra.
418
379
type rfqTestScenario struct {
419
380
testHarness * harnessTest
@@ -438,42 +399,43 @@ type rfqTestScenario struct {
438
399
// It also creates new tapd nodes for each of the LND nodes.
439
400
func newRfqTestScenario (t * harnessTest ) * rfqTestScenario {
440
401
// 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
451
403
452
404
// Generate a unique name for each new node.
453
405
aliceName := genRandomNodeName ("AliceLnd" )
454
406
bobName := genRandomNodeName ("BobLnd" )
455
407
carolName := genRandomNodeName ("CarolLnd" )
456
408
409
+ scidAliasArgs := []string {
410
+ "--protocol.option-scid-alias" ,
411
+ "--protocol.anchors" ,
412
+ }
413
+
457
414
// 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 )
461
423
462
424
// Now we want to wait for the nodes to catch up.
463
425
t .lndHarness .WaitForBlockchainSync (aliceLnd )
464
426
t .lndHarness .WaitForBlockchainSync (bobLnd )
465
427
t .lndHarness .WaitForBlockchainSync (carolLnd )
466
428
467
429
// 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 )
471
433
472
434
// Connect the nodes.
473
435
t .lndHarness .EnsureConnected (aliceLnd , bobLnd )
474
436
t .lndHarness .EnsureConnected (bobLnd , carolLnd )
475
437
476
- // Open channels between the nodes: Alice -> Bob -> Carol
438
+ // Open channels between the nodes: Alice -> Bob -> Carol.
477
439
const chanAmt = btcutil .Amount (300000 )
478
440
p := lntest.OpenChannelParams {Amt : chanAmt }
479
441
reqs := []* lntest.OpenChannelRequest {
@@ -486,6 +448,9 @@ func newRfqTestScenario(t *harnessTest) *rfqTestScenario {
486
448
// Make sure Alice is aware of channel Bob -> Carol.
487
449
t .lndHarness .AssertTopologyChannelOpen (aliceLnd , bobCarolChannel )
488
450
451
+ // Make sure Carol is aware of channel Alice -> Bob.
452
+ t .lndHarness .AssertTopologyChannelOpen (carolLnd , aliceBobChannel )
453
+
489
454
// Create tapd nodes.
490
455
aliceTapd := setupTapdHarness (t .t , t , aliceLnd , t .universeServer )
491
456
bobTapd := setupTapdHarness (t .t , t , bobLnd , t .universeServer )
0 commit comments