multi: move mockChainIO, mockNotifier to lntest/mock

This commit is contained in:
eugene 2020-08-27 15:34:55 -04:00
parent 3fa5d042c9
commit c7cbacc35b
18 changed files with 241 additions and 308 deletions

View File

@ -1435,7 +1435,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
// Notify that the breaching transaction is confirmed, to trigger the // Notify that the breaching transaction is confirmed, to trigger the
// retribution logic. // retribution logic.
notifier := brar.cfg.Notifier.(*mockSpendNotifier) notifier := brar.cfg.Notifier.(*mockSpendNotifier)
notifier.confChannel <- &chainntnfs.TxConfirmation{} notifier.ConfChan <- &chainntnfs.TxConfirmation{}
// The breach arbiter should attempt to sweep all outputs on the // The breach arbiter should attempt to sweep all outputs on the
// breached commitment. We'll pretend that the HTLC output has been // breached commitment. We'll pretend that the HTLC output has been
@ -1511,7 +1511,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
// Deliver confirmation of sweep if the test expects it. // Deliver confirmation of sweep if the test expects it.
if test.sendFinalConf { if test.sendFinalConf {
notifier.confChannel <- &chainntnfs.TxConfirmation{} notifier.ConfChan <- &chainntnfs.TxConfirmation{}
} }
// Assert that the channel is fully resolved. // Assert that the channel is fully resolved.

View File

