@@ -11339,3 +11339,60 @@ func TestCreateCooperativeCloseTx(t *testing.T) {
1133911339 })
1134011340 }
1134111341}
11342+
11343+ // TestNoopAddSettle tests that adding and settling an HTLC with no-op, no
11344+ // balances are actually affected.
11345+ func TestNoopAddSettle (t * testing.T ) {
11346+ t .Parallel ()
11347+
11348+ // Create a test channel which will be used for the duration of this
11349+ // unittest. The channel will be funded evenly with Alice having 5 BTC,
11350+ // and Bob having 5 BTC.
11351+ chanType := channeldb .SimpleTaprootFeatureBit |
11352+ channeldb .AnchorOutputsBit | channeldb .ZeroHtlcTxFeeBit |
11353+ channeldb .SingleFunderTweaklessBit | channeldb .TapscriptRootBit
11354+ aliceChannel , bobChannel , err := CreateTestChannels (
11355+ t , chanType ,
11356+ )
11357+ require .NoError (t , err , "unable to create test channels" )
11358+
11359+ const htlcAmt = 10_000
11360+ htlc , preimage := createHTLC (0 , htlcAmt )
11361+ noopRecord := tlv.NewPrimitiveRecord [tlv.TlvType65544 , bool ](true )
11362+
11363+ records , err := tlv .RecordsToMap ([]tlv.Record {noopRecord .Record ()})
11364+ require .NoError (t , err )
11365+ htlc .CustomRecords = records
11366+
11367+ aliceBalance := aliceChannel .channelState .LocalCommitment .LocalBalance
11368+ bobBalance := bobChannel .channelState .LocalCommitment .LocalBalance
11369+
11370+ // Have Alice add the HTLC, then lock it in with a new state transition.
11371+ aliceHtlcIndex , err := aliceChannel .AddHTLC (htlc , nil )
11372+ require .NoError (t , err , "alice unable to add htlc" )
11373+ bobHtlcIndex , err := bobChannel .ReceiveHTLC (htlc )
11374+ require .NoError (t , err , "bob unable to receive htlc" )
11375+ if err := ForceStateTransition (aliceChannel , bobChannel ); err != nil {
11376+ t .Fatalf ("Can't update the channel state: %v" , err )
11377+ }
11378+
11379+ // We'll have Bob settle the HTLC, then force another state transition.
11380+ err = bobChannel .SettleHTLC (preimage , bobHtlcIndex , nil , nil , nil )
11381+ require .NoError (t , err , "bob unable to settle inbound htlc" )
11382+ err = aliceChannel .ReceiveHTLCSettle (preimage , aliceHtlcIndex )
11383+ if err != nil {
11384+ t .Fatalf ("alice unable to accept settle of outbound " +
11385+ "htlc: %v" , err )
11386+ }
11387+ if err := ForceStateTransition (aliceChannel , bobChannel ); err != nil {
11388+ t .Fatalf ("Can't update the channel state: %v" , err )
11389+ }
11390+
11391+ aliceBalanceFinal := aliceChannel .channelState .LocalCommitment .LocalBalance //nolint:ll
11392+ bobBalanceFinal := bobChannel .channelState .LocalCommitment .LocalBalance
11393+
11394+ // The balances of Alice and Bob should be the exact same and shouldn't
11395+ // have changed.
11396+ require .Equal (t , aliceBalance , aliceBalanceFinal )
11397+ require .Equal (t , bobBalance , bobBalanceFinal )
11398+ }
0 commit comments