neo-go/pkg/network/payload/version_test.go

49 lines
1.1 KiB
Go
Raw Permalink Normal View History

2018-01-27 15:00:28 +00:00
package payload
import (
"testing"
"github.com/nspcc-dev/neo-go/internal/testserdes"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neo-go/pkg/network/capability"
"github.com/stretchr/testify/assert"
2018-01-27 15:00:28 +00:00
)
func TestVersionEncodeDecode(t *testing.T) {
var magic netmode.Magic = 56753
var tcpPort uint16 = 3000
var wsPort uint16 = 3001
var id uint32 = 13337
useragent := "/NEO:0.0.1/"
var height uint32 = 100500
var capabilities = []capability.Capability{
{
Type: capability.TCPServer,
Data: &capability.Server{
Port: tcpPort,
},
},
{
Type: capability.WSServer,
Data: &capability.Server{
Port: wsPort,
},
},
{
Type: capability.FullNode,
Data: &capability.Node{
StartHeight: height,
},
},
}
version := NewVersion(magic, id, useragent, capabilities)
2018-01-28 15:06:41 +00:00
versionDecoded := &Version{}
testserdes.EncodeDecodeBinary(t, version, versionDecoded)
assert.Equal(t, versionDecoded.Nonce, id)
assert.ElementsMatch(t, capabilities, versionDecoded.Capabilities)
assert.Equal(t, versionDecoded.UserAgent, []byte(useragent))
assert.Equal(t, version, versionDecoded)
2018-01-27 15:00:28 +00:00
}