4
4
"bytes"
5
5
"context"
6
6
"crypto/rand"
7
- "crypto/sha256"
8
7
"encoding/hex"
9
8
"encoding/json"
10
9
"fmt"
@@ -727,6 +726,12 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
727
726
opt (cfg )
728
727
}
729
728
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
+
730
735
ctxb := context .Background ()
731
736
ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
732
737
defer cancel ()
@@ -1014,6 +1019,12 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
1014
1019
opt (cfg )
1015
1020
}
1016
1021
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
+
1017
1028
ctxb := context .Background ()
1018
1029
ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
1019
1030
defer cancel ()
@@ -1139,6 +1150,12 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
1139
1150
opt (cfg )
1140
1151
}
1141
1152
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
+
1142
1159
ctxb := context .Background ()
1143
1160
ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
1144
1161
defer cancel ()
@@ -1219,12 +1236,11 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
1219
1236
1220
1237
var targetID string
1221
1238
switch {
1239
+ case len (groupID ) > 0 :
1240
+ targetID = hex .EncodeToString (groupID )
1241
+
1222
1242
case len (assetID ) > 0 :
1223
1243
targetID = hex .EncodeToString (assetID )
1224
-
1225
- case len (groupID ) > 0 :
1226
- groupHash := sha256 .Sum256 (groupID )
1227
- targetID = hex .EncodeToString (groupHash [:])
1228
1244
}
1229
1245
1230
1246
var totalAssetAmount uint64
@@ -1275,12 +1291,11 @@ func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
1275
1291
1276
1292
var targetID string
1277
1293
switch {
1294
+ case len (groupID ) > 0 :
1295
+ targetID = hex .EncodeToString (groupID )
1296
+
1278
1297
case len (assetID ) > 0 :
1279
1298
targetID = hex .EncodeToString (assetID )
1280
-
1281
- case len (groupID ) > 0 :
1282
- groupHash := sha256 .Sum256 (groupID )
1283
- targetID = hex .EncodeToString (groupHash [:])
1284
1299
}
1285
1300
1286
1301
var totalAssetAmount uint64
@@ -1311,7 +1326,19 @@ type assetHodlInvoice struct {
1311
1326
}
1312
1327
1313
1328
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
+ }
1315
1342
1316
1343
ctxb := context .Background ()
1317
1344
ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
@@ -1335,6 +1362,7 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
1335
1362
1336
1363
resp , err := dstTapd .AddInvoice (ctxt , & tchrpc.AddInvoiceRequest {
1337
1364
AssetId : assetID ,
1365
+ GroupKey : cfg .groupKey ,
1338
1366
AssetAmount : assetAmount ,
1339
1367
PeerPubkey : dstRfqPeer .PubKey [:],
1340
1368
InvoiceRequest : & lnrpc.Invoice {
@@ -1373,6 +1401,22 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
1373
1401
}
1374
1402
}
1375
1403
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
+
1376
1420
func waitForSendEvent (t * testing.T ,
1377
1421
sendEvents taprpc.TaprootAssets_SubscribeSendEventsClient ,
1378
1422
expectedState tapfreighter.SendState ) {
0 commit comments