Skip to content

Commit 45a38e9

Browse files
committed
itest: add an asset invoice with sats value reference
1 parent 98e3579 commit 45a38e9

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

itest/assets_test.go

+23-6
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
11021102

11031103
type invoiceConfig struct {
11041104
errSubStr string
1105+
msats lnwire.MilliSatoshi
11051106
}
11061107

11071108
func defaultInvoiceConfig() *invoiceConfig {
@@ -1118,6 +1119,12 @@ func withInvoiceErrSubStr(errSubStr string) invoiceOpt {
11181119
}
11191120
}
11201121

1122+
func withMsatAmount(amt uint64) invoiceOpt {
1123+
return func(c *invoiceConfig) {
1124+
c.msats = lnwire.MilliSatoshi(amt)
1125+
}
1126+
}
1127+
11211128
func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11221129
assetAmount uint64, assetID []byte,
11231130
opts ...invoiceOpt) *lnrpc.AddInvoiceResponse {
@@ -1146,7 +1153,8 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11461153
InvoiceRequest: &lnrpc.Invoice{
11471154
Memo: fmt.Sprintf("this is an asset invoice for "+
11481155
"%d units", assetAmount),
1149-
Expiry: timeoutSeconds,
1156+
Expiry: timeoutSeconds,
1157+
ValueMsat: int64(cfg.msats),
11501158
},
11511159
})
11521160
if cfg.errSubStr != "" {
@@ -1168,11 +1176,20 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11681176

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

1171-
assetUnits := rfqmath.NewBigIntFixedPoint(assetAmount, 0)
1172-
numMSats := rfqmath.UnitsToMilliSatoshi(assetUnits, *rate)
1173-
mSatPerUnit := float64(decodedInvoice.NumMsat) / float64(assetAmount)
1179+
var mSatPerUnit float64
1180+
1181+
if cfg.msats > 0 {
1182+
require.EqualValues(t, decodedInvoice.NumMsat, cfg.msats)
1183+
units := rfqmath.MilliSatoshiToUnits(cfg.msats, *rate)
11741184

1175-
require.EqualValues(t, numMSats, decodedInvoice.NumMsat)
1185+
mSatPerUnit = float64(cfg.msats) / float64(units.ToUint64())
1186+
} else {
1187+
assetUnits := rfqmath.NewBigIntFixedPoint(assetAmount, 0)
1188+
numMSats := rfqmath.UnitsToMilliSatoshi(assetUnits, *rate)
1189+
mSatPerUnit = float64(decodedInvoice.NumMsat) / float64(assetAmount)
1190+
1191+
require.EqualValues(t, numMSats, decodedInvoice.NumMsat)
1192+
}
11761193

11771194
t.Logf("Got quote for %d mSats at %3f msat/unit from peer %x with "+
11781195
"SCID %d", decodedInvoice.NumMsat, mSatPerUnit,
@@ -1334,7 +1351,7 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
13341351

13351352
require.EqualValues(t, uint64(numMSats), uint64(decodedInvoice.NumMsat))
13361353

1337-
t.Logf("Got quote for %d sats at %v msat/unit from peer %x with SCID "+
1354+
t.Logf("Got quote for %d msats at %v msat/unit from peer %x with SCID "+
13381355
"%d", decodedInvoice.NumMsat, mSatPerUnit, dstRfqPeer.PubKey[:],
13391356
resp.AcceptedBuyQuote.Scid)
13401357

itest/litd_custom_channels_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -2094,9 +2094,12 @@ func testCustomChannelsLiquidityEdgeCases(ctx context.Context,
20942094
assertNumHtlcs(t.t, erin, 0)
20952095
assertNumHtlcs(t.t, fabia, 0)
20962096

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

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

0 commit comments

Comments
 (0)