Skip to content

Commit 957dec6

Browse files
committed
itest: use groupkey payments & invoices in grouped asset test
1 parent 70f4d28 commit 957dec6

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)
@@ -937,6 +939,7 @@ type payConfig struct {
937939
payStatus lnrpc.Payment_PaymentStatus
938940
failureReason lnrpc.PaymentFailureReason
939941
rfq fn.Option[rfqmsg.ID]
942+
groupKey []byte
940943
}
941944

942945
func defaultPayConfig() *payConfig {
@@ -951,6 +954,12 @@ func defaultPayConfig() *payConfig {
951954

952955
type payOpt func(*payConfig)
953956

957+
func withGroupKey(groupKey []byte) payOpt {
958+
return func(c *payConfig) {
959+
c.groupKey = groupKey
960+
}
961+
}
962+
954963
func withSmallShards() payOpt {
955964
return func(c *payConfig) {
956965
c.smallShards = true
@@ -1036,6 +1045,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10361045
stream, err := payerTapd.SendPayment(ctxt, &tchrpc.SendPaymentRequest{
10371046
AssetId: assetID,
10381047
PeerPubkey: rfqPeer.PubKey[:],
1048+
GroupKey: cfg.groupKey,
10391049
PaymentRequest: sendReq,
10401050
RfqId: rfqBytes,
10411051
AllowOverpay: cfg.allowOverpay,
@@ -1097,6 +1107,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
10971107

10981108
type invoiceConfig struct {
10991109
errSubStr string
1110+
groupKey []byte
11001111
}
11011112

11021113
func defaultInvoiceConfig() *invoiceConfig {
@@ -1113,6 +1124,12 @@ func withInvoiceErrSubStr(errSubStr string) invoiceOpt {
11131124
}
11141125
}
11151126

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

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

11861204
ctxb := context.Background()
@@ -1199,7 +1217,15 @@ func assertInvoiceHtlcAssets(t *testing.T, node *HarnessNode,
11991217

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

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

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

12311257
ctxb := context.Background()
12321258
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -1247,7 +1273,15 @@ func assertPaymentHtlcAssets(t *testing.T, node *HarnessNode, payHash []byte,
12471273

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

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

12521286
var totalAssetAmount uint64
12531287
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)