neo-go/pkg/network/payload/ping_test.go
Vsevolod Brekelov 4e6ed9021c network: add ping pong processing
add pingInterval same as used in ref C# implementation with the same logic
add pingTimeout which is used to check whether pong received. If not -- drop the peer.
add pingLimit which is hardcoded to 4 in TCPPeer. It's limit for unsuccessful ping/pong calls (where pong wasn't received in pingTimeout interval)
2020-01-17 13:24:14 +03:00

25 lines
621 B
Go

package payload
import (
"testing"
"github.com/CityOfZion/neo-go/pkg/io"
"github.com/stretchr/testify/assert"
)
func TestEncodeDecodeBinary(t *testing.T) {
payload := NewPing(uint32(1), uint32(2))
assert.NotEqual(t, 0, payload.Timestamp)
bufBinWriter := io.NewBufBinWriter()
payload.EncodeBinary(bufBinWriter.BinWriter)
assert.Nil(t, bufBinWriter.Err)
binReader := io.NewBinReaderFromBuf(bufBinWriter.Bytes())
decodedPing := &Ping{}
decodedPing.DecodeBinary(binReader)
assert.Nil(t, binReader.Err)
assert.Equal(t, uint32(1), decodedPing.LastBlockIndex)
assert.Equal(t, uint32(2), decodedPing.Nonce)
}