@ -8,8 +8,10 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/clock" "github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
) )
@ -80,8 +82,12 @@ func TestChainArbitratorRepublishCloses(t *testing.T) {
published := make(map[chainhash.Hash]int) published := make(map[chainhash.Hash]int)
chainArbCfg := ChainArbitratorConfig{ chainArbCfg := ChainArbitratorConfig{
ChainIO: &mockChainIO{}, ChainIO: &mock.ChainIO{},
Notifier: &mockNotifier{}, Notifier: &mock.ChainNotifier{
SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation),
},
PublishTx: func(tx *wire.MsgTx, _ string) error { PublishTx: func(tx *wire.MsgTx, _ string) error {
published[tx.TxHash()]++ published[tx.TxHash()]++
return nil return nil
@ -172,8 +178,12 @@ func TestResolveContract(t *testing.T) {
// chain arbitrator that should pick up these new channels and launch // chain arbitrator that should pick up these new channels and launch
// resolver for them. // resolver for them.
chainArbCfg := ChainArbitratorConfig{ chainArbCfg := ChainArbitratorConfig{
ChainIO: &mockChainIO{}, ChainIO: &mock.ChainIO{},
Notifier: &mockNotifier{}, Notifier: &mock.ChainNotifier{
SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation),
},
PublishTx: func(tx *wire.MsgTx, _ string) error { PublishTx: func(tx *wire.MsgTx, _ string) error {
return nil return nil
}, },

View File

@ -7,58 +7,15 @@ import (
"testing" "testing"
"time" "time"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
) )
type mockNotifier struct {
spendChan chan *chainntnfs.SpendDetail
epochChan chan *chainntnfs.BlockEpoch
confChan chan *chainntnfs.TxConfirmation
}
func (m *mockNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash, _ []byte, numConfs,
heightHint uint32) (*chainntnfs.ConfirmationEvent, error) {
return &chainntnfs.ConfirmationEvent{
Confirmed: m.confChan,
Cancel: func() {},
}, nil
}
func (m *mockNotifier) RegisterBlockEpochNtfn(
bestBlock *chainntnfs.BlockEpoch) (*chainntnfs.BlockEpochEvent, error) {
return &chainntnfs.BlockEpochEvent{
Epochs: m.epochChan,
Cancel: func() {},
}, nil
}
func (m *mockNotifier) Start() error {
return nil
}
func (m *mockNotifier) Started() bool {
return true
}
func (m *mockNotifier) Stop() error {
return nil
}
func (m *mockNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint, _ []byte,
heightHint uint32) (*chainntnfs.SpendEvent, error) {
return &chainntnfs.SpendEvent{
Spend: m.spendChan,
Cancel: func() {},
}, nil
}
// TestChainWatcherRemoteUnilateralClose tests that the chain watcher is able // TestChainWatcherRemoteUnilateralClose tests that the chain watcher is able
// to properly detect a normal unilateral close by the remote node using their // to properly detect a normal unilateral close by the remote node using their
// lowest commitment. // lowest commitment.
@ -77,8 +34,10 @@ func TestChainWatcherRemoteUnilateralClose(t *testing.T) {
// With the channels created, we'll now create a chain watcher instance // With the channels created, we'll now create a chain watcher instance
// which will be watching for any closes of Alice's channel. // which will be watching for any closes of Alice's channel.
aliceNotifier := &mockNotifier{ aliceNotifier := &mock.ChainNotifier{
spendChan: make(chan *chainntnfs.SpendDetail), SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{ aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
chanState: aliceChannel.State(), chanState: aliceChannel.State(),
@ -107,7 +66,7 @@ func TestChainWatcherRemoteUnilateralClose(t *testing.T) {
SpenderTxHash: &bobTxHash, SpenderTxHash: &bobTxHash,
SpendingTx: bobCommit, SpendingTx: bobCommit,
} }
aliceNotifier.spendChan <- bobSpend aliceNotifier.SpendChan <- bobSpend
// We should get a new spend event over the remote unilateral close // We should get a new spend event over the remote unilateral close
// event channel. // event channel.
@ -166,8 +125,10 @@ func TestChainWatcherRemoteUnilateralClosePendingCommit(t *testing.T) {
// With the channels created, we'll now create a chain watcher instance // With the channels created, we'll now create a chain watcher instance
// which will be watching for any closes of Alice's channel. // which will be watching for any closes of Alice's channel.
aliceNotifier := &mockNotifier{ aliceNotifier := &mock.ChainNotifier{
spendChan: make(chan *chainntnfs.SpendDetail), SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{ aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
chanState: aliceChannel.State(), chanState: aliceChannel.State(),
@ -216,7 +177,7 @@ func TestChainWatcherRemoteUnilateralClosePendingCommit(t *testing.T) {
SpenderTxHash: &bobTxHash, SpenderTxHash: &bobTxHash,
SpendingTx: bobCommit, SpendingTx: bobCommit,
} }
aliceNotifier.spendChan <- bobSpend aliceNotifier.SpendChan <- bobSpend
// We should get a new spend event over the remote unilateral close // We should get a new spend event over the remote unilateral close
// event channel. // event channel.
@ -292,8 +253,10 @@ func TestChainWatcherDataLossProtect(t *testing.T) {
// With the channels created, we'll now create a chain watcher // With the channels created, we'll now create a chain watcher
// instance which will be watching for any closes of Alice's // instance which will be watching for any closes of Alice's
// channel. // channel.
aliceNotifier := &mockNotifier{ aliceNotifier := &mock.ChainNotifier{
spendChan: make(chan *chainntnfs.SpendDetail), SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{ aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
chanState: aliceChannel.State(), chanState: aliceChannel.State(),
@ -350,7 +313,7 @@ func TestChainWatcherDataLossProtect(t *testing.T) {
SpenderTxHash: &bobTxHash, SpenderTxHash: &bobTxHash,
SpendingTx: bobCommit, SpendingTx: bobCommit,
} }
aliceNotifier.spendChan <- bobSpend aliceNotifier.SpendChan <- bobSpend
// We should get a new uni close resolution that indicates we // We should get a new uni close resolution that indicates we
// processed the DLP scenario. // processed the DLP scenario.
@ -461,8 +424,10 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
// With the channels created, we'll now create a chain watcher // With the channels created, we'll now create a chain watcher
// instance which will be watching for any closes of Alice's // instance which will be watching for any closes of Alice's
// channel. // channel.
aliceNotifier := &mockNotifier{ aliceNotifier := &mock.ChainNotifier{
spendChan: make(chan *chainntnfs.SpendDetail), SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{ aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
chanState: aliceChannel.State(), chanState: aliceChannel.State(),
@ -517,7 +482,7 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
SpenderTxHash: &aliceTxHash, SpenderTxHash: &aliceTxHash,
SpendingTx: aliceCommit, SpendingTx: aliceCommit,
} }
aliceNotifier.spendChan <- aliceSpend aliceNotifier.SpendChan <- aliceSpend
// We should get a local force close event from Alice as she // We should get a local force close event from Alice as she
// should be able to detect the close based on the commitment // should be able to detect the close based on the commitment

View File

@ -19,6 +19,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb/kvdb" "github.com/lightningnetwork/lnd/channeldb/kvdb"
"github.com/lightningnetwork/lnd/clock" "github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
) )
@ -334,10 +335,10 @@ func createTestChannelArbitrator(t *testing.T, log ArbitratorLog,
}, },
OutgoingBroadcastDelta: 5, OutgoingBroadcastDelta: 5,
IncomingBroadcastDelta: 5, IncomingBroadcastDelta: 5,
Notifier: &mockNotifier{ Notifier: &mock.ChainNotifier{
epochChan: make(chan *chainntnfs.BlockEpoch), EpochChan: make(chan *chainntnfs.BlockEpoch),
spendChan: make(chan *chainntnfs.SpendDetail), SpendChan: make(chan *chainntnfs.SpendDetail),
confChan: make(chan *chainntnfs.TxConfirmation), ConfChan: make(chan *chainntnfs.TxConfirmation),
}, },
IncubateOutputs: func(wire.OutPoint, IncubateOutputs: func(wire.OutPoint,
*lnwallet.OutgoingHtlcResolution, *lnwallet.OutgoingHtlcResolution,
@ -878,7 +879,7 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) {
// We'll grab the old notifier here as our resolvers are still holding // We'll grab the old notifier here as our resolvers are still holding
// a reference to this instance, and a new one will be created when we // a reference to this instance, and a new one will be created when we
// restart the channel arb below. // restart the channel arb below.
oldNotifier := chanArb.cfg.Notifier.(*mockNotifier) oldNotifier := chanArb.cfg.Notifier.(*mock.ChainNotifier)
// At this point, in order to simulate a restart, we'll re-create the // At this point, in order to simulate a restart, we'll re-create the
// channel arbitrator. We do this to ensure that all information // channel arbitrator. We do this to ensure that all information
@ -927,7 +928,7 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) {
} }
// Send a notification that the expiry height has been reached. // Send a notification that the expiry height has been reached.
oldNotifier.epochChan <- &chainntnfs.BlockEpoch{Height: 10} oldNotifier.EpochChan <- &chainntnfs.BlockEpoch{Height: 10}
// htlcOutgoingContestResolver is now transforming into a // htlcOutgoingContestResolver is now transforming into a
// htlcTimeoutResolver and should send the contract off for incubation. // htlcTimeoutResolver and should send the contract off for incubation.
@ -939,7 +940,7 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) {
// Notify resolver that the HTLC output of the commitment has been // Notify resolver that the HTLC output of the commitment has been
// spent. // spent.
oldNotifier.spendChan <- &chainntnfs.SpendDetail{SpendingTx: closeTx} oldNotifier.SpendChan <- &chainntnfs.SpendDetail{SpendingTx: closeTx}
// Finally, we should also receive a resolution message instructing the // Finally, we should also receive a resolution message instructing the
// switch to cancel back the HTLC. // switch to cancel back the HTLC.
@ -967,7 +968,7 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) {
} }
// Notify resolver that the second level transaction is spent. // Notify resolver that the second level transaction is spent.
oldNotifier.spendChan <- &chainntnfs.SpendDetail{SpendingTx: closeTx} oldNotifier.SpendChan <- &chainntnfs.SpendDetail{SpendingTx: closeTx}
// At this point channel should be marked as resolved. // At this point channel should be marked as resolved.
chanArbCtxNew.AssertStateTransitions(StateFullyResolved) chanArbCtxNew.AssertStateTransitions(StateFullyResolved)

View File

@ -10,6 +10,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channeldb/kvdb" "github.com/lightningnetwork/lnd/channeldb/kvdb"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/sweep" "github.com/lightningnetwork/lnd/sweep"
@ -17,7 +18,7 @@ import (
type commitSweepResolverTestContext struct { type commitSweepResolverTestContext struct {
resolver *commitSweepResolver resolver *commitSweepResolver
notifier *mockNotifier notifier *mock.ChainNotifier
sweeper *mockSweeper sweeper *mockSweeper
resolverResultChan chan resolveResult resolverResultChan chan resolveResult
t *testing.T t *testing.T
@ -26,10 +27,10 @@ type commitSweepResolverTestContext struct {
func newCommitSweepResolverTestContext(t *testing.T, func newCommitSweepResolverTestContext(t *testing.T,
resolution *lnwallet.CommitOutputResolution) *commitSweepResolverTestContext { resolution *lnwallet.CommitOutputResolution) *commitSweepResolverTestContext {
notifier := &mockNotifier{ notifier := &mock.ChainNotifier{
epochChan: make(chan *chainntnfs.BlockEpoch), EpochChan: make(chan *chainntnfs.BlockEpoch),
spendChan: make(chan *chainntnfs.SpendDetail), SpendChan: make(chan *chainntnfs.SpendDetail),
confChan: make(chan *chainntnfs.TxConfirmation), ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
sweeper := newMockSweeper() sweeper := newMockSweeper()
@ -83,7 +84,7 @@ func (i *commitSweepResolverTestContext) resolve() {
} }
func (i *commitSweepResolverTestContext) notifyEpoch(height int32) { func (i *commitSweepResolverTestContext) notifyEpoch(height int32) {
i.notifier.epochChan <- &chainntnfs.BlockEpoch{ i.notifier.EpochChan <- &chainntnfs.BlockEpoch{
Height: height, Height: height,
} }
} }
@ -189,7 +190,7 @@ func TestCommitSweepResolverNoDelay(t *testing.T) {
spendTx := &wire.MsgTx{} spendTx := &wire.MsgTx{}
spendHash := spendTx.TxHash() spendHash := spendTx.TxHash()
ctx.notifier.confChan <- &chainntnfs.TxConfirmation{ ctx.notifier.ConfChan <- &chainntnfs.TxConfirmation{
Tx: spendTx, Tx: spendTx,
} }
@ -267,7 +268,7 @@ func testCommitSweepResolverDelay(t *testing.T, sweepErr error) {
ctx.resolve() ctx.resolve()
ctx.notifier.confChan <- &chainntnfs.TxConfirmation{ ctx.notifier.ConfChan <- &chainntnfs.TxConfirmation{
BlockHeight: testInitialBlockHeight - 1, BlockHeight: testInitialBlockHeight - 1,
} }

View File

@ -12,6 +12,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb/kvdb" "github.com/lightningnetwork/lnd/channeldb/kvdb"
"github.com/lightningnetwork/lnd/htlcswitch/hop" "github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
@ -295,7 +296,7 @@ type incomingResolverTestContext struct {
registry *mockRegistry registry *mockRegistry
witnessBeacon *mockWitnessBeacon witnessBeacon *mockWitnessBeacon
resolver *htlcIncomingContestResolver resolver *htlcIncomingContestResolver
notifier *mockNotifier notifier *mock.ChainNotifier
onionProcessor *mockOnionProcessor onionProcessor *mockOnionProcessor
resolveErr chan error resolveErr chan error
nextResolver ContractResolver nextResolver ContractResolver
@ -303,10 +304,10 @@ type incomingResolverTestContext struct {
} }
func newIncomingResolverTestContext(t *testing.T, isExit bool) *incomingResolverTestContext { func newIncomingResolverTestContext(t *testing.T, isExit bool) *incomingResolverTestContext {
notifier := &mockNotifier{ notifier := &mock.ChainNotifier{
epochChan: make(chan *chainntnfs.BlockEpoch), EpochChan: make(chan *chainntnfs.BlockEpoch),
spendChan: make(chan *chainntnfs.SpendDetail), SpendChan: make(chan *chainntnfs.SpendDetail),
confChan: make(chan *chainntnfs.TxConfirmation), ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
witnessBeacon := newMockWitnessBeacon() witnessBeacon := newMockWitnessBeacon()
registry := &mockRegistry{ registry := &mockRegistry{
@ -377,7 +378,7 @@ func (i *incomingResolverTestContext) resolve() {
} }
func (i *incomingResolverTestContext) notifyEpoch(height int32) { func (i *incomingResolverTestContext) notifyEpoch(height int32) {
i.notifier.epochChan <- &chainntnfs.BlockEpoch{ i.notifier.EpochChan <- &chainntnfs.BlockEpoch{
Height: height, Height: height,
} }
} }

View File

@ -9,6 +9,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channeldb/kvdb" "github.com/lightningnetwork/lnd/channeldb/kvdb"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
@ -80,7 +81,7 @@ func TestHtlcOutgoingResolverRemoteClaim(t *testing.T) {
spendHash := spendTx.TxHash() spendHash := spendTx.TxHash()
ctx.notifier.spendChan <- &chainntnfs.SpendDetail{ ctx.notifier.SpendChan <- &chainntnfs.SpendDetail{
SpendingTx: spendTx, SpendingTx: spendTx,
SpenderTxHash: &spendHash, SpenderTxHash: &spendHash,
} }
@ -114,7 +115,7 @@ type resolveResult struct {
type outgoingResolverTestContext struct { type outgoingResolverTestContext struct {
resolver *htlcOutgoingContestResolver resolver *htlcOutgoingContestResolver
notifier *mockNotifier notifier *mock.ChainNotifier
preimageDB *mockWitnessBeacon preimageDB *mockWitnessBeacon
resolverResultChan chan resolveResult resolverResultChan chan resolveResult
resolutionChan chan ResolutionMsg resolutionChan chan ResolutionMsg
@ -122,10 +123,10 @@ type outgoingResolverTestContext struct {
} }
func newOutgoingResolverTestContext(t *testing.T) *outgoingResolverTestContext { func newOutgoingResolverTestContext(t *testing.T) *outgoingResolverTestContext {
notifier := &mockNotifier{ notifier := &mock.ChainNotifier{
epochChan: make(chan *chainntnfs.BlockEpoch), EpochChan: make(chan *chainntnfs.BlockEpoch),
spendChan: make(chan *chainntnfs.SpendDetail), SpendChan: make(chan *chainntnfs.SpendDetail),
confChan: make(chan *chainntnfs.TxConfirmation), ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
checkPointChan := make(chan struct{}, 1) checkPointChan := make(chan struct{}, 1)
@ -212,7 +213,7 @@ func (i *outgoingResolverTestContext) resolve() {
} }
func (i *outgoingResolverTestContext) notifyEpoch(height int32) { func (i *outgoingResolverTestContext) notifyEpoch(height int32) {
i.notifier.epochChan <- &chainntnfs.BlockEpoch{ i.notifier.EpochChan <- &chainntnfs.BlockEpoch{
Height: height, Height: height,
} }
} }

View File

@ -8,6 +8,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channeldb/kvdb" "github.com/lightningnetwork/lnd/channeldb/kvdb"
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
) )
@ -16,16 +17,16 @@ var testHtlcAmt = lnwire.MilliSatoshi(200000)
type htlcSuccessResolverTestContext struct { type htlcSuccessResolverTestContext struct {
resolver *htlcSuccessResolver resolver *htlcSuccessResolver
notifier *mockNotifier notifier *mock.ChainNotifier
resolverResultChan chan resolveResult resolverResultChan chan resolveResult
t *testing.T t *testing.T
} }
func newHtlcSuccessResolverTextContext(t *testing.T) *htlcSuccessResolverTestContext { func newHtlcSuccessResolverTextContext(t *testing.T) *htlcSuccessResolverTestContext {
notifier := &mockNotifier{ notifier := &mock.ChainNotifier{
epochChan: make(chan *chainntnfs.BlockEpoch), EpochChan: make(chan *chainntnfs.BlockEpoch),
spendChan: make(chan *chainntnfs.SpendDetail), SpendChan: make(chan *chainntnfs.SpendDetail),
confChan: make(chan *chainntnfs.TxConfirmation), ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
checkPointChan := make(chan struct{}, 1) checkPointChan := make(chan struct{}, 1)
@ -116,7 +117,7 @@ func TestSingleStageSuccess(t *testing.T) {
// We send a confirmation for our sweep tx to indicate that our sweep // We send a confirmation for our sweep tx to indicate that our sweep
// succeeded. // succeeded.
resolve := func(ctx *htlcSuccessResolverTestContext) { resolve := func(ctx *htlcSuccessResolverTestContext) {
ctx.notifier.confChan <- &chainntnfs.TxConfirmation{ ctx.notifier.ConfChan <- &chainntnfs.TxConfirmation{
Tx: ctx.resolver.sweepTx, Tx: ctx.resolver.sweepTx,
BlockHeight: testInitialBlockHeight - 1, BlockHeight: testInitialBlockHeight - 1,
} }
@ -165,7 +166,7 @@ func TestSecondStageResolution(t *testing.T) {
// We send a spend notification for our output to resolve our htlc. // We send a spend notification for our output to resolve our htlc.
resolve := func(ctx *htlcSuccessResolverTestContext) { resolve := func(ctx *htlcSuccessResolverTestContext) {
ctx.notifier.spendChan <- &chainntnfs.SpendDetail{ ctx.notifier.SpendChan <- &chainntnfs.SpendDetail{
SpendingTx: sweepTx, SpendingTx: sweepTx,
SpenderTxHash: &sweepHash, SpenderTxHash: &sweepHash,
} }

View File

@ -203,10 +203,10 @@ func TestHtlcTimeoutResolver(t *testing.T) {
}, },
} }
notifier := &mockNotifier{ notifier := &mock.ChainNotifier{
epochChan: make(chan *chainntnfs.BlockEpoch), EpochChan: make(chan *chainntnfs.BlockEpoch),
spendChan: make(chan *chainntnfs.SpendDetail), SpendChan: make(chan *chainntnfs.SpendDetail),
confChan: make(chan *chainntnfs.TxConfirmation), ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
witnessBeacon := newMockWitnessBeacon() witnessBeacon := newMockWitnessBeacon()
@ -331,7 +331,7 @@ func TestHtlcTimeoutResolver(t *testing.T) {
spendTxHash := spendingTx.TxHash() spendTxHash := spendingTx.TxHash()
select { select {
case notifier.spendChan <- &chainntnfs.SpendDetail{ case notifier.SpendChan <- &chainntnfs.SpendDetail{
SpendingTx: spendingTx, SpendingTx: spendingTx,
SpenderTxHash: &spendTxHash, SpenderTxHash: &spendTxHash,
}: }:
@ -388,7 +388,7 @@ func TestHtlcTimeoutResolver(t *testing.T) {
// only if this is a local commitment transaction. // only if this is a local commitment transaction.
if !testCase.remoteCommit { if !testCase.remoteCommit {
select { select {
case notifier.spendChan <- &chainntnfs.SpendDetail{ case notifier.SpendChan <- &chainntnfs.SpendDetail{
SpendingTx: spendingTx, SpendingTx: spendingTx,
SpenderTxHash: &spendTxHash, SpenderTxHash: &spendTxHash,
}: }:

View File

@ -305,8 +305,8 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
signer := &mock.SingleSigner{ signer := &mock.SingleSigner{
Privkey: alicePrivKey, Privkey: alicePrivKey,
} }
bio := &mockChainIO{ bio := &mock.ChainIO{
bestHeight: fundingBroadcastHeight, BestHeight: fundingBroadcastHeight,
} }
// The mock channel event notifier will receive events for each pending // The mock channel event notifier will receive events for each pending

View File

@ -10,6 +10,7 @@ import (
sphinx "github.com/lightningnetwork/lightning-onion" sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/lntest/mock"
) )
const ( const (
@ -28,16 +29,18 @@ func tempDecayedLogPath(t *testing.T) string {
} }
// startup sets up the DecayedLog and possibly the garbage collector. // startup sets up the DecayedLog and possibly the garbage collector.
func startup(dbPath string, notifier bool) (sphinx.ReplayLog, *mockNotifier, func startup(dbPath string, notifier bool) (sphinx.ReplayLog,
*sphinx.HashPrefix, error) { *mock.ChainNotifier, *sphinx.HashPrefix, error) {
var log sphinx.ReplayLog var log sphinx.ReplayLog
var chainNotifier *mockNotifier var chainNotifier *mock.ChainNotifier
if notifier { if notifier {
// Create the MockNotifier which triggers the garbage collector // Create the MockNotifier which triggers the garbage collector
chainNotifier = &mockNotifier{ chainNotifier = &mock.ChainNotifier{
epochChan: make(chan *chainntnfs.BlockEpoch, 1), SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch, 1),
ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
// Initialize the DecayedLog object // Initialize the DecayedLog object
@ -99,7 +102,7 @@ func TestDecayedLogGarbageCollector(t *testing.T) {
// should remove the entry by block 100001. // should remove the entry by block 100001.
// Send block 100000 // Send block 100000
notifier.epochChan <- &chainntnfs.BlockEpoch{ notifier.EpochChan <- &chainntnfs.BlockEpoch{
Height: 100000, Height: 100000,
} }
@ -114,7 +117,7 @@ func TestDecayedLogGarbageCollector(t *testing.T) {
} }
// Send block 100001 (expiry block) // Send block 100001 (expiry block)
notifier.epochChan <- &chainntnfs.BlockEpoch{ notifier.EpochChan <- &chainntnfs.BlockEpoch{
Height: 100001, Height: 100001,
} }
@ -175,7 +178,7 @@ func TestDecayedLogPersistentGarbageCollector(t *testing.T) {
// Send a block notification to the garbage collector that expires // Send a block notification to the garbage collector that expires
// the stored CLTV. // the stored CLTV.
notifier2.epochChan <- &chainntnfs.BlockEpoch{ notifier2.EpochChan <- &chainntnfs.BlockEpoch{
Height: int32(100001), Height: int32(100001),
} }

View File

@ -15,7 +15,6 @@ import (
"time" "time"
"github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/go-errors/errors" "github.com/go-errors/errors"
sphinx "github.com/lightningnetwork/lightning-onion" sphinx "github.com/lightningnetwork/lightning-onion"
@ -26,6 +25,7 @@ import (
"github.com/lightningnetwork/lnd/htlcswitch/hop" "github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/lnpeer" "github.com/lightningnetwork/lnd/lnpeer"
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
@ -170,7 +170,11 @@ func initSwitchWithDB(startingHeight uint32, db *channeldb.DB) (*Switch, error)
FetchLastChannelUpdate: func(lnwire.ShortChannelID) (*lnwire.ChannelUpdate, error) { FetchLastChannelUpdate: func(lnwire.ShortChannelID) (*lnwire.ChannelUpdate, error) {
return nil, nil return nil, nil
}, },
Notifier: &mockNotifier{}, Notifier: &mock.ChainNotifier{
SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation),
},
FwdEventTicker: ticker.NewForce(DefaultFwdEventInterval), FwdEventTicker: ticker.NewForce(DefaultFwdEventInterval),
LogEventTicker: ticker.NewForce(DefaultLogInterval), LogEventTicker: ticker.NewForce(DefaultLogInterval),
AckEventTicker: ticker.NewForce(DefaultAckInterval), AckEventTicker: ticker.NewForce(DefaultAckInterval),
@ -853,42 +857,6 @@ func (i *mockInvoiceRegistry) HodlUnsubscribeAll(subscriber chan<- interface{})
var _ InvoiceDatabase = (*mockInvoiceRegistry)(nil) var _ InvoiceDatabase = (*mockInvoiceRegistry)(nil)
type mockNotifier struct {
epochChan chan *chainntnfs.BlockEpoch
}
func (m *mockNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash, _ []byte,
numConfs uint32, heightHint uint32) (*chainntnfs.ConfirmationEvent, error) {
return nil, nil
}
func (m *mockNotifier) RegisterBlockEpochNtfn(
bestBlock *chainntnfs.BlockEpoch) (*chainntnfs.BlockEpochEvent, error) {
return &chainntnfs.BlockEpochEvent{
Epochs: m.epochChan,
Cancel: func() {},
}, nil
}
func (m *mockNotifier) Start() error {
return nil
}
func (m *mockNotifier) Started() bool {
return true
}
func (m *mockNotifier) Stop() error {
return nil
}
func (m *mockNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint, _ []byte,
heightHint uint32) (*chainntnfs.SpendEvent, error) {
return &chainntnfs.SpendEvent{
Spend: make(chan *chainntnfs.SpendDetail),
}, nil
}
type mockCircuitMap struct { type mockCircuitMap struct {
lookup chan *PaymentCircuit lookup chan *PaymentCircuit
} }

34
lntest/mock/chainio.go Normal file
View File

@ -0,0 +1,34 @@
package mock
import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
)
// ChainIO is a mock implementation of the BlockChainIO interface.
type ChainIO struct {
BestHeight int32
}
// GetBestBlock currently returns dummy values.
func (c *ChainIO) GetBestBlock() (*chainhash.Hash, int32, error) {
return chaincfg.TestNet3Params.GenesisHash, c.BestHeight, nil
}
// GetUtxo currently returns dummy values.
func (c *ChainIO) GetUtxo(op *wire.OutPoint, _ []byte,
heightHint uint32, _ <-chan struct{}) (*wire.TxOut, error) {
return nil, nil
}
// GetBlockHash currently returns dummy values.
func (c *ChainIO) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) {
return nil, nil
}
// GetBlock currently returns dummy values.
func (c *ChainIO) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) {
return nil, nil
}

View File

@ -0,0 +1,64 @@
package mock
import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainntnfs"
)
// ChainNotifier is a mock implementation of the ChainNotifier interface.
type ChainNotifier struct {
SpendChan chan *chainntnfs.SpendDetail
EpochChan chan *chainntnfs.BlockEpoch
ConfChan chan *chainntnfs.TxConfirmation
}
// RegisterConfirmationsNtfn returns a ConfirmationEvent that contains a channel
// that the tx confirmation will go over.
func (c *ChainNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
pkScript []byte, numConfs, heightHint uint32) (*chainntnfs.ConfirmationEvent,
error) {
return &chainntnfs.ConfirmationEvent{
Confirmed: c.ConfChan,
Cancel: func() {},
}, nil
}
// RegisterSpendNtfn returns a SpendEvent that contains a channel that the spend
// details will go over.
func (c *ChainNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
pkScript []byte, heightHint uint32) (*chainntnfs.SpendEvent, error) {
return &chainntnfs.SpendEvent{
Spend: c.SpendChan,
Cancel: func() {},
}, nil
}
// RegisterBlockEpochNtfn returns a BlockEpochEvent that contains a channel that
// block epochs will go over.
func (c *ChainNotifier) RegisterBlockEpochNtfn(blockEpoch *chainntnfs.BlockEpoch) (
*chainntnfs.BlockEpochEvent, error) {
return &chainntnfs.BlockEpochEvent{
Epochs: c.EpochChan,
Cancel: func() {},
}, nil
}
// Start currently returns a dummy value.
func (c *ChainNotifier) Start() error {
return nil
}
// Started currently returns a dummy value.
func (c *ChainNotifier) Started() bool {
return true
}
// Stop currently returns a dummy value.
func (c *ChainNotifier) Stop() error {
return nil
}

76
mock.go
View File

@ -3,58 +3,19 @@ package lnd
import ( import (
"sync" "sync"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lntest/mock"
) )
// The block height returned by the mock BlockChainIO's GetBestBlock. // The block height returned by the mock BlockChainIO's GetBestBlock.
const fundingBroadcastHeight = 123 const fundingBroadcastHeight = 123
type mockNotfier struct { // mockSpendNotifier extends the mock.ChainNotifier so that spend
confChannel chan *chainntnfs.TxConfirmation // notifications can be triggered and delivered to subscribers.
}
func (m *mockNotfier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
_ []byte, numConfs, heightHint uint32) (*chainntnfs.ConfirmationEvent, error) {
return &chainntnfs.ConfirmationEvent{
Confirmed: m.confChannel,
}, nil
}
func (m *mockNotfier) RegisterBlockEpochNtfn(
bestBlock *chainntnfs.BlockEpoch) (*chainntnfs.BlockEpochEvent, error) {
return &chainntnfs.BlockEpochEvent{
Epochs: make(chan *chainntnfs.BlockEpoch),
Cancel: func() {},
}, nil
}
func (m *mockNotfier) Start() error {
return nil
}
func (m *mockNotfier) Started() bool {
return true
}
func (m *mockNotfier) Stop() error {
return nil
}
func (m *mockNotfier) RegisterSpendNtfn(outpoint *wire.OutPoint, _ []byte,
heightHint uint32) (*chainntnfs.SpendEvent, error) {
return &chainntnfs.SpendEvent{
Spend: make(chan *chainntnfs.SpendDetail),
Cancel: func() {},
}, nil
}
// mockSpendNotifier extends the mockNotifier so that spend notifications can be
// triggered and delivered to subscribers.
type mockSpendNotifier struct { type mockSpendNotifier struct {
*mockNotfier *mock.ChainNotifier
spendMap map[wire.OutPoint][]chan *chainntnfs.SpendDetail spendMap map[wire.OutPoint][]chan *chainntnfs.SpendDetail
spends map[wire.OutPoint]*chainntnfs.SpendDetail spends map[wire.OutPoint]*chainntnfs.SpendDetail
mtx sync.Mutex mtx sync.Mutex
@ -62,8 +23,10 @@ type mockSpendNotifier struct {
func makeMockSpendNotifier() *mockSpendNotifier { func makeMockSpendNotifier() *mockSpendNotifier {
return &mockSpendNotifier{ return &mockSpendNotifier{
mockNotfier: &mockNotfier{ ChainNotifier: &mock.ChainNotifier{
confChannel: make(chan *chainntnfs.TxConfirmation), SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation),
}, },
spendMap: make(map[wire.OutPoint][]chan *chainntnfs.SpendDetail), spendMap: make(map[wire.OutPoint][]chan *chainntnfs.SpendDetail),
spends: make(map[wire.OutPoint]*chainntnfs.SpendDetail), spends: make(map[wire.OutPoint]*chainntnfs.SpendDetail),
@ -133,26 +96,3 @@ func (m *mockSpendNotifier) Spend(outpoint *wire.OutPoint, height int32,
} }
} }
} }
type mockChainIO struct {
bestHeight int32
}
var _ lnwallet.BlockChainIO = (*mockChainIO)(nil)
func (m *mockChainIO) GetBestBlock() (*chainhash.Hash, int32, error) {
return chaincfg.TestNet3Params.GenesisHash, m.bestHeight, nil
}
func (*mockChainIO) GetUtxo(op *wire.OutPoint, _ []byte,
heightHint uint32, _ <-chan struct{}) (*wire.TxOut, error) {
return nil, nil
}
func (*mockChainIO) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) {
return nil, nil
}
func (*mockChainIO) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) {
return nil, nil
}

View File

@ -12,6 +12,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lnwallet/chancloser" "github.com/lightningnetwork/lnd/lnwallet/chancloser"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
) )
@ -33,8 +34,10 @@ var (
func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) { func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
t.Parallel() t.Parallel()
notifier := &mockNotifier{ notifier := &mock.ChainNotifier{
confChannel: make(chan *chainntnfs.TxConfirmation), SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
broadcastTxChan := make(chan *wire.MsgTx) broadcastTxChan := make(chan *wire.MsgTx)
@ -126,7 +129,7 @@ func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
} }
// Alice should be waiting in a goroutine for a confirmation. // Alice should be waiting in a goroutine for a confirmation.
notifier.confChannel <- &chainntnfs.TxConfirmation{} notifier.ConfChan <- &chainntnfs.TxConfirmation{}
} }
// TestPeerChannelClosureAcceptFeeInitiator tests the shutdown initiator's // TestPeerChannelClosureAcceptFeeInitiator tests the shutdown initiator's
@ -134,8 +137,10 @@ func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) { func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
t.Parallel() t.Parallel()
notifier := &mockNotifier{ notifier := &mock.ChainNotifier{
confChannel: make(chan *chainntnfs.TxConfirmation), SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
broadcastTxChan := make(chan *wire.MsgTx) broadcastTxChan := make(chan *wire.MsgTx)
@ -245,7 +250,7 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
} }
// Alice should be waiting on a single confirmation for the coop close tx. // Alice should be waiting on a single confirmation for the coop close tx.
notifier.confChannel <- &chainntnfs.TxConfirmation{} notifier.ConfChan <- &chainntnfs.TxConfirmation{}
} }
// TestPeerChannelClosureFeeNegotiationsResponder tests the shutdown // TestPeerChannelClosureFeeNegotiationsResponder tests the shutdown
@ -254,8 +259,10 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) { func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
t.Parallel() t.Parallel()
notifier := &mockNotifier{ notifier := &mock.ChainNotifier{
confChannel: make(chan *chainntnfs.TxConfirmation), SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
broadcastTxChan := make(chan *wire.MsgTx) broadcastTxChan := make(chan *wire.MsgTx)
@ -437,7 +444,7 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
} }
// Alice should be waiting on a single confirmation for the coop close tx. // Alice should be waiting on a single confirmation for the coop close tx.
notifier.confChannel <- &chainntnfs.TxConfirmation{} notifier.ConfChan <- &chainntnfs.TxConfirmation{}
} }
// TestPeerChannelClosureFeeNegotiationsInitiator tests the shutdown // TestPeerChannelClosureFeeNegotiationsInitiator tests the shutdown
@ -446,8 +453,10 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) { func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
t.Parallel() t.Parallel()
notifier := &mockNotifier{ notifier := &mock.ChainNotifier{
confChannel: make(chan *chainntnfs.TxConfirmation), SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
broadcastTxChan := make(chan *wire.MsgTx) broadcastTxChan := make(chan *wire.MsgTx)
@ -642,7 +651,7 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
} }
// Alice should be waiting on a single confirmation for the coop close tx. // Alice should be waiting on a single confirmation for the coop close tx.
notifier.confChannel <- &chainntnfs.TxConfirmation{} notifier.ConfChan <- &chainntnfs.TxConfirmation{}
} }
// TestChooseDeliveryScript tests that chooseDeliveryScript correctly errors // TestChooseDeliveryScript tests that chooseDeliveryScript correctly errors
@ -779,8 +788,10 @@ func TestCustomShutdownScript(t *testing.T) {
test := test test := test
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
notifier := &mockNotifier{ notifier := &mock.ChainNotifier{
confChannel: make(chan *chainntnfs.TxConfirmation), SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
ConfChan: make(chan *chainntnfs.TxConfirmation),
} }
broadcastTxChan := make(chan *wire.MsgTx) broadcastTxChan := make(chan *wire.MsgTx)

View File

@ -99,74 +99,6 @@ var (
// call the setup code with no custom values on the channels set up. // call the setup code with no custom values on the channels set up.
var noUpdate = func(a, b *channeldb.OpenChannel) {} var noUpdate = func(a, b *channeldb.OpenChannel) {}
type mockChainIO struct {
bestHeight int32
}
func (m *mockChainIO) GetBestBlock() (*chainhash.Hash, int32, error) {
return nil, m.bestHeight, nil
}
func (*mockChainIO) GetUtxo(op *wire.OutPoint, _ []byte,
heightHint uint32, _ <-chan struct{}) (*wire.TxOut, error) {
return nil, nil
}
func (*mockChainIO) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) {
return nil, nil
}
func (*mockChainIO) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) {
return nil, nil
}
var _ lnwallet.BlockChainIO = (*mockChainIO)(nil)
type mockNotifier struct {
confChannel chan *chainntnfs.TxConfirmation
}
func (m *mockNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
_ []byte, numConfs, heightHint uint32) (*chainntnfs.ConfirmationEvent,
error) {
return &chainntnfs.ConfirmationEvent{
Confirmed: m.confChannel,
}, nil
}
func (m *mockNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint, _ []byte,
heightHint uint32) (*chainntnfs.SpendEvent, error) {
return &chainntnfs.SpendEvent{
Spend: make(chan *chainntnfs.SpendDetail),
Cancel: func() {},
}, nil
}
func (m *mockNotifier) RegisterBlockEpochNtfn(
bestBlock *chainntnfs.BlockEpoch) (*chainntnfs.BlockEpochEvent, error) {
return &chainntnfs.BlockEpochEvent{
Epochs: make(chan *chainntnfs.BlockEpoch),
Cancel: func() {},
}, nil
}
func (m *mockNotifier) Start() error {
return nil
}
func (m *mockNotifier) Stop() error {
return nil
}
func (m *mockNotifier) Started() bool {
return true
}
var _ chainntnfs.ChainNotifier = (*mockNotifier)(nil)
// createTestPeer creates a channel between two nodes, and returns a peer for // createTestPeer creates a channel between two nodes, and returns a peer for
// one of the nodes, together with the channel seen from both nodes. It takes // one of the nodes, together with the channel seen from both nodes. It takes
// an updateChan function which can be used to modify the default values on // an updateChan function which can be used to modify the default values on
@ -414,8 +346,8 @@ func createTestPeer(notifier chainntnfs.ChainNotifier,
} }
_ = bobPool.Start() _ = bobPool.Start()
chainIO := &mockChainIO{ chainIO := &mock.ChainIO{
bestHeight: broadcastHeight, BestHeight: broadcastHeight,
} }
wallet := &lnwallet.LightningWallet{ wallet := &lnwallet.LightningWallet{
WalletController: &mock.WalletController{ WalletController: &mock.WalletController{

View File

@ -20,6 +20,7 @@ import (
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/sweep" "github.com/lightningnetwork/lnd/sweep"
) )
@ -398,7 +399,7 @@ func TestBabyOutputSerialization(t *testing.T) {
type nurseryTestContext struct { type nurseryTestContext struct {
nursery *utxoNursery nursery *utxoNursery
notifier *sweep.MockNotifier notifier *sweep.MockNotifier
chainIO *mockChainIO chainIO *mock.ChainIO
publishChan chan wire.MsgTx publishChan chan wire.MsgTx
store *nurseryStoreInterceptor store *nurseryStoreInterceptor
restart func() bool restart func() bool
@ -441,8 +442,8 @@ func createNurseryTestContext(t *testing.T,
timeoutChan := make(chan chan time.Time) timeoutChan := make(chan chan time.Time)
chainIO := &mockChainIO{ chainIO := &mock.ChainIO{
bestHeight: 0, BestHeight: 0,
} }
sweeper := newMockSweeper(t) sweeper := newMockSweeper(t)
@ -522,7 +523,7 @@ func createNurseryTestContext(t *testing.T,
func (ctx *nurseryTestContext) notifyEpoch(height int32) { func (ctx *nurseryTestContext) notifyEpoch(height int32) {
ctx.t.Helper() ctx.t.Helper()
ctx.chainIO.bestHeight = height ctx.chainIO.BestHeight = height
ctx.notifier.NotifyEpoch(height) ctx.notifier.NotifyEpoch(height)
} }