mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-07 05:07:36 +00:00
parent
e6f617a43f
commit
c590cc02f4
15 changed files with 333 additions and 101 deletions
|
@ -3,9 +3,9 @@ package network
|
|||
import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||
|
@ -163,15 +163,6 @@ func (d testDiscovery) RequestRemote(n int) {}
|
|||
func (d testDiscovery) BadPeers() []string { return []string{} }
|
||||
func (d testDiscovery) GoodPeers() []string { return []string{} }
|
||||
|
||||
type localTransport struct{}
|
||||
|
||||
func (t localTransport) Dial(addr string, timeout time.Duration) error {
|
||||
return nil
|
||||
}
|
||||
func (t localTransport) Accept() {}
|
||||
func (t localTransport) Proto() string { return "local" }
|
||||
func (t localTransport) Close() {}
|
||||
|
||||
var defaultMessageHandler = func(t *testing.T, msg *Message) {}
|
||||
|
||||
type localPeer struct {
|
||||
|
@ -180,6 +171,7 @@ type localPeer struct {
|
|||
version *payload.Version
|
||||
lastBlockIndex uint32
|
||||
handshaked bool
|
||||
isFullNode bool
|
||||
t *testing.T
|
||||
messageHandler func(t *testing.T, msg *Message)
|
||||
pingSent int
|
||||
|
@ -240,7 +232,10 @@ func (p *localPeer) HandleVersion(v *payload.Version) error {
|
|||
return nil
|
||||
}
|
||||
func (p *localPeer) SendVersion() error {
|
||||
m := p.server.getVersionMsg()
|
||||
m, err := p.server.getVersionMsg()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_ = p.EnqueueMessage(m)
|
||||
return nil
|
||||
}
|
||||
|
@ -267,11 +262,14 @@ func (p *localPeer) Handshaked() bool {
|
|||
return p.handshaked
|
||||
}
|
||||
|
||||
func newTestServer(t *testing.T) *Server {
|
||||
return &Server{
|
||||
ServerConfig: ServerConfig{},
|
||||
func (p *localPeer) IsFullNode() bool {
|
||||
return p.isFullNode
|
||||
}
|
||||
|
||||
func newTestServer(t *testing.T, serverConfig ServerConfig) *Server {
|
||||
s := &Server{
|
||||
ServerConfig: serverConfig,
|
||||
chain: &testChain{},
|
||||
transport: localTransport{},
|
||||
discovery: testDiscovery{},
|
||||
id: rand.Uint32(),
|
||||
quit: make(chan struct{}),
|
||||
|
@ -280,5 +278,6 @@ func newTestServer(t *testing.T) *Server {
|
|||
peers: make(map[Peer]bool),
|
||||
log: zaptest.NewLogger(t),
|
||||
}
|
||||
|
||||
s.transport = NewTCPTransport(s, net.JoinHostPort(s.ServerConfig.Address, strconv.Itoa(int(s.ServerConfig.Port))), s.log)
|
||||
return s
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue