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 ()
@@ -1004,6 +1009,12 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
1004
1009
opt (cfg )
1005
1010
}
1006
1011
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
+
1007
1018
ctxb := context .Background ()
1008
1019
ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
1009
1020
defer cancel ()
@@ -1129,6 +1140,12 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
1129
1140
opt (cfg )
1130
1141
}
1131
1142
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
+
1132
1149
ctxb := context .Background ()
1133
1150
ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
1134
1151
defer cancel ()
@@ -1209,12 +1226,11 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
1209
1226
1210
1227
var targetID string
1211
1228
switch {
1229
+ case len (groupID ) > 0 :
1230
+ targetID = hex .EncodeToString (groupID )
1231
+
1212
1232
case len (assetID ) > 0 :
1213
1233
targetID = hex .EncodeToString (assetID )
1214
-
1215
- case len (groupID ) > 0 :
1216
- groupHash := sha256 .Sum256 (groupID )
1217
- targetID = hex .EncodeToString (groupHash [:])
1218
1234
}
1219
1235
1220
1236
var totalAssetAmount uint64
@@ -1265,12 +1281,11 @@ func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
1265
1281
1266
1282
var targetID string
1267
1283
switch {
1284
+ case len (groupID ) > 0 :
1285
+ targetID = hex .EncodeToString (groupID )
1286
+
1268
1287
case len (assetID ) > 0 :
1269
1288
targetID = hex .EncodeToString (assetID )
1270
-
1271
- case len (groupID ) > 0 :
1272
- groupHash := sha256 .Sum256 (groupID )
1273
- targetID = hex .EncodeToString (groupHash [:])
1274
1289
}
1275
1290
1276
1291
var totalAssetAmount uint64
@@ -1301,7 +1316,19 @@ type assetHodlInvoice struct {
1301
1316
}
1302
1317
1303
1318
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
+ }
1305
1332
1306
1333
ctxb := context .Background ()
1307
1334
ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
@@ -1325,6 +1352,7 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
1325
1352
1326
1353
resp , err := dstTapd .AddInvoice (ctxt , & tchrpc.AddInvoiceRequest {
1327
1354
AssetId : assetID ,
1355
+ GroupKey : cfg .groupKey ,
1328
1356
AssetAmount : assetAmount ,
1329
1357
PeerPubkey : dstRfqPeer .PubKey [:],
1330
1358
InvoiceRequest : & lnrpc.Invoice {
@@ -1363,6 +1391,22 @@ func createAssetHodlInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
1363
1391
}
1364
1392
}
1365
1393
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
+
1366
1410
func waitForSendEvent (t * testing.T ,
1367
1411
sendEvents taprpc.TaprootAssets_SubscribeSendEventsClient ,
1368
1412
expectedState tapfreighter.SendState ) {
0 commit comments