Skip to content

Commit d74dd65

Browse files
committed
itest+rfq: re-enable and fix RFQ itests
1 parent 8479baa commit d74dd65

File tree

4 files changed

+60
-98
lines changed

4 files changed

+60
-98
lines changed

itest/assets_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ func testMintAssetNameCollisionError(t *harnessTest) {
330330
require.Equal(t.t, a.GroupKey, b.GroupKey)
331331
require.Equal(t.t, a.GroupAnchor, b.GroupAnchor)
332332
}
333+
333334
// If we attempt to add both assets to the same batch, the second mint
334335
// call should fail.
335336
collideResp, err := t.tapd.MintAsset(ctxt, &assetCollide)
@@ -376,12 +377,11 @@ func testMintAssetNameCollisionError(t *harnessTest) {
376377

377378
// The only change in the returned batch after cancellation should be
378379
// the batch state.
379-
cancelBatch, err := t.tapd.ListBatches(
380-
ctxt, &mintrpc.ListBatchRequest{
381-
Filter: &mintrpc.ListBatchRequest_BatchKey{
382-
BatchKey: collideResp.PendingBatch.BatchKey,
383-
},
384-
})
380+
cancelBatch, err := t.tapd.ListBatches(ctxt, &mintrpc.ListBatchRequest{
381+
Filter: &mintrpc.ListBatchRequest_BatchKey{
382+
BatchKey: collideResp.PendingBatch.BatchKey,
383+
},
384+
})
385385
require.NoError(t.t, err)
386386

387387
require.Len(t.t, cancelBatch.Batches, 1)

itest/rfq_test.go

+42-77
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
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.
418379
type 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.
439400
func 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)

itest/test_list_on_test.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,10 @@ var testCases = []*testCase{
299299
name: "rfq asset buy htlc intercept",
300300
test: testRfqAssetBuyHtlcIntercept,
301301
},
302-
303-
// TODO(ffranr): Re-enable this test once we have a way to set the
304-
// `WireCustomRecords` field in the first hop `UpdateAddHtlc` p2p
305-
// message
306-
//{
307-
// name: "rfq asset sell htlc intercept",
308-
// test: testRfqAssetSellHtlcIntercept,
309-
//},
302+
{
303+
name: "rfq asset sell htlc intercept",
304+
test: testRfqAssetSellHtlcIntercept,
305+
},
310306

311307
{
312308
name: "multi signature on all levels",

rfq/manager.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/lightninglabs/taproot-assets/asset"
1313
"github.com/lightninglabs/taproot-assets/fn"
1414
"github.com/lightninglabs/taproot-assets/rfqmsg"
15+
lfn "github.com/lightningnetwork/lnd/fn"
1516
"github.com/lightningnetwork/lnd/lnutils"
1617
"github.com/lightningnetwork/lnd/lnwire"
1718
"github.com/lightningnetwork/lnd/routing/route"
@@ -521,21 +522,21 @@ func (m *Manager) addScidAlias(scidAlias uint64, assetID asset.ID,
521522
}
522523

523524
// Filter for channels with the given peer.
524-
peerChannels := make([]lndclient.ChannelInfo, 0)
525-
for _, localChan := range localChans {
526-
if localChan.PubKeyBytes == peer {
527-
peerChannels = append(peerChannels, localChan)
528-
}
529-
}
525+
peerChannels := lfn.Filter(func(c lndclient.ChannelInfo) bool {
526+
return c.PubKeyBytes == peer
527+
}, localChans)
530528

531529
// Identify the correct channel to use as the base SCID for the alias
532530
// by inspecting the asset data in the custom channel data.
533531
var (
534532
assetIDStr = assetID.String()
535533
baseSCID uint64
536534
)
537-
538535
for _, localChan := range peerChannels {
536+
if len(localChan.CustomChannelData) == 0 {
537+
continue
538+
}
539+
539540
var assetData rfqmsg.JsonAssetChannel
540541
err = json.Unmarshal(localChan.CustomChannelData, &assetData)
541542
if err != nil {

0 commit comments

Comments
 (0)