@@ -11504,3 +11504,184 @@ func TestNoopAddBelowReserve(t *testing.T) {
11504
11504
bobChan .LocalChanReserve ()+ htlcAmt .ToSatoshis (),
11505
11505
)
11506
11506
}
11507
+
11508
+ // TestEvaluateNoOpHtlc tests that the noop htlc evaluator helper function
11509
+ // produces the expected balance deltas from various starting states.
11510
+ func TestEvaluateNoOpHtlc (t * testing.T ) {
11511
+ testCases := []struct {
11512
+ name string
11513
+ localBalance , remoteBalance btcutil.Amount
11514
+ localReserve , remoteReserve btcutil.Amount
11515
+ entry * paymentDescriptor
11516
+ receiver lntypes.ChannelParty
11517
+ balanceDeltas * lntypes.Dual [int64 ]
11518
+ expectedDeltas * lntypes.Dual [int64 ]
11519
+ }{
11520
+ {
11521
+ name : "remote receive" ,
11522
+ entry : & paymentDescriptor {
11523
+ Amount : lnwire .MilliSatoshi (2500 ),
11524
+ },
11525
+ receiver : lntypes .Remote ,
11526
+ balanceDeltas : & lntypes.Dual [int64 ]{
11527
+ Local : 0 ,
11528
+ Remote : 0 ,
11529
+ },
11530
+ expectedDeltas : & lntypes.Dual [int64 ]{
11531
+ Local : 2_500 ,
11532
+ Remote : 0 ,
11533
+ },
11534
+ },
11535
+ {
11536
+ name : "local receive" ,
11537
+ entry : & paymentDescriptor {
11538
+ Amount : lnwire .MilliSatoshi (2500 ),
11539
+ },
11540
+ receiver : lntypes .Local ,
11541
+ balanceDeltas : & lntypes.Dual [int64 ]{
11542
+ Local : 0 ,
11543
+ Remote : 0 ,
11544
+ },
11545
+ expectedDeltas : & lntypes.Dual [int64 ]{
11546
+ Local : 0 ,
11547
+ Remote : 2_500 ,
11548
+ },
11549
+ },
11550
+ {
11551
+ name : "remote below reserve" ,
11552
+ entry : & paymentDescriptor {
11553
+ Amount : lnwire .MilliSatoshi (2500 ),
11554
+ },
11555
+ receiver : lntypes .Remote ,
11556
+ remoteBalance : 25_000 ,
11557
+ remoteReserve : 50_000 ,
11558
+ balanceDeltas : & lntypes.Dual [int64 ]{
11559
+ Local : 0 ,
11560
+ Remote : 0 ,
11561
+ },
11562
+ expectedDeltas : & lntypes.Dual [int64 ]{
11563
+ Local : 0 ,
11564
+ Remote : 2_500 ,
11565
+ },
11566
+ },
11567
+ {
11568
+ name : "local below reserve" ,
11569
+ entry : & paymentDescriptor {
11570
+ Amount : lnwire .MilliSatoshi (2500 ),
11571
+ },
11572
+ receiver : lntypes .Local ,
11573
+ localBalance : 25_000 ,
11574
+ localReserve : 50_000 ,
11575
+ balanceDeltas : & lntypes.Dual [int64 ]{
11576
+ Local : 0 ,
11577
+ Remote : 0 ,
11578
+ },
11579
+ expectedDeltas : & lntypes.Dual [int64 ]{
11580
+ Local : 2_500 ,
11581
+ Remote : 0 ,
11582
+ },
11583
+ },
11584
+ {
11585
+ name : "local above reserve with delta" ,
11586
+ entry : & paymentDescriptor {
11587
+ Amount : lnwire .MilliSatoshi (2500 ),
11588
+ },
11589
+ receiver : lntypes .Local ,
11590
+ localBalance : 25_000 ,
11591
+ localReserve : 50_000 ,
11592
+ balanceDeltas : & lntypes.Dual [int64 ]{
11593
+ Local : 25_001 ,
11594
+ Remote : 0 ,
11595
+ },
11596
+ expectedDeltas : & lntypes.Dual [int64 ]{
11597
+ Local : 25_001 ,
11598
+ Remote : 2_500 ,
11599
+ },
11600
+ },
11601
+ {
11602
+ name : "remote above reserve with delta" ,
11603
+ entry : & paymentDescriptor {
11604
+ Amount : lnwire .MilliSatoshi (2500 ),
11605
+ },
11606
+ receiver : lntypes .Remote ,
11607
+ remoteBalance : 25_000 ,
11608
+ remoteReserve : 50_000 ,
11609
+ balanceDeltas : & lntypes.Dual [int64 ]{
11610
+ Local : 0 ,
11611
+ Remote : 25_001 ,
11612
+ },
11613
+ expectedDeltas : & lntypes.Dual [int64 ]{
11614
+ Local : 2_500 ,
11615
+ Remote : 25_001 ,
11616
+ },
11617
+ },
11618
+ {
11619
+ name : "local below reserve with delta" ,
11620
+ entry : & paymentDescriptor {
11621
+ Amount : lnwire .MilliSatoshi (2500 ),
11622
+ },
11623
+ receiver : lntypes .Local ,
11624
+ localBalance : 25_000 ,
11625
+ localReserve : 50_000 ,
11626
+ balanceDeltas : & lntypes.Dual [int64 ]{
11627
+ Local : 24_999 ,
11628
+ Remote : 0 ,
11629
+ },
11630
+ expectedDeltas : & lntypes.Dual [int64 ]{
11631
+ Local : 27_499 ,
11632
+ Remote : 0 ,
11633
+ },
11634
+ },
11635
+ {
11636
+ name : "remote below reserve with delta" ,
11637
+ entry : & paymentDescriptor {
11638
+ Amount : lnwire .MilliSatoshi (2500 ),
11639
+ },
11640
+ receiver : lntypes .Remote ,
11641
+ remoteBalance : 25_000 ,
11642
+ remoteReserve : 50_000 ,
11643
+ balanceDeltas : & lntypes.Dual [int64 ]{
11644
+ Local : 0 ,
11645
+ Remote : 24_998 ,
11646
+ },
11647
+ expectedDeltas : & lntypes.Dual [int64 ]{
11648
+ Local : 0 ,
11649
+ Remote : 27_498 ,
11650
+ },
11651
+ },
11652
+ }
11653
+
11654
+ chanType := channeldb .SimpleTaprootFeatureBit |
11655
+ channeldb .AnchorOutputsBit | channeldb .ZeroHtlcTxFeeBit |
11656
+ channeldb .SingleFunderTweaklessBit | channeldb .TapscriptRootBit
11657
+ aliceChan , _ , err := CreateTestChannels (t , chanType )
11658
+ require .NoError (t , err , "unable to create test channels" )
11659
+
11660
+ for _ , testCase := range testCases {
11661
+ tc := testCase
11662
+
11663
+ t .Logf ("Running test case: %s" , testCase .name )
11664
+
11665
+ if tc .localBalance != 0 && tc .localReserve != 0 {
11666
+ aliceChan .channelState .LocalChanCfg .ChanReserve =
11667
+ tc .localReserve
11668
+
11669
+ aliceChan .channelState .LocalCommitment .LocalBalance =
11670
+ lnwire .NewMSatFromSatoshis (tc .localBalance )
11671
+ }
11672
+
11673
+ if tc .remoteBalance != 0 && tc .remoteReserve != 0 {
11674
+ aliceChan .channelState .RemoteChanCfg .ChanReserve =
11675
+ tc .remoteReserve
11676
+
11677
+ aliceChan .channelState .RemoteCommitment .RemoteBalance =
11678
+ lnwire .NewMSatFromSatoshis (tc .remoteBalance )
11679
+ }
11680
+
11681
+ aliceChan .evaluateNoOpHtlc (
11682
+ tc .entry , tc .receiver , tc .balanceDeltas ,
11683
+ )
11684
+
11685
+ require .Equal (t , tc .expectedDeltas , tc .balanceDeltas )
11686
+ }
11687
+ }
0 commit comments