neoneo-go/pkg/network/server_test.go

54 lines
1 KiB
Go
Raw Normal View History

package network
import (
"testing"
2018-01-31 19:11:08 +00:00
"github.com/anthdm/neo-go/pkg/network/payload"
)
func TestHandleVersion(t *testing.T) {
2018-01-31 19:11:08 +00:00
s := NewServer(ModeDevNet)
go s.loop()
p := NewLocalPeer(s)
version := payload.NewVersion(1337, p.addr().Port, "/NEO:0.0.0/", 0, true)
msg := newMessage(ModeDevNet, cmdVersion, version)
resp := s.handleVersionCmd(msg, p)
if resp.commandType() != cmdVerack {
t.Fatalf("expected response message to be verack got %s", resp.commandType())
}
if resp.Payload != nil {
t.Fatal("verack payload should be nil")
}
}
2018-02-01 07:19:29 +00:00
func TestPeerCount(t *testing.T) {
s := NewServer(ModeDevNet)
go s.loop()
lenPeers := 10
for i := 0; i < lenPeers; i++ {
s.register <- NewLocalPeer(s)
}
if have, want := s.peerCount(), lenPeers; want != have {
t.Fatalf("expected %d connected peers got %d", want, have)
}
}
2018-01-31 19:11:08 +00:00
func TestHandleAddrCmd(t *testing.T) {
// todo
}
func TestHandleGetAddrCmd(t *testing.T) {
// todo
}
func TestHandleInv(t *testing.T) {
// todo
}
func TestHandleBlockCmd(t *testing.T) {
// todo
}