Skip to content

Commit c050f67

Browse files
authored
Merge pull request #1020 from GeorgeTsagk/sats-asset-invoices
Asset Invoice with sats value itest
2 parents 4a37e62 + f129384 commit c050f67

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

itest/assets_test.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
14271427
type invoiceConfig struct {
14281428
errSubStr string
14291429
groupKey []byte
1430+
msats lnwire.MilliSatoshi
14301431
routeHints []*lnrpc.RouteHint
14311432
}
14321433

@@ -1450,6 +1451,12 @@ func withInvGroupKey(groupKey []byte) invoiceOpt {
14501451
}
14511452
}
14521453

1454+
func withMsatAmount(amt uint64) invoiceOpt {
1455+
return func(c *invoiceConfig) {
1456+
c.msats = lnwire.MilliSatoshi(amt)
1457+
}
1458+
}
1459+
14531460
func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
14541461
assetAmount uint64, assetID []byte,
14551462
opts ...invoiceOpt) *lnrpc.AddInvoiceResponse {
@@ -1478,7 +1485,8 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
14781485
InvoiceRequest: &lnrpc.Invoice{
14791486
Memo: fmt.Sprintf("this is an asset invoice for "+
14801487
"%d units", assetAmount),
1481-
Expiry: timeoutSeconds,
1488+
Expiry: timeoutSeconds,
1489+
ValueMsat: int64(cfg.msats),
14821490
},
14831491
}
14841492

@@ -1510,11 +1518,21 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
15101518

15111519
t.Logf("Got quote for %v asset units per BTC", rate)
15121520

1513-
assetUnits := rfqmath.NewBigIntFixedPoint(assetAmount, 0)
1514-
numMSats := rfqmath.UnitsToMilliSatoshi(assetUnits, *rate)
1515-
mSatPerUnit := float64(decodedInvoice.NumMsat) / float64(assetAmount)
1521+
var mSatPerUnit float64
1522+
1523+
if cfg.msats > 0 {
1524+
require.EqualValues(t, decodedInvoice.NumMsat, cfg.msats)
1525+
units := rfqmath.MilliSatoshiToUnits(cfg.msats, *rate)
15161526

1517-
require.EqualValues(t, numMSats, decodedInvoice.NumMsat)
1527+
mSatPerUnit = float64(cfg.msats) / float64(units.ToUint64())
1528+
} else {
1529+
assetUnits := rfqmath.NewBigIntFixedPoint(assetAmount, 0)
1530+
numMSats := rfqmath.UnitsToMilliSatoshi(assetUnits, *rate)
1531+
mSatPerUnit = float64(decodedInvoice.NumMsat) /
1532+
float64(assetAmount)
1533+
1534+
require.EqualValues(t, numMSats, decodedInvoice.NumMsat)
1535+
}
15181536

15191537
t.Logf("Got quote for %d mSats at %3f msat/unit from peer %x with "+
15201538
"SCID %d", decodedInvoice.NumMsat, mSatPerUnit,

itest/litd_custom_channels_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,10 +2679,13 @@ func testCustomChannelsLiquidityEdgeCasesCore(ctx context.Context,
26792679
assertNumHtlcs(t.t, erin, 0)
26802680
assertNumHtlcs(t.t, fabia, 0)
26812681

2682-
// Now Fabia creates the normal invoice.
2682+
// Now Fabia creates another invoice. We also use a fixed msat value for
2683+
// the invoice. Since our itest oracle evaluates every asset to about
2684+
// 17.1 sats, this invoice should be a bit below 10k assets, so roughly
2685+
// the same volume as the previous invoice we just cancelled.
26832686
invoiceResp = createAssetInvoice(
2684-
t.t, erin, fabia, 10_000, assetID,
2685-
withInvGroupKey(groupID),
2687+
t.t, erin, fabia, 0, assetID, withInvGroupKey(groupID),
2688+
withMsatAmount(170_000_000),
26862689
)
26872690

26882691
// Now Charlie pays the invoice, again by using the manually specified

0 commit comments

Comments
 (0)