From 5240953de02d281be694b2c87d151d6c7dce2cb5 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 31 Jul 2017 20:53:02 -0700 Subject: [PATCH] lnwallet: temporarily ensure TestStateUpdatePersistence doesn't make dust MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note that this commit is temporary, and should be reverted once #231 is merged. The reason we need to do this for now, is that we don’t properly track the exact state of the remote party’s commitment. In this test case, the resulting HTLC’s added are dust to one party, but non-dust to another. So upon restart, the states (balance wise) has diverged. --- lnwallet/channel_test.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index 12c12354..c43896b0 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -1195,6 +1195,7 @@ func TestStateUpdatePersistence(t *testing.T) { } const numHtlcs = 4 + const htlcAmt = 20000 // Alice adds 3 HTLCs to the update log, while Bob adds a single HTLC. var alicePreimage [32]byte @@ -1205,7 +1206,7 @@ func TestStateUpdatePersistence(t *testing.T) { rHash := sha256.Sum256(alicePreimage[:]) h := &lnwire.UpdateAddHTLC{ PaymentHash: rHash, - Amount: btcutil.Amount(5000), + Amount: htlcAmt, Expiry: uint32(10), } @@ -1219,7 +1220,7 @@ func TestStateUpdatePersistence(t *testing.T) { rHash := sha256.Sum256(bobPreimage[:]) bobh := &lnwire.UpdateAddHTLC{ PaymentHash: rHash, - Amount: btcutil.Amount(5000), + Amount: htlcAmt, Expiry: uint32(10), } if _, err := bobChannel.AddHTLC(bobh); err != nil { @@ -1287,9 +1288,6 @@ func TestStateUpdatePersistence(t *testing.T) { if err != nil { t.Fatalf("unable to create new channel: %v", err) } - if err := initRevocationWindows(aliceChannelNew, bobChannelNew, 3); err != nil { - t.Fatalf("unable to init revocation windows: %v", err) - } // The state update logs of the new channels and the old channels // should now be identical other than the height the HTLCs were added. @@ -1396,7 +1394,7 @@ func TestStateUpdatePersistence(t *testing.T) { } // Now settle all the HTLCs, then force a state update. The state - // update should suceed as both sides have identical. + // update should succeed as both sides have identical. for i := 0; i < 3; i++ { settleIndex, err := bobChannelNew.SettleHTLC(alicePreimage) if err != nil { @@ -1429,21 +1427,21 @@ func TestStateUpdatePersistence(t *testing.T) { // The amounts transferred should been updated as per the amounts in // the HTLCs - if aliceChannelNew.channelState.TotalSatoshisSent != 15000 { + if aliceChannelNew.channelState.TotalSatoshisSent != htlcAmt*3 { t.Fatalf("expected %v alice satoshis sent, got %v", - 15000, aliceChannelNew.channelState.TotalSatoshisSent) + htlcAmt*3, aliceChannelNew.channelState.TotalSatoshisSent) } - if aliceChannelNew.channelState.TotalSatoshisReceived != 5000 { + if aliceChannelNew.channelState.TotalSatoshisReceived != htlcAmt { t.Fatalf("expected %v alice satoshis received, got %v", - 5000, aliceChannelNew.channelState.TotalSatoshisReceived) + htlcAmt, aliceChannelNew.channelState.TotalSatoshisReceived) } - if bobChannelNew.channelState.TotalSatoshisSent != 5000 { + if bobChannelNew.channelState.TotalSatoshisSent != htlcAmt { t.Fatalf("expected %v bob satoshis sent, got %v", - 5000, bobChannel.channelState.TotalSatoshisSent) + htlcAmt, bobChannel.channelState.TotalSatoshisSent) } - if bobChannelNew.channelState.TotalSatoshisReceived != 15000 { + if bobChannelNew.channelState.TotalSatoshisReceived != htlcAmt*3 { t.Fatalf("expected %v bob satoshis sent, got %v", - 15000, bobChannel.channelState.TotalSatoshisSent) + htlcAmt*3, bobChannel.channelState.TotalSatoshisSent) } }