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

Function TestPongHandle

p2pserver/message/utils/msg_handler_test.go:478–510  ·  view source on GitHub ↗

TestPingHandle tests Function PingHandle handling a pong message

(t *testing.T)

Source from the content-addressed store, hash-verified

476
477// TestPingHandle tests Function PingHandle handling a pong message
478func TestPongHandle(t *testing.T) {
479 // Simulate a remote peer to be added to the neighbor peers
480 var testID uint64
481 _, testPub, _ := keypair.GenerateKeyPair(keypair.PK_ECDSA, keypair.P256)
482 key := keypair.SerializePublicKey(testPub)
483 err := binary.Read(bytes.NewBuffer(key[:8]), binary.LittleEndian, &(testID))
484 assert.Nil(t, err)
485
486 remotePeer := peer.NewPeer()
487 assert.NotNil(t, remotePeer)
488 remotePeer.UpdateInfo(time.Now(), 1, 12345678, 20336,
489 testID, 0, 12345, "1.5.2")
490 remotePeer.Link.SetAddr("127.0.0.1:50010")
491
492 network.AddNbrNode(remotePeer)
493
494 // Construct a pong packet
495 height := ledger.DefLedger.GetCurrentBlockHeight()
496 assert.Nil(t, err)
497
498 buf := msgpack.NewPongMsg(uint64(height))
499
500 msg := &types.MsgPayload{
501 Id: testID,
502 Addr: "127.0.0.1:50010",
503 Payload: buf,
504 }
505
506 // Invoke PingHandle to handle the msg
507 PongHandle(msg, network, nil)
508
509 network.DelNbrNode(testID)
510}
511
512// TestBlkHeaderHandle tests Function BlkHeaderHandle handling a sync header msg
513func TestBlkHeaderHandle(t *testing.T) {

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected