2018-03-09 15:55:25 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-09-09 14:54:38 +00:00
|
|
|
"net"
|
2018-03-09 15:55:25 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-03-26 14:43:24 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
2020-05-22 09:59:18 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/network/capability"
|
2018-03-09 15:55:25 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEncodeDecodeAddress(t *testing.T) {
|
|
|
|
var (
|
2019-09-09 14:54:38 +00:00
|
|
|
e, _ = net.ResolveTCPAddr("tcp", "127.0.0.1:2000")
|
2019-08-29 15:39:46 +00:00
|
|
|
ts = time.Now()
|
2020-05-22 09:59:18 +00:00
|
|
|
addr = NewAddressAndTime(e, ts, capability.Capabilities{
|
|
|
|
{
|
|
|
|
Type: capability.TCPServer,
|
|
|
|
Data: &capability.Server{Port: uint16(e.Port)},
|
|
|
|
},
|
|
|
|
})
|
2018-03-09 15:55:25 +00:00
|
|
|
)
|
|
|
|
|
2019-08-29 15:39:46 +00:00
|
|
|
assert.Equal(t, ts.UTC().Unix(), int64(addr.Timestamp))
|
2019-09-09 14:54:38 +00:00
|
|
|
aatip := make(net.IP, 16)
|
|
|
|
copy(aatip, addr.IP[:])
|
|
|
|
assert.Equal(t, e.IP, aatip)
|
2020-05-22 09:59:18 +00:00
|
|
|
assert.Equal(t, 1, len(addr.Capabilities))
|
|
|
|
assert.Equal(t, capability.Capability{
|
|
|
|
Type: capability.TCPServer,
|
|
|
|
Data: &capability.Server{Port: uint16(e.Port)},
|
|
|
|
}, addr.Capabilities[0])
|
2018-03-09 15:55:25 +00:00
|
|
|
|
2020-03-26 14:43:24 +00:00
|
|
|
testserdes.EncodeDecodeBinary(t, addr, new(AddressAndTime))
|
2018-03-09 15:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEncodeDecodeAddressList(t *testing.T) {
|
|
|
|
var lenList uint8 = 4
|
2019-09-13 17:38:34 +00:00
|
|
|
addrList := NewAddressList(int(lenList))
|
2018-03-09 15:55:25 +00:00
|
|
|
for i := 0; i < int(lenList); i++ {
|
2019-09-09 14:54:38 +00:00
|
|
|
e, _ := net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:200%d", i))
|
2020-05-22 09:59:18 +00:00
|
|
|
addrList.Addrs[i] = NewAddressAndTime(e, time.Now(), capability.Capabilities{
|
|
|
|
{
|
|
|
|
Type: capability.TCPServer,
|
|
|
|
Data: &capability.Server{Port: 123},
|
|
|
|
},
|
|
|
|
})
|
2018-03-09 15:55:25 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 14:43:24 +00:00
|
|
|
testserdes.EncodeDecodeBinary(t, addrList, new(AddressList))
|
2018-03-09 15:55:25 +00:00
|
|
|
}
|