(t *testing.T)
| 89 | } |
| 90 | |
| 91 | func TestNodeInfoCompatible(t *testing.T) { |
| 92 | |
| 93 | nodeKey1 := NodeKey{PrivKey: ed25519.GenPrivKey()} |
| 94 | nodeKey2 := NodeKey{PrivKey: ed25519.GenPrivKey()} |
| 95 | name := "testing" |
| 96 | |
| 97 | var newTestChannel byte = 0x2 |
| 98 | |
| 99 | // test NodeInfo is compatible |
| 100 | ni1 := testNodeInfo(nodeKey1.ID(), name).(DefaultNodeInfo) |
| 101 | ni2 := testNodeInfo(nodeKey2.ID(), name).(DefaultNodeInfo) |
| 102 | assert.NoError(t, ni1.CompatibleWith(ni2)) |
| 103 | |
| 104 | // add another channel; still compatible |
| 105 | ni2.Channels = append(ni2.Channels, newTestChannel) |
| 106 | assert.True(t, ni2.HasChannel(newTestChannel)) |
| 107 | assert.NoError(t, ni1.CompatibleWith(ni2)) |
| 108 | |
| 109 | // wrong NodeInfo type is not compatible |
| 110 | _, netAddr := CreateRoutableAddr() |
| 111 | ni3 := mockNodeInfo{netAddr} |
| 112 | assert.Error(t, ni1.CompatibleWith(ni3)) |
| 113 | |
| 114 | testCases := []struct { |
| 115 | testName string |
| 116 | malleateNodeInfo func(*DefaultNodeInfo) |
| 117 | }{ |
| 118 | {"Wrong block version", func(ni *DefaultNodeInfo) { ni.ProtocolVersion.Block++ }}, |
| 119 | {"Wrong network", func(ni *DefaultNodeInfo) { ni.Network += "-wrong" }}, |
| 120 | {"No common channels", func(ni *DefaultNodeInfo) { ni.Channels = []byte{newTestChannel} }}, |
| 121 | } |
| 122 | |
| 123 | for _, tc := range testCases { |
| 124 | ni := testNodeInfo(nodeKey2.ID(), name).(DefaultNodeInfo) |
| 125 | tc.malleateNodeInfo(&ni) |
| 126 | assert.Error(t, ni1.CompatibleWith(ni)) |
| 127 | } |
| 128 | } |
nothing calls this directly
no test coverage detected