htlcswitch/multi: update tests for lnpeer.Peer iface
This commit is contained in:
parent
4380c67124
commit
4dace6c941
@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/contractcourt"
|
"github.com/lightningnetwork/lnd/contractcourt"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch/hodl"
|
"github.com/lightningnetwork/lnd/htlcswitch/hodl"
|
||||||
|
"github.com/lightningnetwork/lnd/lnpeer"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/roasbeef/btcd/btcec"
|
"github.com/roasbeef/btcd/btcec"
|
||||||
@ -1396,14 +1397,14 @@ type mockPeer struct {
|
|||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Peer = (*mockPeer)(nil)
|
var _ lnpeer.Peer = (*mockPeer)(nil)
|
||||||
|
|
||||||
func (m *mockPeer) SendMessage(msg lnwire.Message, sync bool) error {
|
func (m *mockPeer) SendMessage(sync bool, msgs ...lnwire.Message) error {
|
||||||
if m.disconnected {
|
if m.disconnected {
|
||||||
return fmt.Errorf("disconnected")
|
return fmt.Errorf("disconnected")
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case m.sentMsgs <- msg:
|
case m.sentMsgs <- msgs[0]:
|
||||||
case <-m.quit:
|
case <-m.quit:
|
||||||
return fmt.Errorf("mockPeer shutting down")
|
return fmt.Errorf("mockPeer shutting down")
|
||||||
}
|
}
|
||||||
@ -1415,8 +1416,11 @@ func (m *mockPeer) WipeChannel(*wire.OutPoint) error {
|
|||||||
func (m *mockPeer) PubKey() [33]byte {
|
func (m *mockPeer) PubKey() [33]byte {
|
||||||
return [33]byte{}
|
return [33]byte{}
|
||||||
}
|
}
|
||||||
|
func (m *mockPeer) IdentityKey() *btcec.PublicKey {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var _ Peer = (*mockPeer)(nil)
|
var _ lnpeer.Peer = (*mockPeer)(nil)
|
||||||
|
|
||||||
func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) (
|
func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) (
|
||||||
ChannelLink, *lnwallet.LightningChannel, chan time.Time, func() error,
|
ChannelLink, *lnwallet.LightningChannel, chan time.Time, func() error,
|
||||||
|
@ -20,6 +20,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/contractcourt"
|
"github.com/lightningnetwork/lnd/contractcourt"
|
||||||
|
"github.com/lightningnetwork/lnd/lnpeer"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/roasbeef/btcd/btcec"
|
"github.com/roasbeef/btcd/btcec"
|
||||||
@ -119,7 +120,7 @@ type mockServer struct {
|
|||||||
interceptorFuncs []messageInterceptor
|
interceptorFuncs []messageInterceptor
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Peer = (*mockServer)(nil)
|
var _ lnpeer.Peer = (*mockServer)(nil)
|
||||||
|
|
||||||
func initSwitchWithDB(db *channeldb.DB) (*Switch, error) {
|
func initSwitchWithDB(db *channeldb.DB) (*Switch, error) {
|
||||||
if db == nil {
|
if db == nil {
|
||||||
@ -450,13 +451,15 @@ func (s *mockServer) intersect(f messageInterceptor) {
|
|||||||
s.interceptorFuncs = append(s.interceptorFuncs, f)
|
s.interceptorFuncs = append(s.interceptorFuncs, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *mockServer) SendMessage(message lnwire.Message, sync bool) error {
|
func (s *mockServer) SendMessage(sync bool, msgs ...lnwire.Message) error {
|
||||||
|
|
||||||
|
for _, msg := range msgs {
|
||||||
select {
|
select {
|
||||||
case s.messages <- message:
|
case s.messages <- msg:
|
||||||
case <-s.quit:
|
case <-s.quit:
|
||||||
return errors.New("server is stopped")
|
return errors.New("server is stopped")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -506,6 +509,11 @@ func (s *mockServer) PubKey() [33]byte {
|
|||||||
return s.id
|
return s.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *mockServer) IdentityKey() *btcec.PublicKey {
|
||||||
|
pubkey, _ := btcec.ParsePubKey(s.id[:], btcec.S256())
|
||||||
|
return pubkey
|
||||||
|
}
|
||||||
|
|
||||||
func (s *mockServer) WipeChannel(*wire.OutPoint) error {
|
func (s *mockServer) WipeChannel(*wire.OutPoint) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -532,7 +540,7 @@ type mockChannelLink struct {
|
|||||||
|
|
||||||
chanID lnwire.ChannelID
|
chanID lnwire.ChannelID
|
||||||
|
|
||||||
peer Peer
|
peer lnpeer.Peer
|
||||||
|
|
||||||
startMailBox bool
|
startMailBox bool
|
||||||
|
|
||||||
@ -579,7 +587,7 @@ func (f *mockChannelLink) deleteCircuit(pkt *htlcPacket) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newMockChannelLink(htlcSwitch *Switch, chanID lnwire.ChannelID,
|
func newMockChannelLink(htlcSwitch *Switch, chanID lnwire.ChannelID,
|
||||||
shortChanID lnwire.ShortChannelID, peer Peer, eligible bool,
|
shortChanID lnwire.ShortChannelID, peer lnpeer.Peer, eligible bool,
|
||||||
) *mockChannelLink {
|
) *mockChannelLink {
|
||||||
|
|
||||||
return &mockChannelLink{
|
return &mockChannelLink{
|
||||||
@ -624,7 +632,7 @@ func (f *mockChannelLink) Start() error {
|
|||||||
func (f *mockChannelLink) ChanID() lnwire.ChannelID { return f.chanID }
|
func (f *mockChannelLink) ChanID() lnwire.ChannelID { return f.chanID }
|
||||||
func (f *mockChannelLink) ShortChanID() lnwire.ShortChannelID { return f.shortChanID }
|
func (f *mockChannelLink) ShortChanID() lnwire.ShortChannelID { return f.shortChanID }
|
||||||
func (f *mockChannelLink) Bandwidth() lnwire.MilliSatoshi { return 99999999 }
|
func (f *mockChannelLink) Bandwidth() lnwire.MilliSatoshi { return 99999999 }
|
||||||
func (f *mockChannelLink) Peer() Peer { return f.peer }
|
func (f *mockChannelLink) Peer() lnpeer.Peer { return f.peer }
|
||||||
func (f *mockChannelLink) Stop() {}
|
func (f *mockChannelLink) Stop() {}
|
||||||
func (f *mockChannelLink) EligibleToForward() bool { return f.eligible }
|
func (f *mockChannelLink) EligibleToForward() bool { return f.eligible }
|
||||||
func (f *mockChannelLink) setLiveShortChanID(sid lnwire.ShortChannelID) { f.shortChanID = sid }
|
func (f *mockChannelLink) setLiveShortChanID(sid lnwire.ShortChannelID) { f.shortChanID = sid }
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/contractcourt"
|
"github.com/lightningnetwork/lnd/contractcourt"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
|
"github.com/lightningnetwork/lnd/lnpeer"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/shachain"
|
"github.com/lightningnetwork/lnd/shachain"
|
||||||
@ -672,7 +673,7 @@ func (r *paymentResponse) Wait(d time.Duration) (chainhash.Hash, error) {
|
|||||||
// * from Alice to Bob
|
// * from Alice to Bob
|
||||||
// * from Alice to Carol through the Bob
|
// * from Alice to Carol through the Bob
|
||||||
// * from Alice to some another peer through the Bob
|
// * from Alice to some another peer through the Bob
|
||||||
func (n *threeHopNetwork) makePayment(sendingPeer, receivingPeer Peer,
|
func (n *threeHopNetwork) makePayment(sendingPeer, receivingPeer lnpeer.Peer,
|
||||||
firstHopPub [33]byte, hops []ForwardingInfo,
|
firstHopPub [33]byte, hops []ForwardingInfo,
|
||||||
invoiceAmt, htlcAmt lnwire.MilliSatoshi,
|
invoiceAmt, htlcAmt lnwire.MilliSatoshi,
|
||||||
timelock uint32) *paymentResponse {
|
timelock uint32) *paymentResponse {
|
||||||
|
Loading…
Reference in New Issue
Block a user