Browse Source

p2p: fix tests for required channels

pull/1049/head
Ethan Buchman 7 years ago
parent
commit
99034904f8
3 changed files with 26 additions and 15 deletions
  1. +3
    -0
      p2p/peer.go
  2. +12
    -8
      p2p/peer_test.go
  3. +11
    -7
      p2p/test_util.go

+ 3
- 0
p2p/peer.go View File

@ -240,6 +240,9 @@ func (p *peer) hasChannel(chID byte) bool {
return true
}
}
// NOTE: probably will want to remove this
// but could be helpful while the feature is new
p.Logger.Debug("Unknown channel for peer", "channel", chID, "channels", p.channels)
return false
}


+ 12
- 8
p2p/peer_test.go View File

@ -13,6 +13,8 @@ import (
tmconn "github.com/tendermint/tendermint/p2p/conn"
)
const testCh = 0x01
func TestPeerBasic(t *testing.T) {
assert, require := assert.New(t), require.New(t)
@ -77,25 +79,26 @@ func TestPeerSend(t *testing.T) {
defer p.Stop()
assert.True(p.CanSend(0x01))
assert.True(p.Send(0x01, "Asylum"))
assert.True(p.CanSend(testCh))
assert.True(p.Send(testCh, "Asylum"))
}
func createOutboundPeerAndPerformHandshake(addr *NetAddress, config *PeerConfig) (*peer, error) {
chDescs := []*tmconn.ChannelDescriptor{
{ID: 0x01, Priority: 1},
{ID: testCh, Priority: 1},
}
reactorsByCh := map[byte]Reactor{0x01: NewTestReactor(chDescs, true)}
reactorsByCh := map[byte]Reactor{testCh: NewTestReactor(chDescs, true)}
pk := crypto.GenPrivKeyEd25519().Wrap()
p, err := newOutboundPeer(addr, reactorsByCh, chDescs, func(p Peer, r interface{}) {}, pk, config, false)
if err != nil {
return nil, err
}
err = p.HandshakeTimeout(NodeInfo{
PubKey: pk.PubKey(),
Moniker: "host_peer",
Network: "testing",
Version: "123.123.123",
PubKey: pk.PubKey(),
Moniker: "host_peer",
Network: "testing",
Version: "123.123.123",
Channels: []byte{testCh},
}, 1*time.Second)
if err != nil {
return nil, err
@ -148,6 +151,7 @@ func (p *remotePeer) accept(l net.Listener) {
Network: "testing",
Version: "123.123.123",
ListenAddr: l.Addr().String(),
Channels: []byte{testCh},
}, 1*time.Second)
if err != nil {
golog.Fatalf("Failed to perform handshake: %+v", err)


+ 11
- 7
p2p/test_util.go View File

@ -132,16 +132,20 @@ func MakeSwitch(cfg *cfg.P2PConfig, i int, network, version string, initSwitch f
nodeKey := &NodeKey{
PrivKey: crypto.GenPrivKeyEd25519().Wrap(),
}
s := NewSwitch(cfg)
s.SetLogger(log.TestingLogger())
s = initSwitch(i, s)
s.SetNodeInfo(NodeInfo{
sw := NewSwitch(cfg)
sw.SetLogger(log.TestingLogger())
sw = initSwitch(i, sw)
ni := NodeInfo{
PubKey: nodeKey.PubKey(),
Moniker: cmn.Fmt("switch%d", i),
Network: network,
Version: version,
ListenAddr: cmn.Fmt("%v:%v", network, rand.Intn(64512)+1023),
})
s.SetNodeKey(nodeKey)
return s
}
for ch, _ := range sw.reactorsByCh {
ni.Channels = append(ni.Channels, ch)
}
sw.SetNodeInfo(ni)
sw.SetNodeKey(nodeKey)
return sw
}

Loading…
Cancel
Save