func TestCanonical(t *testing.T) {
	type item struct {
		in  string
		out string
	}
	testData := []item{
		{"127.0.0.1:1234", "127.0.0.1:1234"},
		{"127.0.0.1:1", "127.0.0.1:1"},
		{" 127.0.0.1 : 1 ", "127.0.0.1:1"},
		{"127.0.0.1:65535", "127.0.0.1:65535"},
		{"0.0.0.0:1234", "0.0.0.0:1234"},
		{"[::1]:1234", "[::1]:1234"},
		{"[::]:1234", "[::]:1234"},
		{"*:1234", "[::]:1234"},
		{"[0:0::0:0]:1234", "[::]:1234"},
		{"[0:0:0:0::1]:1234", "[::1]:1234"},
		{"[2404:6800:4008:c07::66]:443", "[2404:6800:4008:c07::66]:443"},
		{"[2404:6800:4008:0c07:0000:0000:0000:0066]:443", "[2404:6800:4008:c07::66]:443"},
	}
	for i, d := range testData {
		c, err := NewConnection(d.in)
		if nil != err {
			t.Fatalf("NewConnection failed on:[%d] %q  error: %s", i, d.in, err)
		}
		s, v6 := c.CanonicalIPandPort("")
		if s != d.out {
			t.Fatalf("failed on:[%d] %q  actual: %q  expected: %q", i, d.in, s, d.out)
		}
		t.Logf("converted:[%d]: %q  to(%t): %q", i, d.in, v6, s)
		pk := c.Pack()
		cu, n := pk.Unpack()
		if len(pk) != n {
			t.Fatalf("Unpack failed on:[%d] %q  only read: %d of: %d bytes", i, d.in, n, len(pk))
		}
		su, v6u := cu.CanonicalIPandPort("")
		if su != s {
			t.Fatalf("failed on:[%d] %x  actual: %q  expected: %q", i, pk, su, s)
		}
		if v6u != v6 {
			t.Fatalf("failed on:[%d] %x  actual v6: %t  expected v6: %t", i, pk, v6u, v6)
		}
	}
}
Test IP address detection
package util
import (
	"encoding/hex"
	"strings"
	"testing"
	"github.com/bitmark-inc/bitmarkd/fault"
)