Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
type invoiceConfig struct {
errSubStr string
groupKey []byte
msats lnwire.MilliSatoshi
routeHints []*lnrpc.RouteHint
}

Expand All @@ -1450,6 +1451,12 @@ func withInvGroupKey(groupKey []byte) invoiceOpt {
}
}

func withMsatAmount(amt uint64) invoiceOpt {
return func(c *invoiceConfig) {
c.msats = lnwire.MilliSatoshi(amt)
}
}

func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
assetAmount uint64, assetID []byte,
opts ...invoiceOpt) *lnrpc.AddInvoiceResponse {
Expand Down Expand Up @@ -1478,7 +1485,8 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
InvoiceRequest: &lnrpc.Invoice{
Memo: fmt.Sprintf("this is an asset invoice for "+
"%d units", assetAmount),
Expiry: timeoutSeconds,
Expiry: timeoutSeconds,
ValueMsat: int64(cfg.msats),
},
}

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

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

assetUnits := rfqmath.NewBigIntFixedPoint(assetAmount, 0)
numMSats := rfqmath.UnitsToMilliSatoshi(assetUnits, *rate)
mSatPerUnit := float64(decodedInvoice.NumMsat) / float64(assetAmount)
var mSatPerUnit float64

if cfg.msats > 0 {
require.EqualValues(t, decodedInvoice.NumMsat, cfg.msats)
units := rfqmath.MilliSatoshiToUnits(cfg.msats, *rate)

require.EqualValues(t, numMSats, decodedInvoice.NumMsat)
mSatPerUnit = float64(cfg.msats) / float64(units.ToUint64())
} else {
assetUnits := rfqmath.NewBigIntFixedPoint(assetAmount, 0)
numMSats := rfqmath.UnitsToMilliSatoshi(assetUnits, *rate)
mSatPerUnit = float64(decodedInvoice.NumMsat) /
float64(assetAmount)

require.EqualValues(t, numMSats, decodedInvoice.NumMsat)
}

t.Logf("Got quote for %d mSats at %3f msat/unit from peer %x with "+
"SCID %d", decodedInvoice.NumMsat, mSatPerUnit,
Expand Down
9 changes: 6 additions & 3 deletions itest/litd_custom_channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2679,10 +2679,13 @@ func testCustomChannelsLiquidityEdgeCasesCore(ctx context.Context,
assertNumHtlcs(t.t, erin, 0)
assertNumHtlcs(t.t, fabia, 0)

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

// Now Charlie pays the invoice, again by using the manually specified
Expand Down
Loading