Skip to content

Commit 43afd50

Browse files
committed
tapchannel: add group key tests to AuxInvoiceManager
Adds some coverage to the invoice manager unit tests, which involve an RFQ quote over a group key, plus an HTLC with multiple asset balances, which may belong or not to the group.
1 parent 4372c19 commit 43afd50

File tree

1 file changed

+109
-6
lines changed

1 file changed

+109
-6
lines changed

tapchannel/aux_invoice_manager_test.go

+109-6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ var (
6363

6464
// The test RFQ SCID that is derived from testRfqID.
6565
testScid = testRfqID.Scid()
66+
67+
// The common asset ID used on test cases.
68+
assetID = dummyAssetID(1)
69+
70+
// The asset ID of the first asset that is considered part of the group.
71+
groupAssetID_1 = dummyAssetID(41)
72+
73+
// The asset ID of the second asset that is considered part of the
74+
// group.
75+
groupAssetID_2 = dummyAssetID(42)
76+
77+
// The specifier based on the common asset ID.
78+
assetSpecifier = asset.NewSpecifierFromId(assetID)
79+
80+
// The specifier based on a dummy generated group key.
81+
groupSpecifier = asset.NewSpecifierFromGroupKey(*pubKeyFromUint64(1337))
6682
)
6783

6884
// mockRfqManager mocks the interface of the rfq manager required by the aux
@@ -95,7 +111,11 @@ func (m *mockRfqManager) AssetMatchesSpecifier(ctx context.Context,
95111

96112
switch {
97113
case specifier.HasGroupPubKey():
98-
return true, nil
114+
if id == groupAssetID_1 || id == groupAssetID_2 {
115+
return true, nil
116+
}
117+
118+
return false, nil
99119

100120
case specifier.HasId():
101121
return specifier.UnwrapIdToPtr().IsEqual(id), nil
@@ -292,11 +312,6 @@ func (m *mockHtlcModifierProperty) HtlcModifier(ctx context.Context,
292312
// TestAuxInvoiceManager tests that the htlc modifications of the aux invoice
293313
// manager align with our expectations.
294314
func TestAuxInvoiceManager(t *testing.T) {
295-
var (
296-
assetID = dummyAssetID(1)
297-
assetSpecifier = asset.NewSpecifierFromId(assetID)
298-
)
299-
300315
testCases := []struct {
301316
name string
302317
buyQuotes rfq.BuyAcceptMap
@@ -494,6 +509,94 @@ func TestAuxInvoiceManager(t *testing.T) {
494509
},
495510
},
496511
},
512+
{
513+
name: "asset invoice, group key rfq",
514+
requests: []lndclient.InvoiceHtlcModifyRequest{
515+
{
516+
Invoice: &lnrpc.Invoice{
517+
RouteHints: testRouteHints(),
518+
ValueMsat: 20_000_000,
519+
PaymentAddr: []byte{1, 1, 1},
520+
},
521+
WireCustomRecords: newWireCustomRecords(
522+
t, []*rfqmsg.AssetBalance{
523+
// Balance asset ID
524+
// belongs to group.
525+
rfqmsg.NewAssetBalance(
526+
groupAssetID_1,
527+
3,
528+
),
529+
// Balance asset ID
530+
// belongs to group.
531+
rfqmsg.NewAssetBalance(
532+
groupAssetID_2,
533+
4,
534+
),
535+
}, fn.Some(testRfqID),
536+
),
537+
},
538+
},
539+
responses: []lndclient.InvoiceHtlcModifyResponse{
540+
{
541+
AmtPaid: 3_000_000 + 4_000_000,
542+
},
543+
},
544+
buyQuotes: rfq.BuyAcceptMap{
545+
testScid: {
546+
Peer: testNodeID,
547+
AssetRate: rfqmsg.NewAssetRate(
548+
testAssetRate, time.Now(),
549+
),
550+
Request: rfqmsg.BuyRequest{
551+
AssetSpecifier: groupSpecifier,
552+
},
553+
},
554+
},
555+
},
556+
{
557+
name: "asset invoice, group key rfq, bad htlc",
558+
requests: []lndclient.InvoiceHtlcModifyRequest{
559+
{
560+
Invoice: &lnrpc.Invoice{
561+
RouteHints: testRouteHints(),
562+
ValueMsat: 20_000_000,
563+
PaymentAddr: []byte{1, 1, 1},
564+
},
565+
WireCustomRecords: newWireCustomRecords(
566+
t, []*rfqmsg.AssetBalance{
567+
// Balance asset ID does
568+
// not belong to group.
569+
rfqmsg.NewAssetBalance(
570+
dummyAssetID(2),
571+
3,
572+
),
573+
// Balance asset ID does
574+
// not belong to group.
575+
rfqmsg.NewAssetBalance(
576+
dummyAssetID(3),
577+
4,
578+
),
579+
}, fn.Some(testRfqID),
580+
),
581+
},
582+
},
583+
responses: []lndclient.InvoiceHtlcModifyResponse{
584+
{
585+
CancelSet: true,
586+
},
587+
},
588+
buyQuotes: rfq.BuyAcceptMap{
589+
testScid: {
590+
Peer: testNodeID,
591+
AssetRate: rfqmsg.NewAssetRate(
592+
testAssetRate, time.Now(),
593+
),
594+
Request: rfqmsg.BuyRequest{
595+
AssetSpecifier: groupSpecifier,
596+
},
597+
},
598+
},
599+
},
497600
}
498601

499602
for _, testCase := range testCases {

0 commit comments

Comments
 (0)