contractcourt: update existing chain watcher tests due to new logic
All the tests need to send a confirmation _after_ the spend is detected now.
This commit is contained in:
1 parent
ce779a9707
commit
e0f7b0a033
1 file changed
+37
-12
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/chainio"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/fn/v2"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
lnmock "github.com/lightningnetwork/lnd/lntest/mock"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
@@ -34,16 +35,19 @@ func TestChainWatcherRemoteUnilateralClose(t *testing.T) {
|
||||
|
||||
// With the channels created, we'll now create a chain watcher instance
|
||||
// which will be watching for any closes of Alice's channel.
|
||||
confRegistered := make(chan struct{}, 1)
|
||||
aliceNotifier := &lnmock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail, 1),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail, 1),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation, 1),
|
||||
ConfRegistered: confRegistered,
|
||||
}
|
||||
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
|
||||
chanState: aliceChannel.State(),
|
||||
notifier: aliceNotifier,
|
||||
signer: aliceChannel.Signer,
|
||||
extractStateNumHint: lnwallet.GetStateNumHint,
|
||||
chanCloseConfs: fn.Some(uint32(1)),
|
||||
})
|
||||
require.NoError(t, err, "unable to create chain watcher")
|
||||
err = aliceChainWatcher.Start()
|
||||
@@ -90,6 +94,11 @@ func TestChainWatcherRemoteUnilateralClose(t *testing.T) {
|
||||
t.Fatalf("unable to send blockbeat")
|
||||
}
|
||||
|
||||
// Wait for the chain watcher to register for confirmations and send
|
||||
// the confirmation. Since we set chanCloseConfs to 1, one confirmation
|
||||
// is sufficient.
|
||||
aliceNotifier.WaitForConfRegistrationAndSend(t)
|
||||
|
||||
// We should get a new spend event over the remote unilateral close
|
||||
// event channel.
|
||||
var uniClose *RemoteUnilateralCloseInfo
|
||||
@@ -144,16 +153,19 @@ func TestChainWatcherRemoteUnilateralClosePendingCommit(t *testing.T) {
|
||||
|
||||
// With the channels created, we'll now create a chain watcher instance
|
||||
// which will be watching for any closes of Alice's channel.
|
||||
confRegistered := make(chan struct{}, 1)
|
||||
aliceNotifier := &lnmock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
ConfRegistered: confRegistered,
|
||||
}
|
||||
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
|
||||
chanState: aliceChannel.State(),
|
||||
notifier: aliceNotifier,
|
||||
signer: aliceChannel.Signer,
|
||||
extractStateNumHint: lnwallet.GetStateNumHint,
|
||||
chanCloseConfs: fn.Some(uint32(1)),
|
||||
})
|
||||
require.NoError(t, err, "unable to create chain watcher")
|
||||
if err := aliceChainWatcher.Start(); err != nil {
|
||||
@@ -219,6 +231,11 @@ func TestChainWatcherRemoteUnilateralClosePendingCommit(t *testing.T) {
|
||||
t.Fatalf("unable to send blockbeat")
|
||||
}
|
||||
|
||||
// Wait for the chain watcher to register for confirmations and send
|
||||
// the confirmation. Since we set chanCloseConfs to 1, one confirmation
|
||||
// is sufficient.
|
||||
aliceNotifier.WaitForConfRegistrationAndSend(t)
|
||||
|
||||
// We should get a new spend event over the remote unilateral close
|
||||
// event channel.
|
||||
var uniClose *RemoteUnilateralCloseInfo
|
||||
@@ -331,10 +348,12 @@ func TestChainWatcherDataLossProtect(t *testing.T) {
|
||||
// With the channels created, we'll now create a chain watcher
|
||||
// instance which will be watching for any closes of Alice's
|
||||
// channel.
|
||||
confRegistered := make(chan struct{}, 1)
|
||||
aliceNotifier := &lnmock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
ConfRegistered: confRegistered,
|
||||
}
|
||||
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
|
||||
chanState: aliceChanState,
|
||||
@@ -407,6 +426,8 @@ func TestChainWatcherDataLossProtect(t *testing.T) {
|
||||
t.Fatalf("unable to send blockbeat")
|
||||
}
|
||||
|
||||
aliceNotifier.WaitForConfRegistrationAndSend(t)
|
||||
|
||||
// We should get a new uni close resolution that indicates we
|
||||
// processed the DLP scenario.
|
||||
var uniClose *RemoteUnilateralCloseInfo
|
||||
@@ -532,10 +553,12 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
|
||||
// With the channels created, we'll now create a chain watcher
|
||||
// instance which will be watching for any closes of Alice's
|
||||
// channel.
|
||||
confRegistered := make(chan struct{}, 1)
|
||||
aliceNotifier := &lnmock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
ConfRegistered: confRegistered,
|
||||
}
|
||||
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
|
||||
chanState: aliceChanState,
|
||||
@@ -604,6 +627,8 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
|
||||
t.Fatalf("unable to send blockbeat")
|
||||
}
|
||||
|
||||
aliceNotifier.WaitForConfRegistrationAndSend(t)
|
||||
|
||||
// We should get a local force close event from Alice as she
|
||||
// should be able to detect the close based on the commitment
|
||||
// outputs.
|
||||
|
||||
Reference in new issue
Block a user