Skip to content

Commit 4768ba2

Browse files
committed
itest: use groupkey payments & invoices in grouped asset test
1 parent 99c1d7d commit 4768ba2

File tree

2 files changed

+67
-23
lines changed

2 files changed

+67
-23
lines changed

itest/assets_test.go

Lines changed: 38 additions & 4 deletions
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"
@@ -755,6 +756,7 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
755756
stream, err := srcTapd.SendPayment(ctxt, &tchrpc.SendPaymentRequest{
756757
AssetId: assetID,
757758
AssetAmount: amt,
759+
GroupKey: cfg.groupKey,
758760
PaymentRequest: sendReq,
759761
})
760762
require.NoError(t, err)
@@ -927,6 +929,7 @@ type payConfig struct {
927929
payStatus lnrpc.Payment_PaymentStatus
928930
failureReason lnrpc.PaymentFailureReason
929931
rfq fn.Option[rfqmsg.ID]
932+
groupKey []byte
930933
}
931934

932935
func defaultPayConfig() *payConfig {
@@ -941,6 +944,12 @@ func defaultPayConfig() *payConfig {
941944

942945
type payOpt func(*payConfig)
943946

947+
func withGroupKey(groupKey []byte) payOpt {
948+
return func(c *payConfig) {
949+
c.groupKey = groupKey
950+
}
951+
}
952+
944953
func withSmallShards() payOpt {
945954
return func(c *payConfig) {
946955
c.smallShards = true
@@ -1026,6 +1035,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10261035
stream, err := payerTapd.SendPayment(ctxt, &tchrpc.SendPaymentRequest{
10271036
AssetId: assetID,
10281037
PeerPubkey: rfqPeer.PubKey[:],
1038+
GroupKey: cfg.groupKey,
10291039
PaymentRequest: sendReq,
10301040
RfqId: rfqBytes,
10311041
AllowOverpay: cfg.allowOverpay,
@@ -1087,6 +1097,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10871097

10881098
type invoiceConfig struct {
10891099
errSubStr string
1100+
groupKey []byte
10901101
}
10911102

10921103
func defaultInvoiceConfig() *invoiceConfig {
@@ -1103,6 +1114,12 @@ func withInvoiceErrSubStr(errSubStr string) invoiceOpt {
11031114
}
11041115
}
11051116

1117+
func withInvGroupKey(groupKey []byte) invoiceOpt {
1118+
return func(c *invoiceConfig) {
1119+
c.groupKey = groupKey
1120+
}
1121+
}
1122+
11061123
func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11071124
assetAmount uint64, assetID []byte,
11081125
opts ...invoiceOpt) *lnrpc.AddInvoiceResponse {
@@ -1126,6 +1143,7 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11261143

11271144
resp, err := dstTapd.AddInvoice(ctxt, &tchrpc.AddInvoiceRequest{
11281145
AssetId: assetID,
1146+
GroupKey: cfg.groupKey,
11291147
AssetAmount: assetAmount,
11301148
PeerPubkey: dstRfqPeer.PubKey[:],
11311149
InvoiceRequest: &lnrpc.Invoice{
@@ -1170,7 +1188,7 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
11701188
// individual HTLCs that arrived for it and that they show the correct asset
11711189
// amounts for the given ID when decoded.
11721190
func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
1173-
addedInvoice *lnrpc.AddInvoiceResponse, assetID []byte,
1191+
addedInvoice *lnrpc.AddInvoiceResponse, assetID []byte, groupID []byte,
11741192
assetAmount uint64) {
11751193

11761194
ctxb := context.Background()
@@ -1189,7 +1207,15 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
11891207

11901208
t.Logf("Asset invoice: %v", toProtoJSON(t, invoice))
11911209

1192-
targetID := hex.EncodeToString(assetID)
1210+
var targetID string
1211+
switch {
1212+
case len(assetID) > 0:
1213+
targetID = hex.EncodeToString(assetID)
1214+
1215+
case len(groupID) > 0:
1216+
groupHash := sha256.Sum256(groupID)
1217+
targetID = hex.EncodeToString(groupHash[:])
1218+
}
11931219

11941220
var totalAssetAmount uint64
11951221
for _, htlc := range invoice.Htlcs {
@@ -1216,7 +1242,7 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
12161242
// individual HTLCs that arrived for it and that they show the correct asset
12171243
// amounts for the given ID when decoded.
12181244
func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
1219-
assetID []byte, assetAmount uint64) {
1245+
assetID []byte, groupID []byte, assetAmount uint64) {
12201246

12211247
ctxb := context.Background()
12221248
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -1237,7 +1263,15 @@ func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
12371263

12381264
t.Logf("Asset payment: %v", toProtoJSON(t, payment))
12391265

1240-
targetID := hex.EncodeToString(assetID)
1266+
var targetID string
1267+
switch {
1268+
case len(assetID) > 0:
1269+
targetID = hex.EncodeToString(assetID)
1270+
1271+
case len(groupID) > 0:
1272+
groupHash := sha256.Sum256(groupID)
1273+
targetID = hex.EncodeToString(groupHash[:])
1274+
}
12411275

12421276
var totalAssetAmount uint64
12431277
for _, htlc := range payment.Htlcs {

itest/litd_custom_channels_test.go

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,11 @@ func testCustomChannelsLarge(_ context.Context, net *NetworkHarness,
261261
// sender side show the individual HTLCs that arrived for it and that
262262
// they show the correct asset amounts when decoded.
263263
assertInvoiceHtlcAssets(
264-
t.t, dave, invoiceResp3, assetID, largeInvoiceAmount,
264+
t.t, dave, invoiceResp3, assetID, nil, largeInvoiceAmount,
265265
)
266266
assertPaymentHtlcAssets(
267-
t.t, charlie, invoiceResp3.RHash, assetID, largeInvoiceAmount,
267+
t.t, charlie, invoiceResp3.RHash, assetID, nil,
268+
largeInvoiceAmount,
268269
)
269270

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

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

@@ -919,10 +922,11 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
919922
// invoice.
920923
// ------------
921924
createAndPayNormalInvoice(
922-
t.t, charlie, dave, dave, 20_000, assetID, withSmallShards(),
925+
t.t, charlie, dave, dave, 20_000, nil, withSmallShards(),
923926
withFailure(lnrpc.Payment_FAILED, failureIncorrectDetails),
927+
withGroupKey(groupID),
924928
)
925-
logBalance(t.t, nodes, assetID, "after invoice")
929+
logBalance(t.t, nodes, assetID, "after failed invoice")
926930

927931
// We should also be able to do a multi-hop BTC only payment, paying an
928932
// invoice from Erin by Charlie.
@@ -936,22 +940,24 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
936940
// ------------
937941
const daveInvoiceAssetAmount = 2_000
938942
invoiceResp := createAssetInvoice(
939-
t.t, charlie, dave, daveInvoiceAssetAmount, assetID,
943+
t.t, charlie, dave, daveInvoiceAssetAmount, nil,
944+
withInvGroupKey(groupID),
940945
)
941946
payInvoiceWithAssets(
942-
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID,
947+
t.t, charlie, dave, invoiceResp.PaymentRequest, nil,
943948
withSmallShards(),
949+
withGroupKey(groupID),
944950
)
945951
logBalance(t.t, nodes, assetID, "after invoice")
946952

947953
// Make sure the invoice on the receiver side and the payment on the
948954
// sender side show the individual HTLCs that arrived for it and that
949955
// they show the correct asset amounts when decoded.
950956
assertInvoiceHtlcAssets(
951-
t.t, dave, invoiceResp, assetID, daveInvoiceAssetAmount,
957+
t.t, dave, invoiceResp, nil, groupID, daveInvoiceAssetAmount,
952958
)
953959
assertPaymentHtlcAssets(
954-
t.t, charlie, invoiceResp.RHash, assetID,
960+
t.t, charlie, invoiceResp.RHash, nil, groupID,
955961
daveInvoiceAssetAmount,
956962
)
957963

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

@@ -975,7 +982,8 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
975982
// ------------
976983
const fabiaInvoiceAssetAmount1 = 1000
977984
invoiceResp = createAssetInvoice(
978-
t.t, erin, fabia, fabiaInvoiceAssetAmount1, assetID,
985+
t.t, erin, fabia, fabiaInvoiceAssetAmount1, nil,
986+
withInvGroupKey(groupID),
979987
)
980988
payInvoiceWithAssets(
981989
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID,
@@ -1015,8 +1023,8 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
10151023
t.t, erin, fabia, fabiaInvoiceAssetAmount3, assetID,
10161024
)
10171025
payInvoiceWithAssets(
1018-
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID,
1019-
withSmallShards(),
1026+
t.t, charlie, dave, invoiceResp.PaymentRequest, nil,
1027+
withSmallShards(), withGroupKey(groupID),
10201028
)
10211029
logBalance(t.t, nodes, assetID, "after invoice")
10221030

@@ -1033,7 +1041,8 @@ func testCustomChannelsGroupedAsset(ctx context.Context, net *NetworkHarness,
10331041

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

19501959
// Dave sends 200k assets and 5k sats to Yara.
@@ -2903,7 +2912,8 @@ func testCustomChannelsOraclePricing(ctx context.Context, net *NetworkHarness,
29032912
charliePaidMSat, rate,
29042913
).ScaleTo(0).ToUint64()
29052914
assertPaymentHtlcAssets(
2906-
t.t, charlie, invoiceResp.RHash, assetID, charliePaidAmount,
2915+
t.t, charlie, invoiceResp.RHash, assetID, nil,
2916+
charliePaidAmount,
29072917
)
29082918

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

0 commit comments

Comments
 (0)