Skip to content

Commit e75169c

Browse files
committed
itest: add groupkey mode to liquidity edge cases
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 957dec6 commit e75169c

File tree

3 files changed

+229
-56
lines changed

3 files changed

+229
-56
lines changed

itest/assets_test.go

+54-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"context"
66
"crypto/rand"
7-
"crypto/sha256"
87
"encoding/hex"
98
"encoding/json"
109
"fmt"
@@ -727,6 +726,12 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
727726
opt(cfg)
728727
}
729728

729+
// Nullify assetID if group key is set. RPC methods won't accept both so
730+
// let's prioritize the group key if set.
731+
if len(cfg.groupKey) > 0 {
732+
assetID = []byte{}
733+
}
734+
730735
ctxb := context.Background()
731736
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
732737
defer cancel()
@@ -1014,6 +1019,12 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10141019
opt(cfg)
10151020
}
10161021

1022+
// Nullify assetID if group key is set. RPC methods won't accept both so
1023+
// let's prioritize the group key if set.
1024+
if len(cfg.groupKey) > 0 {
1025+
assetID = []byte{}
1026+
}
1027+
10171028
ctxb := context.Background()
10181029
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
10191030
defer cancel()
@@ -1139,6 +1150,12 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11391150
opt(cfg)
11401151
}
11411152

1153+
// Nullify assetID if group key is set. RPC methods won't accept both so
1154+
// let's prioritize the group key if set.
1155+
if len(cfg.groupKey) > 0 {
1156+
assetID = []byte{}
1157+
}
1158+
11421159
ctxb := context.Background()
11431160
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
11441161
defer cancel()
@@ -1219,12 +1236,11 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
12191236

12201237
var targetID string
12211238
switch {
1239+
case len(groupID) > 0:
1240+
targetID = hex.EncodeToString(groupID)
1241+
12221242
case len(assetID) > 0:
12231243
targetID = hex.EncodeToString(assetID)
1224-
1225-
case len(groupID) > 0:
1226-
groupHash := sha256.Sum256(groupID)
1227-
targetID = hex.EncodeToString(groupHash[:])
12281244
}
12291245

12301246
var totalAssetAmount uint64
@@ -1275,12 +1291,11 @@ func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
12751291

12761292
var targetID string
12771293
switch {
1294+
case len(groupID) > 0:
1295+
targetID = hex.EncodeToString(groupID)
1296+
12781297
case len(assetID) > 0:
12791298
targetID = hex.EncodeToString(assetID)
1280-
1281-
case len(groupID) > 0:
1282-
groupHash := sha256.Sum256(groupID)
1283-
targetID = hex.EncodeToString(groupHash[:])
12841299
}
12851300

12861301
var totalAssetAmount uint64
@@ -1311,7 +1326,19 @@ type assetHodlInvoice struct {
13111326
}
13121327

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

13161343
ctxb := context.Background()
13171344
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -1335,6 +1362,7 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
13351362

13361363
resp, err := dstTapd.AddInvoice(ctxt, &tchrpc.AddInvoiceRequest{
13371364
AssetId: assetID,
1365+
GroupKey: cfg.groupKey,
13381366
AssetAmount: assetAmount,
13391367
PeerPubkey: dstRfqPeer.PubKey[:],
13401368
InvoiceRequest: &lnrpc.Invoice{
@@ -1373,6 +1401,22 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
13731401
}
13741402
}
13751403

1404+
// addGroupModeOpt may add a group key option to the opts array, if the group
1405+
// mode boolean is true.
1406+
func addGroupModeOpt(opts *[]payOpt, groupMode bool, groupID []byte) {
1407+
if groupMode {
1408+
*opts = append(*opts, withGroupKey(groupID))
1409+
}
1410+
}
1411+
1412+
// addGroupModeInvOpt may add a group key option to the opts array, if the group
1413+
// mode boolean is true.
1414+
func addGroupModeInvOpt(opts *[]invoiceOpt, groupMode bool, groupID []byte) {
1415+
if groupMode {
1416+
*opts = append(*opts, withInvGroupKey(groupID))
1417+
}
1418+
}
1419+
13761420
func waitForSendEvent(t *testing.T,
13771421
sendEvents taprpc.TaprootAssets_SubscribeSendEventsClient,
13781422
expectedState tapfreighter.SendState) {

0 commit comments

Comments
 (0)