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

Function TestBlkHeaderHandle

p2pserver/message/utils/msg_handler_test.go:513–547  ·  view source on GitHub ↗

TestBlkHeaderHandle tests Function BlkHeaderHandle handling a sync header msg

(t *testing.T)

Source from the content-addressed store, hash-verified

511
512// TestBlkHeaderHandle tests Function BlkHeaderHandle handling a sync header msg
513func TestBlkHeaderHandle(t *testing.T) {
514 // Simulate a remote peer to be added to the neighbor peers
515 var testID uint64
516 _, testPub, _ := keypair.GenerateKeyPair(keypair.PK_ECDSA, keypair.P256)
517 key := keypair.SerializePublicKey(testPub)
518 err := binary.Read(bytes.NewBuffer(key[:8]), binary.LittleEndian, &(testID))
519 assert.Nil(t, err)
520
521 remotePeer := peer.NewPeer()
522 assert.NotNil(t, remotePeer)
523 remotePeer.UpdateInfo(time.Now(), 1, 12345678, 20336, testID, 0, 12345, "1.5.2")
524 remotePeer.Link.SetAddr("127.0.0.1:50010")
525
526 network.AddNbrNode(remotePeer)
527
528 // Construct a sync header packet
529 hash := ledger.DefLedger.GetBlockHash(0)
530 assert.NotEqual(t, hash, common.UINT256_EMPTY)
531
532 headers, err := GetHeadersFromHash(hash, hash)
533 assert.Nil(t, err)
534
535 buf := msgpack.NewHeaders(headers)
536
537 msg := &types.MsgPayload{
538 Id: testID,
539 Addr: "127.0.0.1:50010",
540 Payload: buf,
541 }
542
543 // Invoke BlkHeaderHandle to handle the msg
544 BlkHeaderHandle(msg, network, nil)
545
546 network.DelNbrNode(testID)
547}
548
549// TestBlockHandle tests Function BlockHandle handling a block message
550func TestBlockHandle(t *testing.T) {

Callers

nothing calls this directly

Calls 8

UpdateInfoMethod · 0.95
NewPeerFunction · 0.92
GetHeadersFromHashFunction · 0.85
BlkHeaderHandleFunction · 0.85
SetAddrMethod · 0.80
AddNbrNodeMethod · 0.65
GetBlockHashMethod · 0.65
DelNbrNodeMethod · 0.65

Tested by

no test coverage detected