Skip to content

Commit 2d7defe

Browse files
committed
itest: use groupkey payments & invoices in grouped asset test
1 parent a87a302 commit 2d7defe

File tree

2 files changed

+67
-23
lines changed

2 files changed

+67
-23
lines changed

Diff for: itest/assets_test.go

+38-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"crypto/rand"
7+
"crypto/sha256"
78
"encoding/hex"
89
"encoding/json"
910
"fmt"
@@ -754,6 +755,7 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
754755
stream, err := srcTapd.SendPayment(ctxt, &tchrpc.SendPaymentRequest{
755756
AssetId: assetID,
756757
AssetAmount: amt,
758+
GroupKey: cfg.groupKey,
757759
PaymentRequest: sendReq,
758760
})
759761
require.NoError(t, err)
@@ -936,6 +938,7 @@ type payConfig struct {
936938
payStatus lnrpc.Payment_PaymentStatus
937939
failureReason lnrpc.PaymentFailureReason
938940
rfq fn.Option[rfqmsg.ID]
941+
groupKey []byte
939942
}
940943

941944
func defaultPayConfig() *payConfig {
@@ -950,6 +953,12 @@ func defaultPayConfig() *payConfig {
950953

951954
type payOpt func(*payConfig)
952955

956+
func withGroupKey(groupKey []byte) payOpt {
957+
return func(c *payConfig) {
958+
c.groupKey = groupKey
959+
}
960+
}
961+
953962
func withSmallShards() payOpt {
954963
return func(c *payConfig) {
955964
c.smallShards = true
@@ -1035,6 +1044,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10351044
stream, err := payerTapd.SendPayment(ctxt, &tchrpc.SendPaymentRequest{
10361045
AssetId: assetID,
10371046
PeerPubkey: rfqPeer.PubKey[:],
1047+
GroupKey: cfg.groupKey,
10381048
PaymentRequest: sendReq,
10391049
RfqId: rfqBytes,
10401050
AllowOverpay: cfg.allowOverpay,
@@ -1096,6 +1106,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10961106

10971107
type invoiceConfig struct {
10981108
errSubStr string
1109+
groupKey []byte
10991110
}
11001111

11011112
func defaultInvoiceConfig() *invoiceConfig {
@@ -1112,6 +1123,12 @@ func withInvoiceErrSubStr(errSubStr string) invoiceOpt {
11121123
}
11131124
}
11141125

1126+
func withInvGroupKey(groupKey []byte) invoiceOpt {
1127+
return func(c *invoiceConfig) {
1128+
c.groupKey = groupKey
1129+
}
1130+
}
1131+
11151132
func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11161133
assetAmount uint64, assetID []byte,
11171134
opts ...invoiceOpt) *lnrpc.AddInvoiceResponse {
@@ -1135,6 +1152,7 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11351152

11361153
resp, err := dstTapd.AddInvoice(ctxt, &tchrpc.AddInvoiceRequest{
11371154
AssetId: assetID,
1155+
GroupKey: cfg.groupKey,
11381156
AssetAmount: assetAmount,
11391157
PeerPubkey: dstRfqPeer.PubKey[:],
11401158
InvoiceRequest: &lnrpc.Invoice{
@@ -1179,7 +1197,7 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11791197
// individual HTLCs that arrived for it and that they show the correct asset
11801198
// amounts for the given ID when decoded.
11811199
func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
1182-
addedInvoice *lnrpc.AddInvoiceResponse, assetID []byte,
1200+
addedInvoice *lnrpc.AddInvoiceResponse, assetID []byte, groupID []byte,
11831201
assetAmount uint64) {
11841202

11851203
ctxb := context.Background()
@@ -1198,7 +1216,15 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
11981216

11991217
t.Logf("Asset invoice: %v", toProtoJSON(t, invoice))
12001218

1201-
targetID := hex.EncodeToString(assetID)
1219+
var targetID string
1220+
switch {
1221+
case len(assetID) > 0:
1222+
targetID = hex.EncodeToString(assetID)
1223+
1224+
case len(groupID) > 0:
1225+
groupHash := sha256.Sum256(groupID)
1226+
targetID = hex.EncodeToString(groupHash[:])
1227+
}
12021228

12031229
var totalAssetAmount uint64
12041230
for _, htlc := range invoice.Htlcs {
@@ -1225,7 +1251,7 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
12251251
// individual HTLCs that arrived for it and that they show the correct asset
12261252
// amounts for the given ID when decoded.
12271253
func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
1228-
assetID []byte, assetAmount uint64) {
1254+
assetID []byte, groupID []byte, assetAmount uint64) {
12291255

12301256
ctxb := context.Background()
12311257
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -1246,7 +1272,15 @@ func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
12461272

12471273
t.Logf("Asset payment: %v", toProtoJSON(t, payment))
12481274

1249-
targetID := hex.EncodeToString(assetID)
1275+
var targetID string
1276+
switch {
1277+
case len(assetID) > 0:
1278+
targetID = hex.EncodeToString(assetID)
1279+
1280+
case len(groupID) > 0:
1281+
groupHash := sha256.Sum256(groupID)
1282+
targetID = hex.EncodeToString(groupHash[:])
1283+
}
12501284

12511285
var totalAssetAmount uint64
12521286
for _, htlc := range payment.Htlcs {

Diff for: itest/litd_custom_channels_test.go

+29-19
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ func testCustomChannelsLarge(_ context.Context, net *NetworkHarness,
260260
// sender side show the individual HTLCs that arrived for it and that
261261
// they show the correct asset amounts when decoded.
262262
assertInvoiceHtlcAssets(
263-
t.t, dave, invoiceResp3, assetID, largeInvoiceAmount,
263+
t.t, dave, invoiceResp3, assetID, nil, largeInvoiceAmount,
264264
)
265265
assertPaymentHtlcAssets(
266-
t.t, charlie, invoiceResp3.RHash, assetID, largeInvoiceAmount,
266+
t.t, charlie, invoiceResp3.RHash, assetID, nil,
267+
largeInvoiceAmount,
267268
)
268269

269270
// We keysend the rest, so that all the balance is on Dave's side.
@@ -449,10 +450,11 @@ func testCustomChannels(ctx context.Context, net *NetworkHarness,
449450
// sender side show the individual HTLCs that arrived for it and that
450451
// they show the correct asset amounts when decoded.
451452
assertInvoiceHtlcAssets(
452-
t.t, charlie, invoiceResp, assetID, charlieInvoiceAmount,
453+
t.t, charlie, invoiceResp, assetID, nil, charlieInvoiceAmount,
453454
)
454455
assertPaymentHtlcAssets(
455-
t.t, dave, invoiceResp.RHash, assetID, charlieInvoiceAmount,
456+
t.t, dave, invoiceResp.RHash, assetID, nil,
457+
charlieInvoiceAmount,
456458
)
457459

458460
charlieAssetBalance += charlieInvoiceAmount
@@ -890,7 +892,8 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
890892
// ------------
891893
const keySendAmount = 100
892894
sendAssetKeySendPayment(
893-
t.t, charlie, dave, keySendAmount, assetID, fn.None[int64](),
895+
t.t, charlie, dave, keySendAmount, nil, fn.None[int64](),
896+
withGroupKey(groupID),
894897
)
895898
logBalance(t.t, nodes, assetID, "after keysend")
896899

@@ -918,10 +921,11 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
918921
// invoice.
919922
// ------------
920923
createAndPayNormalInvoice(
921-
t.t, charlie, dave, dave, 20_000, assetID, withSmallShards(),
924+
t.t, charlie, dave, dave, 20_000, nil, withSmallShards(),
922925
withFailure(lnrpc.Payment_FAILED, failureIncorrectDetails),
926+
withGroupKey(groupID),
923927
)
924-
logBalance(t.t, nodes, assetID, "after invoice")
928+
logBalance(t.t, nodes, assetID, "after failed invoice")
925929

926930
// We should also be able to do a multi-hop BTC only payment, paying an
927931
// invoice from Erin by Charlie.
@@ -935,22 +939,24 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
935939
// ------------
936940
const daveInvoiceAssetAmount = 2_000
937941
invoiceResp := createAssetInvoice(
938-
t.t, charlie, dave, daveInvoiceAssetAmount, assetID,
942+
t.t, charlie, dave, daveInvoiceAssetAmount, nil,
943+
withInvGroupKey(groupID),
939944
)
940945
payInvoiceWithAssets(
941-
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID,
946+
t.t, charlie, dave, invoiceResp.PaymentRequest, nil,
942947
withSmallShards(),
948+
withGroupKey(groupID),
943949
)
944950
logBalance(t.t, nodes, assetID, "after invoice")
945951

946952
// Make sure the invoice on the receiver side and the payment on the
947953
// sender side show the individual HTLCs that arrived for it and that
948954
// they show the correct asset amounts when decoded.
949955
assertInvoiceHtlcAssets(
950-
t.t, dave, invoiceResp, assetID, daveInvoiceAssetAmount,
956+
t.t, dave, invoiceResp, nil, groupID, daveInvoiceAssetAmount,
951957
)
952958
assertPaymentHtlcAssets(
953-
t.t, charlie, invoiceResp.RHash, assetID,
959+
t.t, charlie, invoiceResp.RHash, nil, groupID,
954960
daveInvoiceAssetAmount,
955961
)
956962

@@ -961,7 +967,8 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
961967
// Test case 4: Pay a normal invoice from Erin by Charlie.
962968
// ------------
963969
paidAssetAmount := createAndPayNormalInvoice(
964-
t.t, charlie, dave, erin, 20_000, assetID, withSmallShards(),
970+
t.t, charlie, dave, erin, 20_000, nil, withSmallShards(),
971+
withGroupKey(groupID),
965972
)
966973
logBalance(t.t, nodes, assetID, "after invoice")
967974

@@ -974,7 +981,8 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
974981
// ------------
975982
const fabiaInvoiceAssetAmount1 = 1000
976983
invoiceResp = createAssetInvoice(
977-
t.t, erin, fabia, fabiaInvoiceAssetAmount1, assetID,
984+
t.t, erin, fabia, fabiaInvoiceAssetAmount1, nil,
985+
withInvGroupKey(groupID),
978986
)
979987
payInvoiceWithAssets(
980988
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID,
@@ -1014,8 +1022,8 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
10141022
t.t, erin, fabia, fabiaInvoiceAssetAmount3, assetID,
10151023
)
10161024
payInvoiceWithAssets(
1017-
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID,
1018-
withSmallShards(),
1025+
t.t, charlie, dave, invoiceResp.PaymentRequest, nil,
1026+
withSmallShards(), withGroupKey(groupID),
10191027
)
10201028
logBalance(t.t, nodes, assetID, "after invoice")
10211029

@@ -1032,7 +1040,8 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
10321040

10331041
const yaraInvoiceAssetAmount1 = 1000
10341042
invoiceResp = createAssetInvoice(
1035-
t.t, dave, yara, yaraInvoiceAssetAmount1, assetID,
1043+
t.t, dave, yara, yaraInvoiceAssetAmount1, nil,
1044+
withInvGroupKey(groupID),
10361045
)
10371046
payInvoiceWithAssets(
10381047
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID,
@@ -1944,10 +1953,10 @@ func testCustomChannelsLiquidityEdgeCases(ctx context.Context,
19441953
// sender side show the individual HTLCs that arrived for it and that
19451954
// they show the correct asset amounts when decoded.
19461955
assertInvoiceHtlcAssets(
1947-
t.t, dave, invoiceResp, assetID, bigAssetAmount,
1956+
t.t, dave, invoiceResp, assetID, nil, bigAssetAmount,
19481957
)
19491958
assertPaymentHtlcAssets(
1950-
t.t, charlie, invoiceResp.RHash, assetID, bigAssetAmount,
1959+
t.t, charlie, invoiceResp.RHash, assetID, nil, bigAssetAmount,
19511960
)
19521961

19531962
// Dave sends 200k assets and 5k sats to Yara.
@@ -2908,7 +2917,8 @@ func testCustomChannelsOraclePricing(ctx context.Context, net *NetworkHarness,
29082917
charliePaidMSat, rate,
29092918
).ScaleTo(0).ToUint64()
29102919
assertPaymentHtlcAssets(
2911-
t.t, charlie, invoiceResp.RHash, assetID, charliePaidAmount,
2920+
t.t, charlie, invoiceResp.RHash, assetID, nil,
2921+
charliePaidAmount,
29122922
)
29132923

29142924
// We now make sure the asset and satoshi channel balances are exactly

0 commit comments

Comments
 (0)