MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / TestNodeInfoCompatible

Function TestNodeInfoCompatible

p2p/node_info_test.go:91–128  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

89}
90
91func 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}

Callers

nothing calls this directly

Calls 7

IDMethod · 0.95
GenPrivKeyFunction · 0.92
testNodeInfoFunction · 0.85
CreateRoutableAddrFunction · 0.85
HasChannelMethod · 0.80
CompatibleWithMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected