lnd test: check inactive channel disables in testSendUpdateDisableChannel

This commit is contained in:
Johan T. Halseth 2018-08-09 10:03:15 +02:00
parent 52941cec53
commit 7b1ac0a979
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -10902,6 +10902,7 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to create carol's node: %v", err)
}
defer shutdownAndAssert(net, t, carol)
if err := net.ConnectNodes(ctxb, net.Alice, carol); err != nil {
t.Fatalf("unable to connect alice to carol: %v", err)
}
@ -10910,6 +10911,34 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
ctxt, t, net, net.Alice, carol, chanAmt, 0, false,
)
// We create a new node Eve that has an inactive channel timeout of
// just 2 seconds (down from the default 20m). It will be used to test
// channel updates for channels going inactive.
eve, err := net.NewNode("Eve", []string{"--inactivechantimeout=2s"})
if err != nil {
t.Fatalf("unable to create eve's node: %v", err)
}
defer shutdownAndAssert(net, t, eve)
// Give Eve some coins.
err = net.SendCoins(ctxb, btcutil.SatoshiPerBitcoin, eve)
if err != nil {
t.Fatalf("unable to send coins to eve: %v", err)
}
// Connect Eve to Carol and Bob, and open a channel to carol.
if err := net.ConnectNodes(ctxb, eve, carol); err != nil {
t.Fatalf("unable to connect alice to carol: %v", err)
}
if err := net.ConnectNodes(ctxb, eve, net.Bob); err != nil {
t.Fatalf("unable to connect eve to bob: %v", err)
}
ctxt, _ = context.WithTimeout(ctxb, timeout)
chanPointEveCarol := openChannelAndAssert(
ctxt, t, net, eve, carol, chanAmt, 0, false,
)
// Launch a node for Dave which will connect to Bob in order to receive
// graph updates from. This will ensure that the channel updates are
// propagated throughout the network.
@ -10934,6 +10963,29 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
Disabled: true,
}
// Let Carol go offline. Since Eve has an inactive timeout of 2s, we
// expect her to send an update disabling the channel.
restartCarol, err := net.SuspendNode(carol)
if err != nil {
t.Fatalf("unable to suspend carol: %v", err)
}
waitForChannelUpdate(
t, daveUpdates, eve.PubKeyStr, expectedPolicy,
chanPointEveCarol,
)
// We restart Carol. Since the channel now becomes active again, Eve
// should send a ChannelUpdate setting the channel no longer disabled.
if err := restartCarol(); err != nil {
t.Fatalf("unable to restart carol: %v", err)
}
expectedPolicy.Disabled = false
waitForChannelUpdate(
t, daveUpdates, eve.PubKeyStr, expectedPolicy,
chanPointEveCarol,
)
// Close Alice's channels with Bob and Carol cooperatively and
// unilaterally respectively.
ctxt, _ = context.WithTimeout(ctxb, timeout)
@ -10950,6 +11002,7 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
// Now that the channel close processes have been started, we should
// receive an update marking each as disabled.
expectedPolicy.Disabled = true
waitForChannelUpdate(
t, daveUpdates, net.Alice.PubKeyStr, expectedPolicy,
chanPointAliceBob, chanPointAliceCarol,
@ -10961,6 +11014,24 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("expected transactions not found in mempool: %v", err)
}
mineBlocks(t, net, 1)
// Also do this check for Eve's channel with Carol.
ctxt, _ = context.WithTimeout(ctxb, timeout)
_, _, err = net.CloseChannel(ctxt, eve, chanPointEveCarol, false)
if err != nil {
t.Fatalf("unable to close channel: %v", err)
}
waitForChannelUpdate(
t, daveUpdates, eve.PubKeyStr, expectedPolicy,
chanPointEveCarol,
)
_, err = waitForNTxsInMempool(net.Miner.Node, 1, timeout)
if err != nil {
t.Fatalf("expected transactions not found in mempool: %v", err)
}
mineBlocks(t, net, 1)
}
type testCase struct {