Skip to content

Commit 1304cf2

Browse files
GeorgeTsagkguggero
authored andcommitted
itest: add an asset invoice with sats value reference
1 parent 5d8753a commit 1304cf2

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

itest/assets_test.go

+22-5
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
14251425
type invoiceConfig struct {
14261426
errSubStr string
14271427
groupKey []byte
1428+
msats lnwire.MilliSatoshi
14281429
}
14291430

14301431
func defaultInvoiceConfig() *invoiceConfig {
@@ -1447,6 +1448,12 @@ func withInvGroupKey(groupKey []byte) invoiceOpt {
14471448
}
14481449
}
14491450

1451+
func withMsatAmount(amt uint64) invoiceOpt {
1452+
return func(c *invoiceConfig) {
1453+
c.msats = lnwire.MilliSatoshi(amt)
1454+
}
1455+
}
1456+
14501457
func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
14511458
assetAmount uint64, assetID []byte,
14521459
opts ...invoiceOpt) *lnrpc.AddInvoiceResponse {
@@ -1475,7 +1482,8 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
14751482
InvoiceRequest: &lnrpc.Invoice{
14761483
Memo: fmt.Sprintf("this is an asset invoice for "+
14771484
"%d units", assetAmount),
1478-
Expiry: timeoutSeconds,
1485+
Expiry: timeoutSeconds,
1486+
ValueMsat: int64(cfg.msats),
14791487
},
14801488
}
14811489

@@ -1507,11 +1515,20 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
15071515

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

1510-
assetUnits := rfqmath.NewBigIntFixedPoint(assetAmount, 0)
1511-
numMSats := rfqmath.UnitsToMilliSatoshi(assetUnits, *rate)
1512-
mSatPerUnit := float64(decodedInvoice.NumMsat) / float64(assetAmount)
1518+
var mSatPerUnit float64
1519+
1520+
if cfg.msats > 0 {
1521+
require.EqualValues(t, decodedInvoice.NumMsat, cfg.msats)
1522+
units := rfqmath.MilliSatoshiToUnits(cfg.msats, *rate)
15131523

1514-
require.EqualValues(t, numMSats, decodedInvoice.NumMsat)
1524+
mSatPerUnit = float64(cfg.msats) / float64(units.ToUint64())
1525+
} else {
1526+
assetUnits := rfqmath.NewBigIntFixedPoint(assetAmount, 0)
1527+
numMSats := rfqmath.UnitsToMilliSatoshi(assetUnits, *rate)
1528+
mSatPerUnit = float64(decodedInvoice.NumMsat) / float64(assetAmount)
1529+
1530+
require.EqualValues(t, numMSats, decodedInvoice.NumMsat)
1531+
}
15151532

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

itest/litd_custom_channels_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -2657,10 +2657,13 @@ func testCustomChannelsLiquidtyEdgeCasesCore(ctx context.Context,
26572657
assertNumHtlcs(t.t, erin, 0)
26582658
assertNumHtlcs(t.t, fabia, 0)
26592659

2660-
// Now Fabia creates the normal invoice.
2660+
// Now Fabia creates another invoice. We also use a fixed msat value for
2661+
// the invoice. Since our itest oracle evaluates every asset to about
2662+
// 17.1 sats, this invoice should be a bit below 10k assets, so roughly
2663+
// the same volume as the previous invoice we just cancelled.
26612664
invoiceResp = createAssetInvoice(
2662-
t.t, erin, fabia, 10_000, assetID,
2663-
withInvGroupKey(groupID),
2665+
t.t, erin, fabia, 0, assetID, withInvGroupKey(groupID),
2666+
withMsatAmount(170_000_000),
26642667
)
26652668

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

0 commit comments

Comments
 (0)