From e6ee835bbe3238365a7e5054f4fd65b2dea05a92 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 10 Jan 2019 12:23:57 +0100 Subject: [PATCH] lnwallet/channel_test: assert FeeUpdate is removed from logs after lock-in --- lnwallet/channel_test.go | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index 7cdb3f7b..348a9e11 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -1395,6 +1395,45 @@ func TestStateUpdatePersistence(t *testing.T) { t.Fatalf("unable to recv bob's htlc: %v", err) } + // Also add a fee update to the update logs. + fee := SatPerKWeight(111) + if err := aliceChannel.UpdateFee(fee); err != nil { + t.Fatalf("unable to send fee update") + } + if err := bobChannel.ReceiveUpdateFee(fee); err != nil { + t.Fatalf("unable to receive fee update") + } + + // Helper method that asserts the expected number of updates are found + // in the update logs. + assertNumLogUpdates := func(numAliceUpdates, numBobUpdates int) { + if aliceChannel.localUpdateLog.Len() != numAliceUpdates { + t.Fatalf("expected %d local updates, found %d", + numAliceUpdates, + aliceChannel.localUpdateLog.Len()) + } + if aliceChannel.remoteUpdateLog.Len() != numBobUpdates { + t.Fatalf("expected %d remote updates, found %d", + numBobUpdates, + aliceChannel.remoteUpdateLog.Len()) + } + + if bobChannel.localUpdateLog.Len() != numBobUpdates { + t.Fatalf("expected %d local updates, found %d", + numBobUpdates, + bobChannel.localUpdateLog.Len()) + } + if bobChannel.remoteUpdateLog.Len() != numAliceUpdates { + t.Fatalf("expected %d remote updates, found %d", + numAliceUpdates, + bobChannel.remoteUpdateLog.Len()) + } + } + + // Both nodes should now have Alice's 3 Adds and 1 FeeUpdate in the + // log, and Bob's 1 Add. + assertNumLogUpdates(4, 1) + // Next, Alice initiates a state transition to include the HTLC's she // added above in a new commitment state. if err := forceStateTransition(aliceChannel, bobChannel); err != nil { @@ -1409,6 +1448,16 @@ func TestStateUpdatePersistence(t *testing.T) { t.Fatalf("unable to complete bob's state transition: %v", err) } + // After the state transition the fee update is fully locked in, and + // should've been removed from both channels' update logs. + if aliceChannel.localCommitChain.tail().feePerKw != fee { + t.Fatalf("fee not locked in") + } + if bobChannel.localCommitChain.tail().feePerKw != fee { + t.Fatalf("fee not locked in") + } + assertNumLogUpdates(3, 1) + // The latest commitment from both sides should have all the HTLCs. numAliceOutgoing := aliceChannel.localCommitChain.tail().outgoingHTLCs numAliceIncoming := aliceChannel.localCommitChain.tail().incomingHTLCs