Skip to content

Commit 6f0f04b

Browse files
committed
itest: formatting enhancements for tap payments
This commit mainly changes the returned type of the payment result for asset payments. We create a struct TapPaymentResult which contains all the related information for the outcome of an asset payment.
1 parent f76ce2f commit 6f0f04b

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed

itest/assets_test.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,8 +1423,10 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
14231423
return
14241424
}
14251425

1426-
result, _, err := getAssetPaymentResult(t, stream, false)
1427-
require.NoError(t, err)
1426+
tapResult := getAssetPaymentResult(t, stream, false)
1427+
require.NoError(t, tapResult.err)
1428+
1429+
result := tapResult.lndResult
14281430
if result.Status == lnrpc.Payment_FAILED {
14291431
t.Logf("Failure reason: %v", result.FailureReason)
14301432
}
@@ -1755,12 +1757,13 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
17551757
sendReq.MaxShardSizeMsat = 80_000_000
17561758
}
17571759

1758-
var rfqBytes, peerPubKey []byte
1760+
var rfqBytes []byte
17591761
cfg.rfq.WhenSome(func(i rfqmsg.ID) {
17601762
rfqBytes = make([]byte, len(i[:]))
17611763
copy(rfqBytes, i[:])
17621764
})
17631765

1766+
var peerPubKey []byte
17641767
if rfqPeer != nil {
17651768
peerPubKey = rfqPeer.PubKey[:]
17661769
}
@@ -1785,7 +1788,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
17851788

17861789
// If an error is returned by the RPC method (meaning the stream itself
17871790
// was established, no network or auth error), we expect the error to be
1788-
// returned on the first read on the stream.
1791+
// returned on the stream.
17891792
if cfg.errSubStr != "" {
17901793
msg, err := stream.Recv()
17911794

@@ -1804,14 +1807,18 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
18041807
rateVal rfqmath.FixedPoint[rfqmath.BigInt]
18051808
)
18061809

1807-
result, rateVal, err := getAssetPaymentResult(
1810+
tapResult := getAssetPaymentResult(
18081811
t, stream, cfg.payStatus == lnrpc.Payment_IN_FLIGHT,
18091812
)
1810-
require.NoError(t, err)
1813+
require.NoError(t, tapResult.err)
1814+
1815+
result := tapResult.lndResult
18111816
require.Equal(t, cfg.payStatus, result.Status)
18121817
require.Equal(t, cfg.failureReason, result.FailureReason)
18131818

18141819
amountMsat := lnwire.MilliSatoshi(decodedInvoice.NumMsat)
1820+
1821+
rateVal = tapResult.assetRate
18151822
milliSatsFP := rfqmath.MilliSatoshiToUnits(amountMsat, rateVal)
18161823
numUnits = milliSatsFP.ScaleTo(0).ToUint64()
18171824

itest/litd_accounts_test.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,24 @@ func getPaymentResult(stream routerrpc.Router_SendPaymentV2Client,
445445
}
446446
}
447447

448+
// TapPaymentResult encapsulates all the information related to the outcome of
449+
// a tap asset payment. It may also contain an error, in which case the rest of
450+
// the values should be ignored, even if set.
451+
type TapPaymentResult struct {
452+
// lndResult contains the lnd part of the payment result.
453+
lndResult *lnrpc.Payment
454+
455+
// assetRate contains the asset rate that was used to convert the assets
456+
// to sats.
457+
assetRate rfqmath.FixedPoint[rfqmath.BigInt]
458+
459+
// err contains the returned error from the payment.
460+
err error
461+
}
462+
448463
func getAssetPaymentResult(t *testing.T,
449464
s tapchannelrpc.TaprootAssetChannels_SendPaymentClient,
450-
isHodl bool) (*lnrpc.Payment, rfqmath.FixedPoint[rfqmath.BigInt],
451-
error) {
465+
isHodl bool) TapPaymentResult {
452466

453467
// No idea why it makes a difference whether we wait before calling
454468
// s.Recv() or not, but it does. Without the sleep, the test will fail
@@ -461,7 +475,11 @@ func getAssetPaymentResult(t *testing.T,
461475
for {
462476
msg, err := s.Recv()
463477
if err != nil {
464-
return nil, rateVal, err
478+
return TapPaymentResult{
479+
lndResult: nil,
480+
assetRate: rateVal,
481+
err: err,
482+
}
465483
}
466484

467485
// Ignore RFQ quote acceptance messages read from the send
@@ -501,19 +519,29 @@ func getAssetPaymentResult(t *testing.T,
501519

502520
payment := msg.GetPaymentResult()
503521
if payment == nil {
504-
return nil, rateVal,
505-
fmt.Errorf("unexpected message: %v", msg)
522+
err := fmt.Errorf("unexpected message: %v", msg)
523+
return TapPaymentResult{
524+
lndResult: nil,
525+
assetRate: rateVal,
526+
err: err,
527+
}
528+
}
529+
530+
result := TapPaymentResult{
531+
lndResult: payment,
532+
assetRate: rateVal,
533+
err: nil,
506534
}
507535

508536
// If this is a hodl payment, then we'll return the first
509537
// expected response. Otherwise, we'll wait until the in flight
510538
// clears to we can observe the other payment states.
511539
switch {
512540
case isHodl:
513-
return payment, rateVal, nil
541+
return result
514542

515543
case payment.Status != lnrpc.Payment_IN_FLIGHT:
516-
return payment, rateVal, nil
544+
return result
517545
}
518546
}
519547
}

0 commit comments

Comments
 (0)