diff options
author | Janos Guljas <janos@resenje.org> | 2018-09-25 22:57:31 +0800 |
---|---|---|
committer | Janos Guljas <janos@resenje.org> | 2018-09-25 22:57:31 +0800 |
commit | 24349144b6c0642755569268bab56b9033743212 (patch) | |
tree | 9d9d2b6659fd8a56512dfc807aafe4b733165ae1 /swarm/network/protocol_test.go | |
parent | 7d56602391e155e2ce9ba7c261300a1804ab9972 (diff) | |
parent | d3441ebb563439bac0837d70591f92e2c6080303 (diff) | |
download | go-tangerine-24349144b6c0642755569268bab56b9033743212.tar go-tangerine-24349144b6c0642755569268bab56b9033743212.tar.gz go-tangerine-24349144b6c0642755569268bab56b9033743212.tar.bz2 go-tangerine-24349144b6c0642755569268bab56b9033743212.tar.lz go-tangerine-24349144b6c0642755569268bab56b9033743212.tar.xz go-tangerine-24349144b6c0642755569268bab56b9033743212.tar.zst go-tangerine-24349144b6c0642755569268bab56b9033743212.zip |
Merge branch 'master' into max-stream-peer-servers
Diffstat (limited to 'swarm/network/protocol_test.go')
-rw-r--r-- | swarm/network/protocol_test.go | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/swarm/network/protocol_test.go b/swarm/network/protocol_test.go index 0fc858371..4b83c7a27 100644 --- a/swarm/network/protocol_test.go +++ b/swarm/network/protocol_test.go @@ -25,7 +25,7 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p" - "github.com/ethereum/go-ethereum/p2p/discover" + "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/protocols" p2ptest "github.com/ethereum/go-ethereum/p2p/testing" ) @@ -71,7 +71,7 @@ func (t *testStore) Save(key string, v []byte) error { return nil } -func HandshakeMsgExchange(lhs, rhs *HandshakeMsg, id discover.NodeID) []p2ptest.Exchange { +func HandshakeMsgExchange(lhs, rhs *HandshakeMsg, id enode.ID) []p2ptest.Exchange { return []p2ptest.Exchange{ { @@ -108,17 +108,13 @@ func newBzzBaseTester(t *testing.T, n int, addr *BzzAddr, spec *protocols.Spec, } protocol := func(p *p2p.Peer, rw p2p.MsgReadWriter) error { - return srv(&BzzPeer{ - Peer: protocols.NewPeer(p, rw, spec), - localAddr: addr, - BzzAddr: NewAddrFromNodeID(p.ID()), - }) + return srv(&BzzPeer{Peer: protocols.NewPeer(p, rw, spec), BzzAddr: NewAddr(p.Node())}) } - s := p2ptest.NewProtocolTester(t, NewNodeIDFromAddr(addr), n, protocol) + s := p2ptest.NewProtocolTester(t, addr.ID(), n, protocol) - for _, id := range s.IDs { - cs[id.String()] = make(chan bool) + for _, node := range s.Nodes { + cs[node.ID().String()] = make(chan bool) } return &bzzTester{ @@ -150,7 +146,7 @@ func newBzz(addr *BzzAddr, lightNode bool) *Bzz { func newBzzHandshakeTester(t *testing.T, n int, addr *BzzAddr, lightNode bool) *bzzTester { bzz := newBzz(addr, lightNode) - pt := p2ptest.NewProtocolTester(t, NewNodeIDFromAddr(addr), n, bzz.runBzz) + pt := p2ptest.NewProtocolTester(t, addr.ID(), n, bzz.runBzz) return &bzzTester{ addr: addr, @@ -161,14 +157,14 @@ func newBzzHandshakeTester(t *testing.T, n int, addr *BzzAddr, lightNode bool) * // should test handshakes in one exchange? parallelisation func (s *bzzTester) testHandshake(lhs, rhs *HandshakeMsg, disconnects ...*p2ptest.Disconnect) error { - var peers []discover.NodeID - id := NewNodeIDFromAddr(rhs.Addr) + var peers []enode.ID + id := rhs.Addr.ID() if len(disconnects) > 0 { for _, d := range disconnects { peers = append(peers, d.Peer) } } else { - peers = []discover.NodeID{id} + peers = []enode.ID{id} } if err := s.TestExchanges(HandshakeMsgExchange(lhs, rhs, id)...); err != nil { @@ -181,7 +177,7 @@ func (s *bzzTester) testHandshake(lhs, rhs *HandshakeMsg, disconnects ...*p2ptes // If we don't expect disconnect, ensure peers remain connected err := s.TestDisconnected(&p2ptest.Disconnect{ - Peer: s.IDs[0], + Peer: s.Nodes[0].ID(), Error: nil, }) @@ -209,12 +205,12 @@ func TestBzzHandshakeNetworkIDMismatch(t *testing.T) { lightNode := false addr := RandomAddr() s := newBzzHandshakeTester(t, 1, addr, lightNode) - id := s.IDs[0] + node := s.Nodes[0] err := s.testHandshake( correctBzzHandshake(addr, lightNode), - &HandshakeMsg{Version: TestProtocolVersion, NetworkID: 321, Addr: NewAddrFromNodeID(id)}, - &p2ptest.Disconnect{Peer: id, Error: fmt.Errorf("Handshake error: Message handler error: (msg code 0): network id mismatch 321 (!= 3)")}, + &HandshakeMsg{Version: TestProtocolVersion, NetworkID: 321, Addr: NewAddr(node)}, + &p2ptest.Disconnect{Peer: node.ID(), Error: fmt.Errorf("Handshake error: Message handler error: (msg code 0): network id mismatch 321 (!= 3)")}, ) if err != nil { @@ -226,12 +222,12 @@ func TestBzzHandshakeVersionMismatch(t *testing.T) { lightNode := false addr := RandomAddr() s := newBzzHandshakeTester(t, 1, addr, lightNode) - id := s.IDs[0] + node := s.Nodes[0] err := s.testHandshake( correctBzzHandshake(addr, lightNode), - &HandshakeMsg{Version: 0, NetworkID: TestProtocolNetworkID, Addr: NewAddrFromNodeID(id)}, - &p2ptest.Disconnect{Peer: id, Error: fmt.Errorf("Handshake error: Message handler error: (msg code 0): version mismatch 0 (!= %d)", TestProtocolVersion)}, + &HandshakeMsg{Version: 0, NetworkID: TestProtocolNetworkID, Addr: NewAddr(node)}, + &p2ptest.Disconnect{Peer: node.ID(), Error: fmt.Errorf("Handshake error: Message handler error: (msg code 0): version mismatch 0 (!= %d)", TestProtocolVersion)}, ) if err != nil { @@ -243,11 +239,11 @@ func TestBzzHandshakeSuccess(t *testing.T) { lightNode := false addr := RandomAddr() s := newBzzHandshakeTester(t, 1, addr, lightNode) - id := s.IDs[0] + node := s.Nodes[0] err := s.testHandshake( correctBzzHandshake(addr, lightNode), - &HandshakeMsg{Version: TestProtocolVersion, NetworkID: TestProtocolNetworkID, Addr: NewAddrFromNodeID(id)}, + &HandshakeMsg{Version: TestProtocolVersion, NetworkID: TestProtocolNetworkID, Addr: NewAddr(node)}, ) if err != nil { @@ -268,8 +264,8 @@ func TestBzzHandshakeLightNode(t *testing.T) { t.Run(test.name, func(t *testing.T) { randomAddr := RandomAddr() pt := newBzzHandshakeTester(t, 1, randomAddr, false) - id := pt.IDs[0] - addr := NewAddrFromNodeID(id) + node := pt.Nodes[0] + addr := NewAddr(node) err := pt.testHandshake( correctBzzHandshake(randomAddr, false), @@ -280,8 +276,8 @@ func TestBzzHandshakeLightNode(t *testing.T) { t.Fatal(err) } - if pt.bzz.handshakes[id].LightNode != test.lightNode { - t.Fatalf("peer LightNode flag is %v, should be %v", pt.bzz.handshakes[id].LightNode, test.lightNode) + if pt.bzz.handshakes[node.ID()].LightNode != test.lightNode { + t.Fatalf("peer LightNode flag is %v, should be %v", pt.bzz.handshakes[node.ID()].LightNode, test.lightNode) } }) } |