From 08c7fd9b4d1fc26cd9c33d3d903e049bf7086d95 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 10 Nov 2017 14:30:58 -0800 Subject: [PATCH] lnwallet: extend TestStateUpdatePersistence to assert proper htlc counters --- lnwallet/channel_test.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index fa33101d..ff995f8e 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -1470,8 +1470,6 @@ func TestStateUpdatePersistence(t *testing.T) { // The state update logs of the new channels and the old channels // should now be identical other than the height the HTLCs were added. - // - // TODO(roasbeef): check for HTLC index as well!!!!! if aliceChannel.localUpdateLog.logIndex != aliceChannelNew.localUpdateLog.logIndex { t.Fatalf("alice log counter: expected %v, got %v", @@ -1624,6 +1622,25 @@ func TestStateUpdatePersistence(t *testing.T) { t.Fatalf("expected %v bob satoshis sent, got %v", htlcAmt*3, bobChannel.channelState.TotalMSatReceived) } + + // As a final test, we'll ensure that the HTLC counters for both sides + // has been persisted properly. If we instruct Alice to add a new HTLC, + // it should have an index of 3. If we instruct Bob to do the + // same, it should have an index of 1. + aliceHtlcIndex, err := aliceChannel.AddHTLC(bobh) + if err != nil { + t.Fatalf("unable to add htlc: %v", err) + } + if aliceHtlcIndex != 3 { + t.Fatalf("wrong htlc index: expected %v, got %v", 3, aliceHtlcIndex) + } + bobHtlcIndex, err := bobChannel.AddHTLC(bobh) + if err != nil { + t.Fatalf("unable to add htlc: %v", err) + } + if bobHtlcIndex != 1 { + t.Fatalf("wrong htlc index: expected %v, got %v", 1, aliceHtlcIndex) + } } func TestCancelHTLC(t *testing.T) {