Skip to content

Commit 673009d

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 4768ba2 commit 673009d

File tree

3 files changed

+235
-56
lines changed

3 files changed

+235
-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()
@@ -1004,6 +1009,12 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10041009
opt(cfg)
10051010
}
10061011

1012+
// Nullify assetID if group key is set. RPC methods won't accept both so
1013+
// let's prioritize the group key if set.
1014+
if len(cfg.groupKey) > 0 {
1015+
assetID = []byte{}
1016+
}
1017+
10071018
ctxb := context.Background()
10081019
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
10091020
defer cancel()
@@ -1129,6 +1140,12 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11291140
opt(cfg)
11301141
}
11311142

1143+
// Nullify assetID if group key is set. RPC methods won't accept both so
1144+
// let's prioritize the group key if set.
1145+
if len(cfg.groupKey) > 0 {
1146+
assetID = []byte{}
1147+
}
1148+
11321149
ctxb := context.Background()
11331150
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
11341151
defer cancel()
@@ -1209,12 +1226,11 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
12091226

12101227
var targetID string
12111228
switch {
1229+
case len(groupID) > 0:
1230+
targetID = hex.EncodeToString(groupID)
1231+
12121232
case len(assetID) > 0:
12131233
targetID = hex.EncodeToString(assetID)
1214-
1215-
case len(groupID) > 0:
1216-
groupHash := sha256.Sum256(groupID)
1217-
targetID = hex.EncodeToString(groupHash[:])
12181234
}
12191235

12201236
var totalAssetAmount uint64
@@ -1265,12 +1281,11 @@ func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
12651281

12661282
var targetID string
12671283
switch {
1284+
case len(groupID) > 0:
1285+
targetID = hex.EncodeToString(groupID)
1286+
12681287
case len(assetID) > 0:
12691288
targetID = hex.EncodeToString(assetID)
1270-
1271-
case len(groupID) > 0:
1272-
groupHash := sha256.Sum256(groupID)
1273-
targetID = hex.EncodeToString(groupHash[:])
12741289
}
12751290

12761291
var totalAssetAmount uint64
@@ -1301,7 +1316,19 @@ type assetHodlInvoice struct {
13011316
}
13021317

13031318
func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
1304-
assetAmount uint64, assetID []byte) assetHodlInvoice {
1319+
assetAmount uint64, assetID []byte,
1320+
opts ...invoiceOpt) assetHodlInvoice {
1321+
1322+
cfg := defaultInvoiceConfig()
1323+
for _, opt := range opts {
1324+
opt(cfg)
1325+
}
1326+
1327+
// Nullify assetID if group key is set. RPC methods won't accept both so
1328+
// let's prioritize the group key if set.
1329+
if len(cfg.groupKey) > 0 {
1330+
assetID = []byte{}
1331+
}
13051332

13061333
ctxb := context.Background()
13071334
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -1325,6 +1352,7 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
13251352

13261353
resp, err := dstTapd.AddInvoice(ctxt, &tchrpc.AddInvoiceRequest{
13271354
AssetId: assetID,
1355+
GroupKey: cfg.groupKey,
13281356
AssetAmount: assetAmount,
13291357
PeerPubkey: dstRfqPeer.PubKey[:],
13301358
InvoiceRequest: &lnrpc.Invoice{
@@ -1363,6 +1391,22 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
13631391
}
13641392
}
13651393

1394+
// addGroupModeOpt may add a group key option to the opts array, if the group
1395+
// mode boolean is true.
1396+
func addGroupModeOpt(opts *[]payOpt, groupMode bool, groupID []byte) {
1397+
if groupMode {
1398+
*opts = append(*opts, withGroupKey(groupID))
1399+
}
1400+
}
1401+
1402+
// addGroupModeInvOpt may add a group key option to the opts array, if the group
1403+
// mode boolean is true.
1404+
func addGroupModeInvOpt(opts *[]invoiceOpt, groupMode bool, groupID []byte) {
1405+
if groupMode {
1406+
*opts = append(*opts, withInvGroupKey(groupID))
1407+
}
1408+
}
1409+
13661410
func waitForSendEvent(t *testing.T,
13671411
sendEvents taprpc.TaprootAssets_SubscribeSendEventsClient,
13681412
expectedState tapfreighter.SendState) {

0 commit comments

Comments
 (0)