9
9
"fmt"
10
10
"os"
11
11
"testing"
12
+ "time"
12
13
13
14
"github.com/btcsuite/btcd/btcec/v2"
14
15
"github.com/btcsuite/btcd/btcec/v2/schnorr"
@@ -45,6 +46,9 @@ import (
45
46
"gopkg.in/macaroon.v2"
46
47
)
47
48
49
+ // PaymentTimeout is the default payment timeout we use in our tests.
50
+ const PaymentTimeout = 6 * time .Second
51
+
48
52
// createTestAssetNetwork sends asset funds from Charlie to Dave and Erin, so
49
53
// they can fund asset channels with Yara and Fabia, respectively. So the asset
50
54
// channels created are Charlie->Dave, Dave->Yara, Erin->Fabia. The channels
@@ -429,9 +433,10 @@ func assertPendingChannels(t *testing.T, node *HarnessNode, assetID []byte,
429
433
430
434
require .NotZero (t , pendingJSON .Assets [0 ].Capacity )
431
435
432
- pendingLocalBalance , pendingRemoteBalance := getAssetChannelBalance (
433
- t , node , assetID , true ,
434
- )
436
+ pendingLocalBalance , pendingRemoteBalance , _ , _ :=
437
+ getAssetChannelBalance (
438
+ t , node , assetID , true ,
439
+ )
435
440
require .EqualValues (t , localSum , pendingLocalBalance )
436
441
require .EqualValues (t , remoteSum , pendingRemoteBalance )
437
442
}
@@ -542,7 +547,7 @@ func getChannelCustomData(src, dst *HarnessNode) (*rfqmsg.JsonAssetChanInfo,
542
547
}
543
548
544
549
func getAssetChannelBalance (t * testing.T , node * HarnessNode , assetID []byte ,
545
- pending bool ) (uint64 , uint64 ) {
550
+ pending bool ) (uint64 , uint64 , uint64 , uint64 ) {
546
551
547
552
ctxb := context .Background ()
548
553
ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
@@ -572,11 +577,14 @@ func getAssetChannelBalance(t *testing.T, node *HarnessNode, assetID []byte,
572
577
remoteSum += balances [assetIDString ].RemoteBalance
573
578
}
574
579
575
- return localSum , remoteSum
580
+ return localSum , remoteSum , balance .LocalBalance .Sat ,
581
+ balance .RemoteBalance .Sat
576
582
}
577
583
578
584
func sendAssetKeySendPayment (t * testing.T , src , dst * HarnessNode , amt uint64 ,
579
- assetID []byte , btcAmt fn.Option [int64 ]) {
585
+ assetID []byte , btcAmt fn.Option [int64 ],
586
+ expectedStatus lnrpc.Payment_PaymentStatus ,
587
+ failReason fn.Option [lnrpc.PaymentFailureReason ]) {
580
588
581
589
ctxb := context .Background ()
582
590
ctxt , cancel := context .WithTimeout (ctxb , defaultTimeout )
@@ -601,7 +609,7 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
601
609
Amt : btcAmt .UnwrapOr (500 ),
602
610
DestCustomRecords : customRecords ,
603
611
PaymentHash : hash [:],
604
- TimeoutSeconds : 3 ,
612
+ TimeoutSeconds : int32 ( PaymentTimeout . Seconds ()) ,
605
613
}
606
614
607
615
stream , err := srcTapd .SendPayment (ctxt , & tchrpc.SendPaymentRequest {
@@ -613,7 +621,12 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
613
621
614
622
result , err := getAssetPaymentResult (stream )
615
623
require .NoError (t , err )
616
- require .Equal (t , lnrpc .Payment_SUCCEEDED , result .Status )
624
+ require .Equal (t , expectedStatus , result .Status )
625
+
626
+ expectedReason := failReason .UnwrapOr (
627
+ lnrpc .PaymentFailureReason_FAILURE_REASON_NONE ,
628
+ )
629
+ require .Equal (t , result .FailureReason , expectedReason )
617
630
}
618
631
619
632
func sendKeySendPayment (t * testing.T , src , dst * HarnessNode ,
@@ -640,7 +653,7 @@ func sendKeySendPayment(t *testing.T, src, dst *HarnessNode,
640
653
Amt : int64 (amt ),
641
654
DestCustomRecords : customRecords ,
642
655
PaymentHash : hash [:],
643
- TimeoutSeconds : 3 ,
656
+ TimeoutSeconds : int32 ( PaymentTimeout . Seconds ()) ,
644
657
}
645
658
646
659
stream , err := src .RouterClient .SendPaymentV2 (ctxt , req )
@@ -698,7 +711,7 @@ func payInvoiceWithSatoshi(t *testing.T, payer *HarnessNode,
698
711
699
712
sendReq := & routerrpc.SendPaymentRequest {
700
713
PaymentRequest : invoice .PaymentRequest ,
701
- TimeoutSeconds : 2 ,
714
+ TimeoutSeconds : int32 ( PaymentTimeout . Seconds ()) ,
702
715
MaxShardSizeMsat : 80_000_000 ,
703
716
FeeLimitMsat : 1_000_000 ,
704
717
}
@@ -727,7 +740,7 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
727
740
728
741
sendReq := & routerrpc.SendPaymentRequest {
729
742
PaymentRequest : invoice .PaymentRequest ,
730
- TimeoutSeconds : 2 ,
743
+ TimeoutSeconds : int32 ( PaymentTimeout . Seconds ()) ,
731
744
FeeLimitMsat : 1_000_000 ,
732
745
}
733
746
@@ -1422,10 +1435,15 @@ func logBalance(t *testing.T, nodes []*HarnessNode, assetID []byte,
1422
1435
1423
1436
t .Helper ()
1424
1437
1438
+ time .Sleep (time .Millisecond * 250 )
1439
+
1425
1440
for _ , node := range nodes {
1426
- local , remote := getAssetChannelBalance (t , node , assetID , false )
1427
- t .Logf ("%-7s balance: local=%-9d remote=%-9d (%v)" ,
1428
- node .Cfg .Name , local , remote , occasion )
1441
+ local , remote , localSat , remoteSat :=
1442
+ getAssetChannelBalance (t , node , assetID , false )
1443
+
1444
+ t .Logf ("%-7s balance: local=%-9d remote=%-9d, localSat=%-9d, " +
1445
+ "remoteSat=%-9d (%v)" , node .Cfg .Name , local , remote ,
1446
+ localSat , remoteSat , occasion )
1429
1447
}
1430
1448
}
1431
1449
0 commit comments