MCPcopy Create free account
hub / github.com/DNAProject/DNA / TestVerAckHandle

Function TestVerAckHandle

p2pserver/message/utils/msg_handler_test.go:198–232  ·  view source on GitHub ↗

TestVerAckHandle tests Function VerAckHandle handling a version ack

(t *testing.T)

Source from the content-addressed store, hash-verified

196
197// TestVerAckHandle tests Function VerAckHandle handling a version ack
198func TestVerAckHandle(t *testing.T) {
199 // Simulate a remote peer to be added to the neighbor peers
200 var testID uint64
201 _, testPub, _ := keypair.GenerateKeyPair(keypair.PK_ECDSA, keypair.P256)
202 key := keypair.SerializePublicKey(testPub)
203 err := binary.Read(bytes.NewBuffer(key[:8]), binary.LittleEndian, &(testID))
204 assert.Nil(t, err)
205
206 remotePeer := peer.NewPeer()
207 assert.NotNil(t, remotePeer)
208
209 remotePeer.SetHttpInfoPort(20335)
210 remotePeer.UpdateInfo(time.Now(), 1, 12345678, 20336, testID, 0, 12345, "1.5.2")
211 network.AddNbrNode(remotePeer)
212 remotePeer.SetState(msgCommon.HAND_SHAKE)
213
214 // Construct a version ack packet
215 buf := msgpack.NewVerAck()
216
217 msg := &types.MsgPayload{
218 Id: testID,
219 Addr: "127.0.0.1:50010",
220 Payload: buf,
221 }
222
223 // Invoke VerAckHandle to handle the msg
224 VerAckHandle(msg, network, nil)
225
226 // Get the remote peer from the neighbor peers by peer id
227 tempPeer := network.GetPeer(testID)
228 assert.NotNil(t, tempPeer)
229 assert.Equal(t, tempPeer.GetState(), uint32(msgCommon.ESTABLISH))
230
231 network.DelNbrNode(testID)
232}
233
234// TestAddrReqHandle tests Function AddrReqHandle handling an address req
235// testcase: no-mask neighbor

Callers

nothing calls this directly

Calls 9

SetHttpInfoPortMethod · 0.95
UpdateInfoMethod · 0.95
SetStateMethod · 0.95
NewPeerFunction · 0.92
VerAckHandleFunction · 0.85
AddNbrNodeMethod · 0.65
GetPeerMethod · 0.65
DelNbrNodeMethod · 0.65
GetStateMethod · 0.45

Tested by

no test coverage detected