wtclient: test case re-add removed tower
This commit is contained in:
parent
b195d39ad7
commit
f6f0d3819f
@ -366,17 +366,18 @@ func (c *mockChannel) getState(i uint64) (*wire.MsgTx, *lnwallet.BreachRetributi
|
|||||||
}
|
}
|
||||||
|
|
||||||
type testHarness struct {
|
type testHarness struct {
|
||||||
t *testing.T
|
t *testing.T
|
||||||
cfg harnessCfg
|
cfg harnessCfg
|
||||||
signer *wtmock.MockSigner
|
signer *wtmock.MockSigner
|
||||||
capacity lnwire.MilliSatoshi
|
capacity lnwire.MilliSatoshi
|
||||||
clientDB *wtmock.ClientDB
|
clientDB *wtmock.ClientDB
|
||||||
clientCfg *wtclient.Config
|
clientCfg *wtclient.Config
|
||||||
client wtclient.Client
|
client wtclient.Client
|
||||||
serverDB *wtmock.TowerDB
|
serverAddr *lnwire.NetAddress
|
||||||
serverCfg *wtserver.Config
|
serverDB *wtmock.TowerDB
|
||||||
server *wtserver.Server
|
serverCfg *wtserver.Config
|
||||||
net *mockNet
|
server *wtserver.Server
|
||||||
|
net *mockNet
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
channels map[lnwire.ChannelID]*mockChannel
|
channels map[lnwire.ChannelID]*mockChannel
|
||||||
@ -467,18 +468,19 @@ func newHarness(t *testing.T, cfg harnessCfg) *testHarness {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h := &testHarness{
|
h := &testHarness{
|
||||||
t: t,
|
t: t,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
signer: signer,
|
signer: signer,
|
||||||
capacity: cfg.localBalance + cfg.remoteBalance,
|
capacity: cfg.localBalance + cfg.remoteBalance,
|
||||||
clientDB: clientDB,
|
clientDB: clientDB,
|
||||||
clientCfg: clientCfg,
|
clientCfg: clientCfg,
|
||||||
client: client,
|
client: client,
|
||||||
serverDB: serverDB,
|
serverAddr: towerAddr,
|
||||||
serverCfg: serverCfg,
|
serverDB: serverDB,
|
||||||
server: server,
|
serverCfg: serverCfg,
|
||||||
net: mockNet,
|
server: server,
|
||||||
channels: make(map[lnwire.ChannelID]*mockChannel),
|
net: mockNet,
|
||||||
|
channels: make(map[lnwire.ChannelID]*mockChannel),
|
||||||
}
|
}
|
||||||
|
|
||||||
h.makeChannel(0, h.cfg.localBalance, h.cfg.remoteBalance)
|
h.makeChannel(0, h.cfg.localBalance, h.cfg.remoteBalance)
|
||||||
@ -782,6 +784,25 @@ func (h *testHarness) assertUpdatesForPolicy(hints []blob.BreachHint,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// addTower adds a tower found at `addr` to the client.
|
||||||
|
func (h *testHarness) addTower(addr *lnwire.NetAddress) {
|
||||||
|
h.t.Helper()
|
||||||
|
|
||||||
|
if err := h.client.AddTower(addr); err != nil {
|
||||||
|
h.t.Fatalf("unable to add tower: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// removeTower removes a tower from the client. If `addr` is specified, then the
|
||||||
|
// only said address is removed from the tower.
|
||||||
|
func (h *testHarness) removeTower(pubKey *btcec.PublicKey, addr net.Addr) {
|
||||||
|
h.t.Helper()
|
||||||
|
|
||||||
|
if err := h.client.RemoveTower(pubKey, addr); err != nil {
|
||||||
|
h.t.Fatalf("unable to remove tower: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
localBalance = lnwire.MilliSatoshi(100000000)
|
localBalance = lnwire.MilliSatoshi(100000000)
|
||||||
remoteBalance = lnwire.MilliSatoshi(200000000)
|
remoteBalance = lnwire.MilliSatoshi(200000000)
|
||||||
@ -1396,6 +1417,60 @@ var clientTests = []clientTest{
|
|||||||
h.waitServerUpdates(hints, 5*time.Second)
|
h.waitServerUpdates(hints, 5*time.Second)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// Asserts that the client can continue making backups to a
|
||||||
|
// tower that's been re-added after it's been removed.
|
||||||
|
name: "re-add removed tower",
|
||||||
|
cfg: harnessCfg{
|
||||||
|
localBalance: localBalance,
|
||||||
|
remoteBalance: remoteBalance,
|
||||||
|
policy: wtpolicy.Policy{
|
||||||
|
TxPolicy: wtpolicy.TxPolicy{
|
||||||
|
BlobType: blob.TypeAltruistCommit,
|
||||||
|
SweepFeeRate: wtpolicy.DefaultSweepFeeRate,
|
||||||
|
},
|
||||||
|
MaxUpdates: 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fn: func(h *testHarness) {
|
||||||
|
const (
|
||||||
|
chanID = 0
|
||||||
|
numUpdates = 4
|
||||||
|
)
|
||||||
|
|
||||||
|
// Create four channel updates and only back up the
|
||||||
|
// first two.
|
||||||
|
hints := h.advanceChannelN(chanID, numUpdates)
|
||||||
|
h.backupStates(chanID, 0, numUpdates/2, nil)
|
||||||
|
h.waitServerUpdates(hints[:numUpdates/2], 5*time.Second)
|
||||||
|
|
||||||
|
// Fully remove the tower, causing its existing sessions
|
||||||
|
// to be marked inactive.
|
||||||
|
h.removeTower(h.serverAddr.IdentityKey, nil)
|
||||||
|
|
||||||
|
// Back up the remaining states. Since the tower has
|
||||||
|
// been removed, it shouldn't receive any updates.
|
||||||
|
h.backupStates(chanID, numUpdates/2, numUpdates, nil)
|
||||||
|
h.waitServerUpdates(nil, time.Second)
|
||||||
|
|
||||||
|
// Re-add the tower. We prevent the tower from acking
|
||||||
|
// session creation to ensure the inactive sessions are
|
||||||
|
// not used.
|
||||||
|
h.server.Stop()
|
||||||
|
h.serverCfg.NoAckCreateSession = true
|
||||||
|
h.startServer()
|
||||||
|
h.addTower(h.serverAddr)
|
||||||
|
h.waitServerUpdates(nil, time.Second)
|
||||||
|
|
||||||
|
// Finally, allow the tower to ack session creation,
|
||||||
|
// allowing the state updates to be sent through the new
|
||||||
|
// session.
|
||||||
|
h.server.Stop()
|
||||||
|
h.serverCfg.NoAckCreateSession = false
|
||||||
|
h.startServer()
|
||||||
|
h.waitServerUpdates(hints[numUpdates/2:], 5*time.Second)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestClient executes the client test suite, asserting the ability to backup
|
// TestClient executes the client test suite, asserting the ability to backup
|
||||||
|
Loading…
Reference in New Issue
Block a user