multi: move mockChainIO, mockNotifier to lntest/mock
This commit is contained in:
parent
3fa5d042c9
commit
c7cbacc35b
@ -1435,7 +1435,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
|
||||
// Notify that the breaching transaction is confirmed, to trigger the
|
||||
// retribution logic.
|
||||
notifier := brar.cfg.Notifier.(*mockSpendNotifier)
|
||||
notifier.confChannel <- &chainntnfs.TxConfirmation{}
|
||||
notifier.ConfChan <- &chainntnfs.TxConfirmation{}
|
||||
|
||||
// The breach arbiter should attempt to sweep all outputs on the
|
||||
// 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.
|
||||
if test.sendFinalConf {
|
||||
notifier.confChannel <- &chainntnfs.TxConfirmation{}
|
||||
notifier.ConfChan <- &chainntnfs.TxConfirmation{}
|
||||
}
|
||||
|
||||
// Assert that the channel is fully resolved.
|
||||
|
@ -8,8 +8,10 @@ import (
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/lightningnetwork/lnd/lntest/mock"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
)
|
||||
|
||||
@ -80,8 +82,12 @@ func TestChainArbitratorRepublishCloses(t *testing.T) {
|
||||
published := make(map[chainhash.Hash]int)
|
||||
|
||||
chainArbCfg := ChainArbitratorConfig{
|
||||
ChainIO: &mockChainIO{},
|
||||
Notifier: &mockNotifier{},
|
||||
ChainIO: &mock.ChainIO{},
|
||||
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 {
|
||||
published[tx.TxHash()]++
|
||||
return nil
|
||||
@ -172,8 +178,12 @@ func TestResolveContract(t *testing.T) {
|
||||
// chain arbitrator that should pick up these new channels and launch
|
||||
// resolver for them.
|
||||
chainArbCfg := ChainArbitratorConfig{
|
||||
ChainIO: &mockChainIO{},
|
||||
Notifier: &mockNotifier{},
|
||||
ChainIO: &mock.ChainIO{},
|
||||
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 {
|
||||
return nil
|
||||
},
|
||||
|
@ -7,58 +7,15 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntest/mock"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"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
|
||||
// to properly detect a normal unilateral close by the remote node using their
|
||||
// lowest commitment.
|
||||
@ -77,8 +34,10 @@ 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.
|
||||
aliceNotifier := &mockNotifier{
|
||||
spendChan: make(chan *chainntnfs.SpendDetail),
|
||||
aliceNotifier := &mock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
|
||||
chanState: aliceChannel.State(),
|
||||
@ -107,7 +66,7 @@ func TestChainWatcherRemoteUnilateralClose(t *testing.T) {
|
||||
SpenderTxHash: &bobTxHash,
|
||||
SpendingTx: bobCommit,
|
||||
}
|
||||
aliceNotifier.spendChan <- bobSpend
|
||||
aliceNotifier.SpendChan <- bobSpend
|
||||
|
||||
// We should get a new spend event over the remote unilateral close
|
||||
// event channel.
|
||||
@ -166,8 +125,10 @@ 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.
|
||||
aliceNotifier := &mockNotifier{
|
||||
spendChan: make(chan *chainntnfs.SpendDetail),
|
||||
aliceNotifier := &mock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
|
||||
chanState: aliceChannel.State(),
|
||||
@ -216,7 +177,7 @@ func TestChainWatcherRemoteUnilateralClosePendingCommit(t *testing.T) {
|
||||
SpenderTxHash: &bobTxHash,
|
||||
SpendingTx: bobCommit,
|
||||
}
|
||||
aliceNotifier.spendChan <- bobSpend
|
||||
aliceNotifier.SpendChan <- bobSpend
|
||||
|
||||
// We should get a new spend event over the remote unilateral close
|
||||
// event channel.
|
||||
@ -292,8 +253,10 @@ 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.
|
||||
aliceNotifier := &mockNotifier{
|
||||
spendChan: make(chan *chainntnfs.SpendDetail),
|
||||
aliceNotifier := &mock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
|
||||
chanState: aliceChannel.State(),
|
||||
@ -350,7 +313,7 @@ func TestChainWatcherDataLossProtect(t *testing.T) {
|
||||
SpenderTxHash: &bobTxHash,
|
||||
SpendingTx: bobCommit,
|
||||
}
|
||||
aliceNotifier.spendChan <- bobSpend
|
||||
aliceNotifier.SpendChan <- bobSpend
|
||||
|
||||
// We should get a new uni close resolution that indicates we
|
||||
// processed the DLP scenario.
|
||||
@ -461,8 +424,10 @@ 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.
|
||||
aliceNotifier := &mockNotifier{
|
||||
spendChan: make(chan *chainntnfs.SpendDetail),
|
||||
aliceNotifier := &mock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
aliceChainWatcher, err := newChainWatcher(chainWatcherConfig{
|
||||
chanState: aliceChannel.State(),
|
||||
@ -517,7 +482,7 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
|
||||
SpenderTxHash: &aliceTxHash,
|
||||
SpendingTx: aliceCommit,
|
||||
}
|
||||
aliceNotifier.spendChan <- aliceSpend
|
||||
aliceNotifier.SpendChan <- aliceSpend
|
||||
|
||||
// We should get a local force close event from Alice as she
|
||||
// should be able to detect the close based on the commitment
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntest/mock"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
@ -334,10 +335,10 @@ func createTestChannelArbitrator(t *testing.T, log ArbitratorLog,
|
||||
},
|
||||
OutgoingBroadcastDelta: 5,
|
||||
IncomingBroadcastDelta: 5,
|
||||
Notifier: &mockNotifier{
|
||||
epochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
spendChan: make(chan *chainntnfs.SpendDetail),
|
||||
confChan: make(chan *chainntnfs.TxConfirmation),
|
||||
Notifier: &mock.ChainNotifier{
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
},
|
||||
IncubateOutputs: func(wire.OutPoint,
|
||||
*lnwallet.OutgoingHtlcResolution,
|
||||
@ -878,7 +879,7 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) {
|
||||
// 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
|
||||
// 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
|
||||
// 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.
|
||||
oldNotifier.epochChan <- &chainntnfs.BlockEpoch{Height: 10}
|
||||
oldNotifier.EpochChan <- &chainntnfs.BlockEpoch{Height: 10}
|
||||
|
||||
// htlcOutgoingContestResolver is now transforming into a
|
||||
// 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
|
||||
// spent.
|
||||
oldNotifier.spendChan <- &chainntnfs.SpendDetail{SpendingTx: closeTx}
|
||||
oldNotifier.SpendChan <- &chainntnfs.SpendDetail{SpendingTx: closeTx}
|
||||
|
||||
// Finally, we should also receive a resolution message instructing the
|
||||
// switch to cancel back the HTLC.
|
||||
@ -967,7 +968,7 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) {
|
||||
}
|
||||
|
||||
// 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.
|
||||
chanArbCtxNew.AssertStateTransitions(StateFullyResolved)
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntest/mock"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/sweep"
|
||||
@ -17,7 +18,7 @@ import (
|
||||
|
||||
type commitSweepResolverTestContext struct {
|
||||
resolver *commitSweepResolver
|
||||
notifier *mockNotifier
|
||||
notifier *mock.ChainNotifier
|
||||
sweeper *mockSweeper
|
||||
resolverResultChan chan resolveResult
|
||||
t *testing.T
|
||||
@ -26,10 +27,10 @@ type commitSweepResolverTestContext struct {
|
||||
func newCommitSweepResolverTestContext(t *testing.T,
|
||||
resolution *lnwallet.CommitOutputResolution) *commitSweepResolverTestContext {
|
||||
|
||||
notifier := &mockNotifier{
|
||||
epochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
spendChan: make(chan *chainntnfs.SpendDetail),
|
||||
confChan: make(chan *chainntnfs.TxConfirmation),
|
||||
notifier := &mock.ChainNotifier{
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
|
||||
sweeper := newMockSweeper()
|
||||
@ -83,7 +84,7 @@ func (i *commitSweepResolverTestContext) resolve() {
|
||||
}
|
||||
|
||||
func (i *commitSweepResolverTestContext) notifyEpoch(height int32) {
|
||||
i.notifier.epochChan <- &chainntnfs.BlockEpoch{
|
||||
i.notifier.EpochChan <- &chainntnfs.BlockEpoch{
|
||||
Height: height,
|
||||
}
|
||||
}
|
||||
@ -189,7 +190,7 @@ func TestCommitSweepResolverNoDelay(t *testing.T) {
|
||||
|
||||
spendTx := &wire.MsgTx{}
|
||||
spendHash := spendTx.TxHash()
|
||||
ctx.notifier.confChan <- &chainntnfs.TxConfirmation{
|
||||
ctx.notifier.ConfChan <- &chainntnfs.TxConfirmation{
|
||||
Tx: spendTx,
|
||||
}
|
||||
|
||||
@ -267,7 +268,7 @@ func testCommitSweepResolverDelay(t *testing.T, sweepErr error) {
|
||||
|
||||
ctx.resolve()
|
||||
|
||||
ctx.notifier.confChan <- &chainntnfs.TxConfirmation{
|
||||
ctx.notifier.ConfChan <- &chainntnfs.TxConfirmation{
|
||||
BlockHeight: testInitialBlockHeight - 1,
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||
"github.com/lightningnetwork/lnd/invoices"
|
||||
"github.com/lightningnetwork/lnd/lntest/mock"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@ -295,7 +296,7 @@ type incomingResolverTestContext struct {
|
||||
registry *mockRegistry
|
||||
witnessBeacon *mockWitnessBeacon
|
||||
resolver *htlcIncomingContestResolver
|
||||
notifier *mockNotifier
|
||||
notifier *mock.ChainNotifier
|
||||
onionProcessor *mockOnionProcessor
|
||||
resolveErr chan error
|
||||
nextResolver ContractResolver
|
||||
@ -303,10 +304,10 @@ type incomingResolverTestContext struct {
|
||||
}
|
||||
|
||||
func newIncomingResolverTestContext(t *testing.T, isExit bool) *incomingResolverTestContext {
|
||||
notifier := &mockNotifier{
|
||||
epochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
spendChan: make(chan *chainntnfs.SpendDetail),
|
||||
confChan: make(chan *chainntnfs.TxConfirmation),
|
||||
notifier := &mock.ChainNotifier{
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
witnessBeacon := newMockWitnessBeacon()
|
||||
registry := &mockRegistry{
|
||||
@ -377,7 +378,7 @@ func (i *incomingResolverTestContext) resolve() {
|
||||
}
|
||||
|
||||
func (i *incomingResolverTestContext) notifyEpoch(height int32) {
|
||||
i.notifier.epochChan <- &chainntnfs.BlockEpoch{
|
||||
i.notifier.EpochChan <- &chainntnfs.BlockEpoch{
|
||||
Height: height,
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntest/mock"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@ -80,7 +81,7 @@ func TestHtlcOutgoingResolverRemoteClaim(t *testing.T) {
|
||||
|
||||
spendHash := spendTx.TxHash()
|
||||
|
||||
ctx.notifier.spendChan <- &chainntnfs.SpendDetail{
|
||||
ctx.notifier.SpendChan <- &chainntnfs.SpendDetail{
|
||||
SpendingTx: spendTx,
|
||||
SpenderTxHash: &spendHash,
|
||||
}
|
||||
@ -114,7 +115,7 @@ type resolveResult struct {
|
||||
|
||||
type outgoingResolverTestContext struct {
|
||||
resolver *htlcOutgoingContestResolver
|
||||
notifier *mockNotifier
|
||||
notifier *mock.ChainNotifier
|
||||
preimageDB *mockWitnessBeacon
|
||||
resolverResultChan chan resolveResult
|
||||
resolutionChan chan ResolutionMsg
|
||||
@ -122,10 +123,10 @@ type outgoingResolverTestContext struct {
|
||||
}
|
||||
|
||||
func newOutgoingResolverTestContext(t *testing.T) *outgoingResolverTestContext {
|
||||
notifier := &mockNotifier{
|
||||
epochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
spendChan: make(chan *chainntnfs.SpendDetail),
|
||||
confChan: make(chan *chainntnfs.TxConfirmation),
|
||||
notifier := &mock.ChainNotifier{
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
|
||||
checkPointChan := make(chan struct{}, 1)
|
||||
@ -212,7 +213,7 @@ func (i *outgoingResolverTestContext) resolve() {
|
||||
}
|
||||
|
||||
func (i *outgoingResolverTestContext) notifyEpoch(height int32) {
|
||||
i.notifier.epochChan <- &chainntnfs.BlockEpoch{
|
||||
i.notifier.EpochChan <- &chainntnfs.BlockEpoch{
|
||||
Height: height,
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/lntest/mock"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
@ -16,16 +17,16 @@ var testHtlcAmt = lnwire.MilliSatoshi(200000)
|
||||
|
||||
type htlcSuccessResolverTestContext struct {
|
||||
resolver *htlcSuccessResolver
|
||||
notifier *mockNotifier
|
||||
notifier *mock.ChainNotifier
|
||||
resolverResultChan chan resolveResult
|
||||
t *testing.T
|
||||
}
|
||||
|
||||
func newHtlcSuccessResolverTextContext(t *testing.T) *htlcSuccessResolverTestContext {
|
||||
notifier := &mockNotifier{
|
||||
epochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
spendChan: make(chan *chainntnfs.SpendDetail),
|
||||
confChan: make(chan *chainntnfs.TxConfirmation),
|
||||
notifier := &mock.ChainNotifier{
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
|
||||
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
|
||||
// succeeded.
|
||||
resolve := func(ctx *htlcSuccessResolverTestContext) {
|
||||
ctx.notifier.confChan <- &chainntnfs.TxConfirmation{
|
||||
ctx.notifier.ConfChan <- &chainntnfs.TxConfirmation{
|
||||
Tx: ctx.resolver.sweepTx,
|
||||
BlockHeight: testInitialBlockHeight - 1,
|
||||
}
|
||||
@ -165,7 +166,7 @@ func TestSecondStageResolution(t *testing.T) {
|
||||
|
||||
// We send a spend notification for our output to resolve our htlc.
|
||||
resolve := func(ctx *htlcSuccessResolverTestContext) {
|
||||
ctx.notifier.spendChan <- &chainntnfs.SpendDetail{
|
||||
ctx.notifier.SpendChan <- &chainntnfs.SpendDetail{
|
||||
SpendingTx: sweepTx,
|
||||
SpenderTxHash: &sweepHash,
|
||||
}
|
||||
|
@ -203,10 +203,10 @@ func TestHtlcTimeoutResolver(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
notifier := &mockNotifier{
|
||||
epochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
spendChan: make(chan *chainntnfs.SpendDetail),
|
||||
confChan: make(chan *chainntnfs.TxConfirmation),
|
||||
notifier := &mock.ChainNotifier{
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
witnessBeacon := newMockWitnessBeacon()
|
||||
|
||||
@ -331,7 +331,7 @@ func TestHtlcTimeoutResolver(t *testing.T) {
|
||||
spendTxHash := spendingTx.TxHash()
|
||||
|
||||
select {
|
||||
case notifier.spendChan <- &chainntnfs.SpendDetail{
|
||||
case notifier.SpendChan <- &chainntnfs.SpendDetail{
|
||||
SpendingTx: spendingTx,
|
||||
SpenderTxHash: &spendTxHash,
|
||||
}:
|
||||
@ -388,7 +388,7 @@ func TestHtlcTimeoutResolver(t *testing.T) {
|
||||
// only if this is a local commitment transaction.
|
||||
if !testCase.remoteCommit {
|
||||
select {
|
||||
case notifier.spendChan <- &chainntnfs.SpendDetail{
|
||||
case notifier.SpendChan <- &chainntnfs.SpendDetail{
|
||||
SpendingTx: spendingTx,
|
||||
SpenderTxHash: &spendTxHash,
|
||||
}:
|
||||
|
@ -305,8 +305,8 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
|
||||
signer := &mock.SingleSigner{
|
||||
Privkey: alicePrivKey,
|
||||
}
|
||||
bio := &mockChainIO{
|
||||
bestHeight: fundingBroadcastHeight,
|
||||
bio := &mock.ChainIO{
|
||||
BestHeight: fundingBroadcastHeight,
|
||||
}
|
||||
|
||||
// The mock channel event notifier will receive events for each pending
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/lntest/mock"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -28,16 +29,18 @@ func tempDecayedLogPath(t *testing.T) string {
|
||||
}
|
||||
|
||||
// startup sets up the DecayedLog and possibly the garbage collector.
|
||||
func startup(dbPath string, notifier bool) (sphinx.ReplayLog, *mockNotifier,
|
||||
*sphinx.HashPrefix, error) {
|
||||
func startup(dbPath string, notifier bool) (sphinx.ReplayLog,
|
||||
*mock.ChainNotifier, *sphinx.HashPrefix, error) {
|
||||
|
||||
var log sphinx.ReplayLog
|
||||
var chainNotifier *mockNotifier
|
||||
var chainNotifier *mock.ChainNotifier
|
||||
if notifier {
|
||||
|
||||
// Create the MockNotifier which triggers the garbage collector
|
||||
chainNotifier = &mockNotifier{
|
||||
epochChan: make(chan *chainntnfs.BlockEpoch, 1),
|
||||
chainNotifier = &mock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch, 1),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
|
||||
// Initialize the DecayedLog object
|
||||
@ -99,7 +102,7 @@ func TestDecayedLogGarbageCollector(t *testing.T) {
|
||||
// should remove the entry by block 100001.
|
||||
|
||||
// Send block 100000
|
||||
notifier.epochChan <- &chainntnfs.BlockEpoch{
|
||||
notifier.EpochChan <- &chainntnfs.BlockEpoch{
|
||||
Height: 100000,
|
||||
}
|
||||
|
||||
@ -114,7 +117,7 @@ func TestDecayedLogGarbageCollector(t *testing.T) {
|
||||
}
|
||||
|
||||
// Send block 100001 (expiry block)
|
||||
notifier.epochChan <- &chainntnfs.BlockEpoch{
|
||||
notifier.EpochChan <- &chainntnfs.BlockEpoch{
|
||||
Height: 100001,
|
||||
}
|
||||
|
||||
@ -175,7 +178,7 @@ func TestDecayedLogPersistentGarbageCollector(t *testing.T) {
|
||||
|
||||
// Send a block notification to the garbage collector that expires
|
||||
// the stored CLTV.
|
||||
notifier2.epochChan <- &chainntnfs.BlockEpoch{
|
||||
notifier2.EpochChan <- &chainntnfs.BlockEpoch{
|
||||
Height: int32(100001),
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/go-errors/errors"
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
@ -26,6 +25,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||
"github.com/lightningnetwork/lnd/invoices"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
"github.com/lightningnetwork/lnd/lntest/mock"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"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) {
|
||||
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),
|
||||
LogEventTicker: ticker.NewForce(DefaultLogInterval),
|
||||
AckEventTicker: ticker.NewForce(DefaultAckInterval),
|
||||
@ -853,42 +857,6 @@ func (i *mockInvoiceRegistry) HodlUnsubscribeAll(subscriber chan<- interface{})
|
||||
|
||||
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 {
|
||||
lookup chan *PaymentCircuit
|
||||
}
|
||||
|
34
lntest/mock/chainio.go
Normal file
34
lntest/mock/chainio.go
Normal 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
|
||||
}
|
64
lntest/mock/chainnotifier.go
Normal file
64
lntest/mock/chainnotifier.go
Normal 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
76
mock.go
@ -3,58 +3,19 @@ package lnd
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
|
||||
"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.
|
||||
const fundingBroadcastHeight = 123
|
||||
|
||||
type mockNotfier struct {
|
||||
confChannel chan *chainntnfs.TxConfirmation
|
||||
}
|
||||
|
||||
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.
|
||||
// mockSpendNotifier extends the mock.ChainNotifier so that spend
|
||||
// notifications can be triggered and delivered to subscribers.
|
||||
type mockSpendNotifier struct {
|
||||
*mockNotfier
|
||||
*mock.ChainNotifier
|
||||
spendMap map[wire.OutPoint][]chan *chainntnfs.SpendDetail
|
||||
spends map[wire.OutPoint]*chainntnfs.SpendDetail
|
||||
mtx sync.Mutex
|
||||
@ -62,8 +23,10 @@ type mockSpendNotifier struct {
|
||||
|
||||
func makeMockSpendNotifier() *mockSpendNotifier {
|
||||
return &mockSpendNotifier{
|
||||
mockNotfier: &mockNotfier{
|
||||
confChannel: make(chan *chainntnfs.TxConfirmation),
|
||||
ChainNotifier: &mock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
},
|
||||
spendMap: make(map[wire.OutPoint][]chan *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
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/lntest/mock"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chancloser"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
@ -33,8 +34,10 @@ var (
|
||||
func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
notifier := &mockNotifier{
|
||||
confChannel: make(chan *chainntnfs.TxConfirmation),
|
||||
notifier := &mock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
broadcastTxChan := make(chan *wire.MsgTx)
|
||||
|
||||
@ -126,7 +129,7 @@ func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
|
||||
}
|
||||
|
||||
// Alice should be waiting in a goroutine for a confirmation.
|
||||
notifier.confChannel <- &chainntnfs.TxConfirmation{}
|
||||
notifier.ConfChan <- &chainntnfs.TxConfirmation{}
|
||||
}
|
||||
|
||||
// TestPeerChannelClosureAcceptFeeInitiator tests the shutdown initiator's
|
||||
@ -134,8 +137,10 @@ func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
|
||||
func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
notifier := &mockNotifier{
|
||||
confChannel: make(chan *chainntnfs.TxConfirmation),
|
||||
notifier := &mock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
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.
|
||||
notifier.confChannel <- &chainntnfs.TxConfirmation{}
|
||||
notifier.ConfChan <- &chainntnfs.TxConfirmation{}
|
||||
}
|
||||
|
||||
// TestPeerChannelClosureFeeNegotiationsResponder tests the shutdown
|
||||
@ -254,8 +259,10 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
|
||||
func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
notifier := &mockNotifier{
|
||||
confChannel: make(chan *chainntnfs.TxConfirmation),
|
||||
notifier := &mock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
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.
|
||||
notifier.confChannel <- &chainntnfs.TxConfirmation{}
|
||||
notifier.ConfChan <- &chainntnfs.TxConfirmation{}
|
||||
}
|
||||
|
||||
// TestPeerChannelClosureFeeNegotiationsInitiator tests the shutdown
|
||||
@ -446,8 +453,10 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
|
||||
func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
notifier := &mockNotifier{
|
||||
confChannel: make(chan *chainntnfs.TxConfirmation),
|
||||
notifier := &mock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
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.
|
||||
notifier.confChannel <- &chainntnfs.TxConfirmation{}
|
||||
notifier.ConfChan <- &chainntnfs.TxConfirmation{}
|
||||
}
|
||||
|
||||
// TestChooseDeliveryScript tests that chooseDeliveryScript correctly errors
|
||||
@ -779,8 +788,10 @@ func TestCustomShutdownScript(t *testing.T) {
|
||||
test := test
|
||||
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
notifier := &mockNotifier{
|
||||
confChannel: make(chan *chainntnfs.TxConfirmation),
|
||||
notifier := &mock.ChainNotifier{
|
||||
SpendChan: make(chan *chainntnfs.SpendDetail),
|
||||
EpochChan: make(chan *chainntnfs.BlockEpoch),
|
||||
ConfChan: make(chan *chainntnfs.TxConfirmation),
|
||||
}
|
||||
broadcastTxChan := make(chan *wire.MsgTx)
|
||||
|
||||
|
@ -99,74 +99,6 @@ var (
|
||||
// call the setup code with no custom values on the channels set up.
|
||||
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
|
||||
// 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
|
||||
@ -414,8 +346,8 @@ func createTestPeer(notifier chainntnfs.ChainNotifier,
|
||||
}
|
||||
_ = bobPool.Start()
|
||||
|
||||
chainIO := &mockChainIO{
|
||||
bestHeight: broadcastHeight,
|
||||
chainIO := &mock.ChainIO{
|
||||
BestHeight: broadcastHeight,
|
||||
}
|
||||
wallet := &lnwallet.LightningWallet{
|
||||
WalletController: &mock.WalletController{
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntest/mock"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/sweep"
|
||||
)
|
||||
@ -398,7 +399,7 @@ func TestBabyOutputSerialization(t *testing.T) {
|
||||
type nurseryTestContext struct {
|
||||
nursery *utxoNursery
|
||||
notifier *sweep.MockNotifier
|
||||
chainIO *mockChainIO
|
||||
chainIO *mock.ChainIO
|
||||
publishChan chan wire.MsgTx
|
||||
store *nurseryStoreInterceptor
|
||||
restart func() bool
|
||||
@ -441,8 +442,8 @@ func createNurseryTestContext(t *testing.T,
|
||||
|
||||
timeoutChan := make(chan chan time.Time)
|
||||
|
||||
chainIO := &mockChainIO{
|
||||
bestHeight: 0,
|
||||
chainIO := &mock.ChainIO{
|
||||
BestHeight: 0,
|
||||
}
|
||||
|
||||
sweeper := newMockSweeper(t)
|
||||
@ -522,7 +523,7 @@ func createNurseryTestContext(t *testing.T,
|
||||
func (ctx *nurseryTestContext) notifyEpoch(height int32) {
|
||||
ctx.t.Helper()
|
||||
|
||||
ctx.chainIO.bestHeight = height
|
||||
ctx.chainIO.BestHeight = height
|
||||
ctx.notifier.NotifyEpoch(height)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user