mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
peer: add mockUpdateHandler for use in mockMessageSwitch
This commit is contained in:
parent
b2e90480ed
commit
608d11dcbc
@ -40,7 +40,7 @@ func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
|
||||
broadcastTxChan := make(chan *wire.MsgTx)
|
||||
|
||||
alicePeer, bobChan, cleanUp, err := createTestPeer(
|
||||
notifier, broadcastTxChan, noUpdate,
|
||||
notifier, broadcastTxChan, noUpdate, nil,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test channels: %v", err)
|
||||
@ -143,7 +143,7 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
|
||||
broadcastTxChan := make(chan *wire.MsgTx)
|
||||
|
||||
alicePeer, bobChan, cleanUp, err := createTestPeer(
|
||||
notifier, broadcastTxChan, noUpdate,
|
||||
notifier, broadcastTxChan, noUpdate, nil,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test channels: %v", err)
|
||||
@ -265,7 +265,7 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
|
||||
broadcastTxChan := make(chan *wire.MsgTx)
|
||||
|
||||
alicePeer, bobChan, cleanUp, err := createTestPeer(
|
||||
notifier, broadcastTxChan, noUpdate,
|
||||
notifier, broadcastTxChan, noUpdate, nil,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test channels: %v", err)
|
||||
@ -459,7 +459,7 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
|
||||
broadcastTxChan := make(chan *wire.MsgTx)
|
||||
|
||||
alicePeer, bobChan, cleanUp, err := createTestPeer(
|
||||
notifier, broadcastTxChan, noUpdate,
|
||||
notifier, broadcastTxChan, noUpdate, nil,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test channels: %v", err)
|
||||
@ -795,7 +795,7 @@ func TestCustomShutdownScript(t *testing.T) {
|
||||
|
||||
// Open a channel.
|
||||
alicePeer, bobChan, cleanUp, err := createTestPeer(
|
||||
notifier, broadcastTxChan, test.update,
|
||||
notifier, broadcastTxChan, test.update, nil,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test channels: %v", err)
|
||||
|
@ -54,7 +54,8 @@ var noUpdate = func(a, b *channeldb.OpenChannel) {}
|
||||
// an updateChan function which can be used to modify the default values on
|
||||
// the channel states for each peer.
|
||||
func createTestPeer(notifier chainntnfs.ChainNotifier,
|
||||
publTx chan *wire.MsgTx, updateChan func(a, b *channeldb.OpenChannel)) (
|
||||
publTx chan *wire.MsgTx, updateChan func(a, b *channeldb.OpenChannel),
|
||||
mockSwitch *mockMessageSwitch) (
|
||||
*Brontide, *lnwallet.LightningChannel, func(), error) {
|
||||
|
||||
aliceKeyPriv, aliceKeyPub := btcec.PrivKeyFromBytes(
|
||||
@ -306,7 +307,11 @@ func createTestPeer(notifier chainntnfs.ChainNotifier,
|
||||
},
|
||||
}
|
||||
|
||||
htlcSwitch := &mockMessageSwitch{}
|
||||
// If mockSwitch is not set by the caller, set it to the default as the
|
||||
// caller does not need to control it.
|
||||
if mockSwitch == nil {
|
||||
mockSwitch = &mockMessageSwitch{}
|
||||
}
|
||||
|
||||
nodeSignerAlice := netann.NewNodeSigner(aliceKeySigner)
|
||||
|
||||
@ -349,7 +354,7 @@ func createTestPeer(notifier chainntnfs.ChainNotifier,
|
||||
PubKeyBytes: pubKey,
|
||||
ErrorBuffer: errBuffer,
|
||||
ChainIO: chainIO,
|
||||
Switch: htlcSwitch,
|
||||
Switch: mockSwitch,
|
||||
|
||||
ChanActiveTimeout: chanActiveTimeout,
|
||||
InterceptSwitch: htlcswitch.NewInterceptableSwitch(nil),
|
||||
@ -404,6 +409,37 @@ func (m *mockMessageSwitch) GetLinksByInterface(pub [33]byte) (
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// mockUpdateHandler is a mock implementation of the ChannelUpdateHandler
|
||||
// interface. It is used in mockMessageSwitch's GetLinksByInterface method.
|
||||
type mockUpdateHandler struct {
|
||||
cid lnwire.ChannelID
|
||||
}
|
||||
|
||||
// newMockUpdateHandler creates a new mockUpdateHandler.
|
||||
func newMockUpdateHandler(cid lnwire.ChannelID) *mockUpdateHandler {
|
||||
return &mockUpdateHandler{
|
||||
cid: cid,
|
||||
}
|
||||
}
|
||||
|
||||
// HandleChannelUpdate currently does nothing.
|
||||
func (m *mockUpdateHandler) HandleChannelUpdate(msg lnwire.Message) {}
|
||||
|
||||
// ChanID returns the mockUpdateHandler's cid.
|
||||
func (m *mockUpdateHandler) ChanID() lnwire.ChannelID { return m.cid }
|
||||
|
||||
// Bandwidth currently returns a dummy value.
|
||||
func (m *mockUpdateHandler) Bandwidth() lnwire.MilliSatoshi { return 0 }
|
||||
|
||||
// EligibleToForward currently returns a dummy value.
|
||||
func (m *mockUpdateHandler) EligibleToForward() bool { return false }
|
||||
|
||||
// MayAddOutgoingHtlc currently returns nil.
|
||||
func (m *mockUpdateHandler) MayAddOutgoingHtlc() error { return nil }
|
||||
|
||||
// ShutdownIfChannelClean currently returns nil.
|
||||
func (m *mockUpdateHandler) ShutdownIfChannelClean() error { return nil }
|
||||
|
||||
type mockMessageConn struct {
|
||||
t *testing.T
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user