Skip to content

Commit

Permalink
tapchannel: add test case for btc invoice paid with assets
Browse files Browse the repository at this point in the history
In this commit we add an extra test case that checks if the
AuxInvoiceManager will reject the asset HTLCs that pay to a btc invoice.
We also do some housekeeping (commonly used vars, comments) across the
other test cases.
  • Loading branch information
GeorgeTsagk committed Dec 6, 2024
1 parent 15e2b2e commit 3a281fd
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions tapchannel/aux_invoice_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import (
)

const (
// The test channel ID to use across the test cases.
testChanID = 1234

// maxRandomInvoiceValueMSat is the maximum invoice value in mSAT to be
// generated by the property based tests.
maxRandomInvoiceValueMSat = 100_000_000_000
Expand All @@ -52,12 +49,20 @@ var (
// The node ID to be used for the RFQ peer.
testNodeID = route.Vertex{1, 2, 3}

// The asset rate value to use across tests.
assetRate = big.NewInt(100_000)

// The asset rate struct based on the assetRate value.
testAssetRate = rfqmath.FixedPoint[rfqmath.BigInt]{
Coefficient: rfqmath.NewBigInt(assetRate),
Scale: 0,
}

// The test RFQ ID to use across tests.
testRfqID = dummyRfqID(31)

// The test RFQ SCID that is derived from testRfqID.
testScid = testRfqID.Scid()
)

// mockRfqManager mocks the interface of the rfq manager required by the aux
Expand Down Expand Up @@ -293,7 +298,7 @@ func TestAuxInvoiceManager(t *testing.T) {
},
},
buyQuotes: map[rfq.SerialisedScid]rfqmsg.BuyAccept{
testChanID: {
testScid: {
Peer: testNodeID,
},
},
Expand All @@ -315,7 +320,7 @@ func TestAuxInvoiceManager(t *testing.T) {
},
},
buyQuotes: map[rfq.SerialisedScid]rfqmsg.BuyAccept{
testChanID: {
testScid: {
Peer: testNodeID,
},
},
Expand All @@ -335,7 +340,7 @@ func TestAuxInvoiceManager(t *testing.T) {
dummyAssetID(1),
3,
),
}, fn.Some(dummyRfqID(31)),
}, fn.Some(testRfqID),
),
},
},
Expand All @@ -345,7 +350,7 @@ func TestAuxInvoiceManager(t *testing.T) {
},
},
buyQuotes: rfq.BuyAcceptMap{
fn.Ptr(dummyRfqID(31)).Scid(): {
testScid: {
Peer: testNodeID,
AssetRate: rfqmsg.NewAssetRate(
testAssetRate, time.Now(),
Expand All @@ -368,7 +373,7 @@ func TestAuxInvoiceManager(t *testing.T) {
dummyAssetID(1),
4,
),
}, fn.Some(dummyRfqID(31)),
}, fn.Some(testRfqID),
),
ExitHtlcAmt: 1234,
},
Expand All @@ -379,14 +384,39 @@ func TestAuxInvoiceManager(t *testing.T) {
},
},
buyQuotes: rfq.BuyAcceptMap{
fn.Ptr(dummyRfqID(31)).Scid(): {
testScid: {
Peer: testNodeID,
AssetRate: rfqmsg.NewAssetRate(
testAssetRate, time.Now(),
),
},
},
},
{
name: "btc invoice, custom records",
requests: []lndclient.InvoiceHtlcModifyRequest{
{
Invoice: &lnrpc.Invoice{
ValueMsat: 10_000_000,
PaymentAddr: []byte{1, 1, 1},
},
WireCustomRecords: newWireCustomRecords(
t, []*rfqmsg.AssetBalance{
rfqmsg.NewAssetBalance(
dummyAssetID(1),
4,
),
}, fn.Some(testRfqID),
),
ExitHtlcAmt: 1234,
},
},
responses: []lndclient.InvoiceHtlcModifyResponse{
{
CancelSet: true,
},
},
},
}

for _, testCase := range testCases {
Expand Down Expand Up @@ -761,8 +791,8 @@ func testRouteHints() []*lnrpc.RouteHint {
NodeId: route.Vertex{1, 1, 1}.String(),
},
{
ChanId: 1234,
NodeId: route.Vertex{1, 2, 3}.String(),
ChanId: uint64(testScid),
NodeId: testNodeID.String(),
},
},
},
Expand Down

0 comments on commit 3a281fd

Please sign in to comment.