p2p, swarm: Make p2p/protocols tests pass + rename types.go

This commit is contained in:
lash 2019-03-13 13:23:09 +01:00
parent f06ff02d0a
commit 828b489438
3 changed files with 12 additions and 6 deletions

View file

@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/simulations/adapters" "github.com/ethereum/go-ethereum/p2p/simulations/adapters"
@ -144,8 +145,11 @@ func newProtocol(pp *p2ptest.TestPeerPool) func(*p2p.Peer, p2p.MsgReadWriter) er
} }
func protocolTester(pp *p2ptest.TestPeerPool) *p2ptest.ProtocolTester { func protocolTester(pp *p2ptest.TestPeerPool) *p2ptest.ProtocolTester {
conf := adapters.RandomNodeConfig() prvkey, err := crypto.GenerateKey()
return p2ptest.NewProtocolTester(conf.ID, 2, newProtocol(pp)) if err != nil {
panic(err)
}
return p2ptest.NewProtocolTester(prvkey, 2, newProtocol(pp))
} }
func protoHandshakeExchange(id enode.ID, proto *protoHandshake) []p2ptest.Exchange { func protoHandshakeExchange(id enode.ID, proto *protoHandshake) []p2ptest.Exchange {
@ -260,9 +264,12 @@ func TestProtocolHook(t *testing.T) {
return peer.Run(handle) return peer.Run(handle)
} }
conf := adapters.RandomNodeConfig() prvkey, err := crypto.GenerateKey()
tester := p2ptest.NewProtocolTester(conf.ID, 2, runFunc) if err != nil {
err := tester.TestExchanges(p2ptest.Exchange{ panic(err)
}
tester := p2ptest.NewProtocolTester(prvkey, 2, runFunc)
err = tester.TestExchanges(p2ptest.Exchange{
Expects: []p2ptest.Expect{ Expects: []p2ptest.Expect{
{ {
Code: 0, Code: 0,

View file

@ -86,7 +86,6 @@ func NewProtocolTester(prvkey *ecdsa.PrivateKey, nodeCount int, run func(*p2p.Pe
} }
if err := net.Start(peers[i].ID); err != nil { if err := net.Start(peers[i].ID); err != nil {
panic(fmt.Sprintf("error starting peer %v: %v", peers[i].ID, err)) panic(fmt.Sprintf("error starting peer %v: %v", peers[i].ID, err))
panic(err.Error())
} }
nodes[i] = peers[i].Node() nodes[i] = peers[i].Node()
} }