mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-24 06:52:32 +00:00

* [NOD-1191] Convert wire protocol to 100% protobuf * [NOD-1191] Simplify wire interface and remove redundant messages * [NOD-1191] Map all proto to wire conversions * [NOD-1203] Create netadapter outside of protocol manager * [NOD-1191] Fix nil errors * [NOD-1191] Fix comments * [NOD-1191] Add converter interface * [NOD-1191] Add missing GetBlockLocator message * [NOD-1191] Change message names that starts with 'get' to 'request' * [NOD-1191] Change message commands values * [NOD-1191] Remove redundant methods * [NOD-1191] Rename message constructors * [NOD-1191] Change message commands to use iota * [NOD-1191] Add missing outputs to protobuf conversion * [NOD-1191] Make block header a required field * [NOD-1191] Rename variables * [NOD-1212] Fix test names * [NOD-1191] Rename flow names * [NOD-1191] Fix infinite loop
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
// Copyright (c) 2013-2016 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package wire
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
)
|
|
|
|
// TestAddresses tests the MsgAddresses API.
|
|
func TestAddresses(t *testing.T) {
|
|
// Ensure the command is expected value.
|
|
wantCmd := MessageCommand(3)
|
|
msg := NewMsgAddresses(false, nil)
|
|
if cmd := msg.Command(); cmd != wantCmd {
|
|
t.Errorf("NewMsgAddresses: wrong command - got %v want %v",
|
|
cmd, wantCmd)
|
|
}
|
|
|
|
// Ensure NetAddresses are added properly.
|
|
tcpAddr := &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 16111}
|
|
na := NewNetAddress(tcpAddr, SFNodeNetwork)
|
|
err := msg.AddAddress(na)
|
|
if err != nil {
|
|
t.Errorf("AddAddress: %v", err)
|
|
}
|
|
if msg.AddrList[0] != na {
|
|
t.Errorf("AddAddress: wrong address added - got %v, want %v",
|
|
spew.Sprint(msg.AddrList[0]), spew.Sprint(na))
|
|
}
|
|
|
|
// Ensure the address list is cleared properly.
|
|
msg.ClearAddresses()
|
|
if len(msg.AddrList) != 0 {
|
|
t.Errorf("ClearAddresses: address list is not empty - "+
|
|
"got %v [%v], want %v", len(msg.AddrList),
|
|
spew.Sprint(msg.AddrList[0]), 0)
|
|
}
|
|
|
|
// Ensure adding more than the max allowed addresses per message returns
|
|
// error.
|
|
for i := 0; i < MaxAddressesPerMsg+1; i++ {
|
|
err = msg.AddAddress(na)
|
|
}
|
|
if err == nil {
|
|
t.Errorf("AddAddress: expected error on too many addresses " +
|
|
"not received")
|
|
}
|
|
err = msg.AddAddresses(na)
|
|
if err == nil {
|
|
t.Errorf("AddAddresses: expected error on too many addresses " +
|
|
"not received")
|
|
}
|
|
}
|