Skip to content

Commit 7ccb618

Browse files
committed
itest: add an asset invoice with sats value reference
1 parent 23f300d commit 7ccb618

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
@@ -1420,6 +1420,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
14201420
type invoiceConfig struct {
14211421
errSubStr string
14221422
groupKey []byte
1423+
msats lnwire.MilliSatoshi
14231424
}
14241425

14251426
func defaultInvoiceConfig() *invoiceConfig {
@@ -1442,6 +1443,12 @@ func withInvGroupKey(groupKey []byte) invoiceOpt {
14421443
}
14431444
}
14441445

1446+
func withMsatAmount(amt uint64) invoiceOpt {
1447+
return func(c *invoiceConfig) {
1448+
c.msats = lnwire.MilliSatoshi(amt)
1449+
}
1450+
}
1451+
14451452
func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
14461453
assetAmount uint64, assetID []byte,
14471454
opts ...invoiceOpt) *lnrpc.AddInvoiceResponse {
@@ -1470,7 +1477,8 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
14701477
InvoiceRequest: &lnrpc.Invoice{
14711478
Memo: fmt.Sprintf("this is an asset invoice for "+
14721479
"%d units", assetAmount),
1473-
Expiry: timeoutSeconds,
1480+
Expiry: timeoutSeconds,
1481+
ValueMsat: int64(cfg.msats),
14741482
},
14751483
}
14761484

@@ -1502,11 +1510,20 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
15021510

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

1505-
assetUnits := rfqmath.NewBigIntFixedPoint(assetAmount, 0)
1506-
numMSats := rfqmath.UnitsToMilliSatoshi(assetUnits, *rate)
1507-
mSatPerUnit := float64(decodedInvoice.NumMsat) / float64(assetAmount)
1513+
var mSatPerUnit float64
1514+
1515+
if cfg.msats > 0 {
1516+
require.EqualValues(t, decodedInvoice.NumMsat, cfg.msats)
1517+
units := rfqmath.MilliSatoshiToUnits(cfg.msats, *rate)
15081518

1509-
require.EqualValues(t, numMSats, decodedInvoice.NumMsat)
1519+
mSatPerUnit = float64(cfg.msats) / float64(units.ToUint64())
1520+
} else {
1521+
assetUnits := rfqmath.NewBigIntFixedPoint(assetAmount, 0)
1522+
numMSats := rfqmath.UnitsToMilliSatoshi(assetUnits, *rate)
1523+
mSatPerUnit = float64(decodedInvoice.NumMsat) / float64(assetAmount)
1524+
1525+
require.EqualValues(t, numMSats, decodedInvoice.NumMsat)
1526+
}
15101527

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

itest/litd_custom_channels_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -3038,10 +3038,13 @@ func testCustomChannelsLiquidtyEdgeCasesCore(ctx context.Context,
30383038
assertNumHtlcs(t.t, erin, 0)
30393039
assertNumHtlcs(t.t, fabia, 0)
30403040

3041-
// Now Fabia creates the normal invoice.
3041+
// Now Fabia creates another invoice. We also use a fixed msat value for
3042+
// the invoice. Since our itest oracle evaluates every asset to about
3043+
// 17.1 sats, this invoice should be a bit below 10k assets, so roughly
3044+
// the same volume as the previous invoice we just cancelled.
30423045
invoiceResp = createAssetInvoice(
3043-
t.t, erin, fabia, 10_000, assetID,
3044-
withInvGroupKey(groupID),
3046+
t.t, erin, fabia, 0, assetID, withInvGroupKey(groupID),
3047+
withMsatAmount(170_000_000),
30453048
)
30463049

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

0 commit comments

Comments
 (0)