Skip to content

Commit 03013b5

Browse files
committed
itest: add an asset invoice with sats value reference
1 parent c7746ed commit 03013b5

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

itest/assets_test.go

+23-6
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
11241124
type invoiceConfig struct {
11251125
errSubStr string
11261126
groupKey []byte
1127+
msats lnwire.MilliSatoshi
11271128
}
11281129

11291130
func defaultInvoiceConfig() *invoiceConfig {
@@ -1146,6 +1147,12 @@ func withInvGroupKey(groupKey []byte) invoiceOpt {
11461147
}
11471148
}
11481149

1150+
func withMsatAmount(amt uint64) invoiceOpt {
1151+
return func(c *invoiceConfig) {
1152+
c.msats = lnwire.MilliSatoshi(amt)
1153+
}
1154+
}
1155+
11491156
func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11501157
assetAmount uint64, assetID []byte,
11511158
opts ...invoiceOpt) *lnrpc.AddInvoiceResponse {
@@ -1181,7 +1188,8 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11811188
InvoiceRequest: &lnrpc.Invoice{
11821189
Memo: fmt.Sprintf("this is an asset invoice for "+
11831190
"%d units", assetAmount),
1184-
Expiry: timeoutSeconds,
1191+
Expiry: timeoutSeconds,
1192+
ValueMsat: int64(cfg.msats),
11851193
},
11861194
})
11871195
if cfg.errSubStr != "" {
@@ -1203,11 +1211,20 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
12031211

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

1206-
assetUnits := rfqmath.NewBigIntFixedPoint(assetAmount, 0)
1207-
numMSats := rfqmath.UnitsToMilliSatoshi(assetUnits, *rate)
1208-
mSatPerUnit := float64(decodedInvoice.NumMsat) / float64(assetAmount)
1214+
var mSatPerUnit float64
1215+
1216+
if cfg.msats > 0 {
1217+
require.EqualValues(t, decodedInvoice.NumMsat, cfg.msats)
1218+
units := rfqmath.MilliSatoshiToUnits(cfg.msats, *rate)
12091219

1210-
require.EqualValues(t, numMSats, decodedInvoice.NumMsat)
1220+
mSatPerUnit = float64(cfg.msats) / float64(units.ToUint64())
1221+
} else {
1222+
assetUnits := rfqmath.NewBigIntFixedPoint(assetAmount, 0)
1223+
numMSats := rfqmath.UnitsToMilliSatoshi(assetUnits, *rate)
1224+
mSatPerUnit = float64(decodedInvoice.NumMsat) / float64(assetAmount)
1225+
1226+
require.EqualValues(t, numMSats, decodedInvoice.NumMsat)
1227+
}
12111228

12121229
t.Logf("Got quote for %d mSats at %3f msat/unit from peer %x with "+
12131230
"SCID %d", decodedInvoice.NumMsat, mSatPerUnit,
@@ -1396,7 +1413,7 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
13961413

13971414
require.EqualValues(t, uint64(numMSats), uint64(decodedInvoice.NumMsat))
13981415

1399-
t.Logf("Got quote for %d sats at %v msat/unit from peer %x with SCID "+
1416+
t.Logf("Got quote for %d msats at %v msat/unit from peer %x with SCID "+
14001417
"%d", decodedInvoice.NumMsat, mSatPerUnit, dstRfqPeer.PubKey[:],
14011418
resp.AcceptedBuyQuote.Scid)
14021419

itest/litd_custom_channels_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -2171,10 +2171,13 @@ func testCustomChannelsLiquidtyEdgeCasesCore(ctx context.Context,
21712171
assertNumHtlcs(t.t, erin, 0)
21722172
assertNumHtlcs(t.t, fabia, 0)
21732173

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

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

0 commit comments

Comments
 (0)