2018-01-27 15:00:28 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-08-29 14:33:53 +00:00
|
|
|
|
2020-05-21 10:35:44 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
2020-03-26 14:43:24 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
2020-05-22 09:17:17 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/network/capability"
|
2019-08-29 14:33:53 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2018-01-27 15:00:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestVersionEncodeDecode(t *testing.T) {
|
2020-05-21 10:35:44 +00:00
|
|
|
var magic config.NetMode = 56753
|
2020-05-22 09:17:17 +00:00
|
|
|
var tcpPort uint16 = 3000
|
|
|
|
var wsPort uint16 = 3001
|
2019-08-29 14:42:13 +00:00
|
|
|
var id uint32 = 13337
|
|
|
|
useragent := "/NEO:0.0.1/"
|
|
|
|
var height uint32 = 100500
|
2020-05-22 09:17:17 +00:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2019-08-29 14:42:13 +00:00
|
|
|
|
2020-05-22 09:17:17 +00:00
|
|
|
version := NewVersion(magic, id, useragent, capabilities)
|
2018-01-28 15:06:41 +00:00
|
|
|
versionDecoded := &Version{}
|
2020-03-26 14:43:24 +00:00
|
|
|
testserdes.EncodeDecodeBinary(t, version, versionDecoded)
|
|
|
|
|
2019-08-29 14:42:13 +00:00
|
|
|
assert.Equal(t, versionDecoded.Nonce, id)
|
2020-05-22 09:17:17 +00:00
|
|
|
assert.ElementsMatch(t, capabilities, versionDecoded.Capabilities)
|
2019-08-29 14:42:13 +00:00
|
|
|
assert.Equal(t, versionDecoded.UserAgent, []byte(useragent))
|
2019-08-29 14:33:53 +00:00
|
|
|
assert.Equal(t, version, versionDecoded)
|
2018-01-27 15:00:28 +00:00
|
|
|
}
|