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

Function TestBlockHandle

p2pserver/message/utils/msg_handler_test.go:550–587  ·  view source on GitHub ↗

TestBlockHandle tests Function BlockHandle handling a block message

(t *testing.T)

Source from the content-addressed store, hash-verified

548
549// TestBlockHandle tests Function BlockHandle handling a block message
550func TestBlockHandle(t *testing.T) {
551 // Simulate a remote peer to be added to the neighbor peers
552 var testID uint64
553 _, testPub, _ := keypair.GenerateKeyPair(keypair.PK_ECDSA, keypair.P256)
554 key := keypair.SerializePublicKey(testPub)
555 err := binary.Read(bytes.NewBuffer(key[:8]), binary.LittleEndian, &(testID))
556 assert.Nil(t, err)
557
558 remotePeer := peer.NewPeer()
559 assert.NotNil(t, remotePeer)
560 remotePeer.UpdateInfo(time.Now(), 1, 12345678, 20336,
561 testID, 0, 12345, "1.5.2")
562 remotePeer.Link.SetAddr("127.0.0.1:50010")
563
564 network.AddNbrNode(remotePeer)
565
566 // Construct a block packet
567 hash := ledger.DefLedger.GetBlockHash(0)
568 assert.NotEqual(t, hash, common.UINT256_EMPTY)
569
570 block, err := ledger.DefLedger.GetBlockByHash(hash)
571 assert.Nil(t, err)
572
573 mr, err := common.Uint256FromHexString("1b8fa7f242d0eeb4395f89cbb59e4c29634047e33245c4914306e78a88e14ce5")
574 assert.Nil(t, err)
575 buf := msgpack.NewBlock(block, mr)
576
577 msg := &types.MsgPayload{
578 Id: testID,
579 Addr: "127.0.0.1:50010",
580 Payload: buf,
581 }
582
583 // Invoke BlockHandle to handle the msg
584 BlockHandle(msg, network, nil)
585
586 network.DelNbrNode(testID)
587}
588
589// TestConsensusHandle tests Function ConsensusHandle handling a consensus message
590func TestConsensusHandle(t *testing.T) {

Callers

nothing calls this directly

Calls 8

UpdateInfoMethod · 0.95
NewPeerFunction · 0.92
BlockHandleFunction · 0.85
SetAddrMethod · 0.80
AddNbrNodeMethod · 0.65
GetBlockHashMethod · 0.65
GetBlockByHashMethod · 0.65
DelNbrNodeMethod · 0.65

Tested by

no test coverage detected