mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-04 09:02:28 +00:00
pkg: hide it by moving to _pkg.dev
The idea here is to preserve the history of `dev` branch development and its code when merging with the `master`. Later this code could be moved into the masters code where appropriate.
This commit is contained in:
parent
bb2568cc53
commit
ddd1d92ff1
183 changed files with 0 additions and 0 deletions
59
_pkg.dev/wire/payload/mversion_test.go
Normal file
59
_pkg.dev/wire/payload/mversion_test.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package payload
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"math/rand"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/wire/protocol"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestValidNewVersionMessage(t *testing.T) {
|
||||
|
||||
expectedIP := "127.0.0.1"
|
||||
expectedPort := 8333
|
||||
tcpAddrMe := &net.TCPAddr{IP: net.ParseIP(expectedIP), Port: expectedPort}
|
||||
nonce := randRange(12949672, 42949672)
|
||||
message, err := NewVersionMessage(tcpAddrMe, 0, true, protocol.DefaultVersion, protocol.UserAgent, nonce, protocol.NodePeerService)
|
||||
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, expectedIP, message.IP.String())
|
||||
assert.Equal(t, uint16(expectedPort), message.Port)
|
||||
assert.Equal(t, protocol.DefaultVersion, message.Version)
|
||||
}
|
||||
func TestEncode(t *testing.T) {
|
||||
|
||||
expectedIP := "127.0.0.1"
|
||||
expectedPort := 8333
|
||||
tcpAddrMe := &net.TCPAddr{IP: net.ParseIP(expectedIP), Port: expectedPort}
|
||||
nonce := randRange(12949672, 42949672)
|
||||
message, err := NewVersionMessage(tcpAddrMe, 0, true, protocol.DefaultVersion, protocol.UserAgent, nonce, protocol.NodePeerService)
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
err = message.EncodePayload(buf)
|
||||
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, len(message.UserAgent)+minMsgVersionSize, int(buf.Len()))
|
||||
}
|
||||
func TestLenIsCorrect(t *testing.T) {
|
||||
|
||||
expectedIP := "127.0.0.1"
|
||||
expectedPort := 8333
|
||||
tcpAddrMe := &net.TCPAddr{IP: net.ParseIP(expectedIP), Port: expectedPort}
|
||||
nonce := randRange(12949672, 42949672)
|
||||
message, err := NewVersionMessage(tcpAddrMe, 0, true, protocol.DefaultVersion, protocol.UserAgent, nonce, protocol.NodePeerService)
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
err = message.EncodePayload(buf)
|
||||
assert.Equal(t, nil, err)
|
||||
|
||||
assert.Equal(t, len(message.UserAgent)+minMsgVersionSize, len(buf.Bytes()))
|
||||
}
|
||||
|
||||
func randRange(min, max int) uint32 {
|
||||
rand.Seed(time.Now().Unix() + int64(rand.Uint64()))
|
||||
return uint32(rand.Intn(max-min) + min)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue