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"
|
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()
|
|
|
|
addr = NewAddressAndTime(e, ts)
|
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)
|
|
|
|
assert.Equal(t, e.Port, int(addr.Port))
|
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))
|
2018-03-09 15:55:25 +00:00
|
|
|
addrList.Addrs[i] = NewAddressAndTime(e, time.Now())
|
|
|
|
}
|
|
|
|
|
2020-03-26 14:43:24 +00:00
|
|
|
testserdes.EncodeDecodeBinary(t, addrList, new(AddressList))
|
2018-03-09 15:55:25 +00:00
|
|
|
}
|