(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestNodeKey(t *testing.T) { |
| 16 | k := NewNode() |
| 17 | if k.IsZero() { |
| 18 | t.Fatal("NodePrivate should not be zero") |
| 19 | } |
| 20 | |
| 21 | p := k.Public() |
| 22 | if p.IsZero() { |
| 23 | t.Fatal("NodePublic should not be zero") |
| 24 | } |
| 25 | |
| 26 | bs, err := p.MarshalText() |
| 27 | if err != nil { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | if full, got := string(bs), ":"+p.UntypedHexString(); !strings.HasSuffix(full, got) { |
| 31 | t.Fatalf("NodePublic.UntypedHexString is not a suffix of the typed serialization, got %q want suffix of %q", got, full) |
| 32 | } |
| 33 | bs, err = p.MarshalBinary() |
| 34 | if err != nil { |
| 35 | t.Fatal(err) |
| 36 | } |
| 37 | if got, want := bs, append([]byte(nodePublicBinaryPrefix), p.k[:]...); !bytes.Equal(got, want) { |
| 38 | t.Fatalf("Binary-encoded NodePublic = %x, want %x", got, want) |
| 39 | } |
| 40 | var decoded NodePublic |
| 41 | if err := decoded.UnmarshalBinary(bs); err != nil { |
| 42 | t.Fatalf("NodePublic.UnmarshalBinary(%x) failed: %v", bs, err) |
| 43 | } |
| 44 | if decoded != p { |
| 45 | t.Errorf("unmarshaled and original NodePublic differ:\noriginal = %v\ndecoded = %v", p, decoded) |
| 46 | } |
| 47 | |
| 48 | z := NodePublic{} |
| 49 | if !z.IsZero() { |
| 50 | t.Fatal("IsZero(NodePublic{}) is false") |
| 51 | } |
| 52 | if s := z.ShortString(); s != "" { |
| 53 | t.Fatalf("NodePublic{}.ShortString() is %q, want \"\"", s) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | func TestNodeSerialization(t *testing.T) { |
| 58 | serialized := `{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…