From b2039f245e97f343a112580061f1c530a9ee64c5 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 12 Oct 2022 10:19:16 +0200 Subject: [PATCH] watchtower: demo cant remove tower during negotiation bug In this commit, a new test is added to demonstrate that an error is thrown if a user attempts to remove a tower during session negotiation even if no current negotiation is taking place with the tower. --- watchtower/wtclient/client_test.go | 41 ++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/watchtower/wtclient/client_test.go b/watchtower/wtclient/client_test.go index 738c8cf02..1d5c5b76a 100644 --- a/watchtower/wtclient/client_test.go +++ b/watchtower/wtclient/client_test.go @@ -17,6 +17,7 @@ import ( "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/keychain" + "github.com/lightningnetwork/lnd/lntest/wait" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/tor" @@ -401,6 +402,7 @@ type harnessCfg struct { policy wtpolicy.Policy noRegisterChan0 bool noAckCreateSession bool + noServerStart bool } func newHarness(t *testing.T, cfg harnessCfg) *testHarness { @@ -467,8 +469,10 @@ func newHarness(t *testing.T, cfg harnessCfg) *testHarness { channels: make(map[lnwire.ChannelID]*mockChannel), } - h.startServer() - t.Cleanup(h.stopServer) + if !cfg.noServerStart { + h.startServer() + t.Cleanup(h.stopServer) + } h.startClient() t.Cleanup(h.client.ForceQuit) @@ -1537,6 +1541,39 @@ var clientTests = []clientTest{ h.waitServerUpdates(hints[:maxUpdates], waitTime) }, }, + { + // Assert that an error is returned if a user tries to remove + // a tower from the client while a session negotiation is in + // progress. This is a bug that will be fixed in a future + // commit. + name: "cant remove tower while session negotiation in progress", + cfg: harnessCfg{ + localBalance: localBalance, + remoteBalance: remoteBalance, + policy: wtpolicy.Policy{ + TxPolicy: wtpolicy.TxPolicy{ + BlobType: blob.TypeAltruistCommit, + SweepFeeRate: wtpolicy.DefaultSweepFeeRate, + }, + MaxUpdates: 5, + }, + noServerStart: true, + }, + fn: func(h *testHarness) { + var err error + waitErr := wait.Predicate(func() bool { + err = h.client.RemoveTower( + h.serverAddr.IdentityKey, nil, + ) + return err != nil + }, time.Second*5) + require.NoError(h.t, waitErr) + + require.ErrorContains(h.t, err, "removing towers is "+ + "disallowed while a new session negotiation "+ + "is in progress") + }, + }, } // TestClient executes the client test suite, asserting the ability to backup