2018-01-27 15:00:28 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-08-29 14:33:53 +00:00
|
|
|
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
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) {
|
2019-08-29 14:42:13 +00:00
|
|
|
var port uint16 = 3000
|
|
|
|
var id uint32 = 13337
|
|
|
|
useragent := "/NEO:0.0.1/"
|
|
|
|
var height uint32 = 100500
|
2019-09-03 15:06:16 +00:00
|
|
|
var relay = true
|
2019-08-29 14:42:13 +00:00
|
|
|
|
|
|
|
version := NewVersion(id, port, useragent, height, relay)
|
2018-01-27 15:00:28 +00:00
|
|
|
|
2019-09-16 09:18:13 +00:00
|
|
|
buf := io.NewBufBinWriter()
|
2019-09-16 16:31:49 +00:00
|
|
|
version.EncodeBinary(buf.BinWriter)
|
|
|
|
assert.Nil(t, buf.Err)
|
2019-09-16 09:18:13 +00:00
|
|
|
b := buf.Bytes()
|
2019-09-16 13:08:00 +00:00
|
|
|
assert.Equal(t, io.GetVarSize(version), len(b))
|
2019-08-29 14:19:52 +00:00
|
|
|
|
2019-09-16 09:18:13 +00:00
|
|
|
r := io.NewBinReaderFromBuf(b)
|
2018-01-28 15:06:41 +00:00
|
|
|
versionDecoded := &Version{}
|
2019-09-16 16:31:49 +00:00
|
|
|
versionDecoded.DecodeBinary(r)
|
|
|
|
assert.Nil(t, r.Err)
|
2019-08-29 14:42:13 +00:00
|
|
|
assert.Equal(t, versionDecoded.Nonce, id)
|
|
|
|
assert.Equal(t, versionDecoded.Port, port)
|
|
|
|
assert.Equal(t, versionDecoded.UserAgent, []byte(useragent))
|
|
|
|
assert.Equal(t, versionDecoded.StartHeight, height)
|
|
|
|
assert.Equal(t, versionDecoded.Relay, relay)
|
2019-08-29 14:33:53 +00:00
|
|
|
assert.Equal(t, version, versionDecoded)
|
2018-01-27 15:00:28 +00:00
|
|
|
}
|