Skip to content

Commit 2cb1bb2

Browse files
committed
itest: use groupkey on grouped asset & liquidity edge cases itests
We add support for group keys on payments and invoices across the itests. This includes all the required helpers and optional arguments to make adding invoices and sending payments group-key enabled. In order to run the liquidity edge cases twice, once using only asset IDs and once using only group keys, we need to extract the main logic into a re-usable function that has the group key option on the top level. If the group key flag is set, then we append the respective group key opt to the payment & invoice related calls.
1 parent d097445 commit 2cb1bb2

File tree

3 files changed

+214
-51
lines changed

3 files changed

+214
-51
lines changed

itest/assets_test.go

+67-5
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,12 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
741741
opt(cfg)
742742
}
743743

744+
// Nullify assetID if group key is set. RPC methods won't accept both so
745+
// let's prioritize the group key if set.
746+
if len(cfg.groupKey) > 0 {
747+
assetID = nil
748+
}
749+
744750
ctxb := context.Background()
745751
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
746752
defer cancel()
@@ -770,6 +776,7 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
770776
stream, err := srcTapd.SendPayment(ctxt, &tchrpc.SendPaymentRequest{
771777
AssetId: assetID,
772778
AssetAmount: amt,
779+
GroupKey: cfg.groupKey,
773780
PaymentRequest: sendReq,
774781
})
775782
require.NoError(t, err)
@@ -942,6 +949,7 @@ type payConfig struct {
942949
payStatus lnrpc.Payment_PaymentStatus
943950
failureReason lnrpc.PaymentFailureReason
944951
rfq fn.Option[rfqmsg.ID]
952+
groupKey []byte
945953
}
946954

947955
func defaultPayConfig() *payConfig {
@@ -956,6 +964,12 @@ func defaultPayConfig() *payConfig {
956964

957965
type payOpt func(*payConfig)
958966

967+
func withGroupKey(groupKey []byte) payOpt {
968+
return func(c *payConfig) {
969+
c.groupKey = groupKey
970+
}
971+
}
972+
959973
func withSmallShards() payOpt {
960974
return func(c *payConfig) {
961975
c.smallShards = true
@@ -1010,6 +1024,12 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10101024
opt(cfg)
10111025
}
10121026

1027+
// Nullify assetID if group key is set. RPC methods won't accept both so
1028+
// let's prioritize the group key if set.
1029+
if len(cfg.groupKey) > 0 {
1030+
assetID = []byte{}
1031+
}
1032+
10131033
ctxb := context.Background()
10141034
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
10151035
defer cancel()
@@ -1041,6 +1061,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10411061
stream, err := payerTapd.SendPayment(ctxt, &tchrpc.SendPaymentRequest{
10421062
AssetId: assetID,
10431063
PeerPubkey: rfqPeer.PubKey[:],
1064+
GroupKey: cfg.groupKey,
10441065
PaymentRequest: sendReq,
10451066
RfqId: rfqBytes,
10461067
AllowOverpay: cfg.allowOverpay,
@@ -1102,6 +1123,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
11021123

11031124
type invoiceConfig struct {
11041125
errSubStr string
1126+
groupKey []byte
11051127
}
11061128

11071129
func defaultInvoiceConfig() *invoiceConfig {
@@ -1118,6 +1140,12 @@ func withInvoiceErrSubStr(errSubStr string) invoiceOpt {
11181140
}
11191141
}
11201142

1143+
func withInvGroupKey(groupKey []byte) invoiceOpt {
1144+
return func(c *invoiceConfig) {
1145+
c.groupKey = groupKey
1146+
}
1147+
}
1148+
11211149
func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11221150
assetAmount uint64, assetID []byte,
11231151
opts ...invoiceOpt) *lnrpc.AddInvoiceResponse {
@@ -1127,6 +1155,12 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11271155
opt(cfg)
11281156
}
11291157

1158+
// Nullify assetID if group key is set. RPC methods won't accept both so
1159+
// let's prioritize the group key if set.
1160+
if len(cfg.groupKey) > 0 {
1161+
assetID = []byte{}
1162+
}
1163+
11301164
ctxb := context.Background()
11311165
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
11321166
defer cancel()
@@ -1141,6 +1175,7 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11411175

11421176
resp, err := dstTapd.AddInvoice(ctxt, &tchrpc.AddInvoiceRequest{
11431177
AssetId: assetID,
1178+
GroupKey: cfg.groupKey,
11441179
AssetAmount: assetAmount,
11451180
PeerPubkey: dstRfqPeer.PubKey[:],
11461181
InvoiceRequest: &lnrpc.Invoice{
@@ -1185,7 +1220,7 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11851220
// individual HTLCs that arrived for it and that they show the correct asset
11861221
// amounts for the given ID when decoded.
11871222
func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
1188-
addedInvoice *lnrpc.AddInvoiceResponse, assetID []byte,
1223+
addedInvoice *lnrpc.AddInvoiceResponse, assetID []byte, groupID []byte,
11891224
assetAmount uint64) {
11901225

11911226
ctxb := context.Background()
@@ -1204,7 +1239,14 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
12041239

12051240
t.Logf("Asset invoice: %v", toProtoJSON(t, invoice))
12061241

1207-
targetID := hex.EncodeToString(assetID)
1242+
var targetID string
1243+
switch {
1244+
case len(groupID) > 0:
1245+
targetID = hex.EncodeToString(groupID)
1246+
1247+
case len(assetID) > 0:
1248+
targetID = hex.EncodeToString(assetID)
1249+
}
12081250

12091251
var totalAssetAmount uint64
12101252
for _, htlc := range invoice.Htlcs {
@@ -1231,7 +1273,7 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
12311273
// individual HTLCs that arrived for it and that they show the correct asset
12321274
// amounts for the given ID when decoded.
12331275
func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
1234-
assetID []byte, assetAmount uint64) {
1276+
assetID []byte, groupID []byte, assetAmount uint64) {
12351277

12361278
ctxb := context.Background()
12371279
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -1252,7 +1294,14 @@ func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
12521294

12531295
t.Logf("Asset payment: %v", toProtoJSON(t, payment))
12541296

1255-
targetID := hex.EncodeToString(assetID)
1297+
var targetID string
1298+
switch {
1299+
case len(groupID) > 0:
1300+
targetID = hex.EncodeToString(groupID)
1301+
1302+
case len(assetID) > 0:
1303+
targetID = hex.EncodeToString(assetID)
1304+
}
12561305

12571306
var totalAssetAmount uint64
12581307
for _, htlc := range payment.Htlcs {
@@ -1282,7 +1331,19 @@ type assetHodlInvoice struct {
12821331
}
12831332

12841333
func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
1285-
assetAmount uint64, assetID []byte) assetHodlInvoice {
1334+
assetAmount uint64, assetID []byte,
1335+
opts ...invoiceOpt) assetHodlInvoice {
1336+
1337+
cfg := defaultInvoiceConfig()
1338+
for _, opt := range opts {
1339+
opt(cfg)
1340+
}
1341+
1342+
// Nullify assetID if group key is set. RPC methods won't accept both so
1343+
// let's prioritize the group key if set.
1344+
if len(cfg.groupKey) > 0 {
1345+
assetID = []byte{}
1346+
}
12861347

12871348
ctxb := context.Background()
12881349
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -1306,6 +1367,7 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
13061367

13071368
resp, err := dstTapd.AddInvoice(ctxt, &tchrpc.AddInvoiceRequest{
13081369
AssetId: assetID,
1370+
GroupKey: cfg.groupKey,
13091371
AssetAmount: assetAmount,
13101372
PeerPubkey: dstRfqPeer.PubKey[:],
13111373
InvoiceRequest: &lnrpc.Invoice{

0 commit comments

Comments
 (0)