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

Function TestPingHandle

p2pserver/message/utils/msg_handler_test.go:443–475  ·  view source on GitHub ↗

TestPingHandle tests Function PingHandle handling a ping message

(t *testing.T)

Source from the content-addressed store, hash-verified

441
442// TestPingHandle tests Function PingHandle handling a ping message
443func TestPingHandle(t *testing.T) {
444 // Simulate a remote peer to be added to the neighbor peers
445 var testID uint64
446 _, testPub, _ := keypair.GenerateKeyPair(keypair.PK_ECDSA, keypair.P256)
447 key := keypair.SerializePublicKey(testPub)
448 err := binary.Read(bytes.NewBuffer(key[:8]), binary.LittleEndian, &(testID))
449 assert.Nil(t, err)
450
451 remotePeer := peer.NewPeer()
452 assert.NotNil(t, remotePeer)
453 remotePeer.UpdateInfo(time.Now(), 1, 12345678, 20336,
454 testID, 0, 12345, "1.5.2")
455 remotePeer.Link.SetAddr("127.0.0.1:50010")
456
457 network.AddNbrNode(remotePeer)
458
459 // Construct a ping packet
460 height := ledger.DefLedger.GetCurrentBlockHeight()
461 assert.Nil(t, err)
462
463 buf := msgpack.NewPingMsg(uint64(height))
464
465 msg := &types.MsgPayload{
466 Id: testID,
467 Addr: "127.0.0.1:50010",
468 Payload: buf,
469 }
470
471 // Invoke PingHandle to handle the msg
472 PingHandle(msg, network, nil)
473
474 network.DelNbrNode(testID)
475}
476
477// TestPingHandle tests Function PingHandle handling a pong message
478func TestPongHandle(t *testing.T) {

Callers

nothing calls this directly

Calls 7

UpdateInfoMethod · 0.95
NewPeerFunction · 0.92
PingHandleFunction · 0.85
SetAddrMethod · 0.80
AddNbrNodeMethod · 0.65
GetCurrentBlockHeightMethod · 0.65
DelNbrNodeMethod · 0.65

Tested by

no test coverage detected