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

Function TestHeadersReqHandle

p2pserver/message/utils/msg_handler_test.go:410–440  ·  view source on GitHub ↗

TestHeadersReqHandle tests Function HeadersReqHandle handling a header req

(t *testing.T)

Source from the content-addressed store, hash-verified

408
409// TestHeadersReqHandle tests Function HeadersReqHandle handling a header req
410func TestHeadersReqHandle(t *testing.T) {
411 // Simulate a remote peer to be added to the neighbor peers
412 var testID uint64
413 _, testPub, _ := keypair.GenerateKeyPair(keypair.PK_ECDSA, keypair.P256)
414 key := keypair.SerializePublicKey(testPub)
415 err := binary.Read(bytes.NewBuffer(key[:8]), binary.LittleEndian, &(testID))
416 assert.Nil(t, err)
417
418 remotePeer := peer.NewPeer()
419 assert.NotNil(t, remotePeer)
420
421 remotePeer.UpdateInfo(time.Now(), 1, 12345678, 20336,
422 testID, 0, 12345, "1.5.2")
423 remotePeer.Link.SetAddr("127.0.0.1:50010")
424
425 network.AddNbrNode(remotePeer)
426
427 // Construct a headers request of packet
428 headerHash := ledger.DefLedger.GetCurrentHeaderHash()
429 buf := msgpack.NewHeadersReq(headerHash)
430
431 msg := &types.MsgPayload{
432 Id: testID,
433 Addr: "127.0.0.1:50010",
434 Payload: buf,
435 }
436
437 // Invoke HeadersReqhandle to handle the msg
438 HeadersReqHandle(msg, network, nil)
439 network.DelNbrNode(testID)
440}
441
442// TestPingHandle tests Function PingHandle handling a ping message
443func TestPingHandle(t *testing.T) {

Callers

nothing calls this directly

Calls 7

UpdateInfoMethod · 0.95
NewPeerFunction · 0.92
HeadersReqHandleFunction · 0.85
SetAddrMethod · 0.80
AddNbrNodeMethod · 0.65
GetCurrentHeaderHashMethod · 0.65
DelNbrNodeMethod · 0.65

Tested by

no test coverage detected