Skip to content

Commit 9f885cc

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 b9d0cd9 commit 9f885cc

File tree

3 files changed

+215
-52
lines changed

3 files changed

+215
-52
lines changed

Diff for: itest/assets_test.go

+75-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,16 @@ func defaultPayConfig() *payConfig {
956964

957965
type payOpt func(*payConfig)
958966

967+
func withMaybeGroupKey(groupMode bool, groupKey []byte) payOpt {
968+
return func(c *payConfig) {
969+
if !groupMode {
970+
return
971+
}
972+
973+
c.groupKey = groupKey
974+
}
975+
}
976+
959977
func withSmallShards() payOpt {
960978
return func(c *payConfig) {
961979
c.smallShards = true
@@ -1010,6 +1028,12 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10101028
opt(cfg)
10111029
}
10121030

1031+
// Nullify assetID if group key is set. RPC methods won't accept both so
1032+
// let's prioritize the group key if set.
1033+
if len(cfg.groupKey) > 0 {
1034+
assetID = []byte{}
1035+
}
1036+
10131037
ctxb := context.Background()
10141038
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
10151039
defer cancel()
@@ -1041,6 +1065,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10411065
stream, err := payerTapd.SendPayment(ctxt, &tchrpc.SendPaymentRequest{
10421066
AssetId: assetID,
10431067
PeerPubkey: rfqPeer.PubKey[:],
1068+
GroupKey: cfg.groupKey,
10441069
PaymentRequest: sendReq,
10451070
RfqId: rfqBytes,
10461071
AllowOverpay: cfg.allowOverpay,
@@ -1102,6 +1127,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
11021127

11031128
type invoiceConfig struct {
11041129
errSubStr string
1130+
groupKey []byte
11051131
}
11061132

11071133
func defaultInvoiceConfig() *invoiceConfig {
@@ -1118,6 +1144,16 @@ func withInvoiceErrSubStr(errSubStr string) invoiceOpt {
11181144
}
11191145
}
11201146

1147+
func withMaybeInvGroupKey(groupMode bool, groupKey []byte) invoiceOpt {
1148+
return func(c *invoiceConfig) {
1149+
if !groupMode {
1150+
return
1151+
}
1152+
1153+
c.groupKey = groupKey
1154+
}
1155+
}
1156+
11211157
func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11221158
assetAmount uint64, assetID []byte,
11231159
opts ...invoiceOpt) *lnrpc.AddInvoiceResponse {
@@ -1127,6 +1163,12 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11271163
opt(cfg)
11281164
}
11291165

1166+
// Nullify assetID if group key is set. RPC methods won't accept both so
1167+
// let's prioritize the group key if set.
1168+
if len(cfg.groupKey) > 0 {
1169+
assetID = []byte{}
1170+
}
1171+
11301172
ctxb := context.Background()
11311173
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
11321174
defer cancel()
@@ -1141,6 +1183,7 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11411183

11421184
resp, err := dstTapd.AddInvoice(ctxt, &tchrpc.AddInvoiceRequest{
11431185
AssetId: assetID,
1186+
GroupKey: cfg.groupKey,
11441187
AssetAmount: assetAmount,
11451188
PeerPubkey: dstRfqPeer.PubKey[:],
11461189
InvoiceRequest: &lnrpc.Invoice{
@@ -1185,7 +1228,7 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11851228
// individual HTLCs that arrived for it and that they show the correct asset
11861229
// amounts for the given ID when decoded.
11871230
func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
1188-
addedInvoice *lnrpc.AddInvoiceResponse, assetID []byte,
1231+
addedInvoice *lnrpc.AddInvoiceResponse, assetID []byte, groupID []byte,
11891232
assetAmount uint64) {
11901233

11911234
ctxb := context.Background()
@@ -1204,7 +1247,14 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
12041247

12051248
t.Logf("Asset invoice: %v", toProtoJSON(t, invoice))
12061249

1207-
targetID := hex.EncodeToString(assetID)
1250+
var targetID string
1251+
switch {
1252+
case len(groupID) > 0:
1253+
targetID = hex.EncodeToString(groupID)
1254+
1255+
case len(assetID) > 0:
1256+
targetID = hex.EncodeToString(assetID)
1257+
}
12081258

12091259
var totalAssetAmount uint64
12101260
for _, htlc := range invoice.Htlcs {
@@ -1231,7 +1281,7 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
12311281
// individual HTLCs that arrived for it and that they show the correct asset
12321282
// amounts for the given ID when decoded.
12331283
func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
1234-
assetID []byte, assetAmount uint64) {
1284+
assetID []byte, groupID []byte, assetAmount uint64) {
12351285

12361286
ctxb := context.Background()
12371287
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -1252,7 +1302,14 @@ func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
12521302

12531303
t.Logf("Asset payment: %v", toProtoJSON(t, payment))
12541304

1255-
targetID := hex.EncodeToString(assetID)
1305+
var targetID string
1306+
switch {
1307+
case len(groupID) > 0:
1308+
targetID = hex.EncodeToString(groupID)
1309+
1310+
case len(assetID) > 0:
1311+
targetID = hex.EncodeToString(assetID)
1312+
}
12561313

12571314
var totalAssetAmount uint64
12581315
for _, htlc := range payment.Htlcs {
@@ -1282,7 +1339,19 @@ type assetHodlInvoice struct {
12821339
}
12831340

12841341
func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
1285-
assetAmount uint64, assetID []byte) assetHodlInvoice {
1342+
assetAmount uint64, assetID []byte,
1343+
opts ...invoiceOpt) assetHodlInvoice {
1344+
1345+
cfg := defaultInvoiceConfig()
1346+
for _, opt := range opts {
1347+
opt(cfg)
1348+
}
1349+
1350+
// Nullify assetID if group key is set. RPC methods won't accept both so
1351+
// let's prioritize the group key if set.
1352+
if len(cfg.groupKey) > 0 {
1353+
assetID = []byte{}
1354+
}
12861355

12871356
ctxb := context.Background()
12881357
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -1306,6 +1375,7 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
13061375

13071376
resp, err := dstTapd.AddInvoice(ctxt, &tchrpc.AddInvoiceRequest{
13081377
AssetId: assetID,
1378+
GroupKey: cfg.groupKey,
13091379
AssetAmount: assetAmount,
13101380
PeerPubkey: dstRfqPeer.PubKey[:],
13111381
InvoiceRequest: &lnrpc.Invoice{

0 commit comments

Comments
 (0)