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

Function TestDataReqHandle

p2pserver/message/utils/msg_handler_test.go:677–718  ·  view source on GitHub ↗

TestDataReqHandle tests Function DataReqHandle handling a data req(block/Transaction)

(t *testing.T)

Source from the content-addressed store, hash-verified

675
676// TestDataReqHandle tests Function DataReqHandle handling a data req(block/Transaction)
677func TestDataReqHandle(t *testing.T) {
678 var testID uint64
679 _, testPub, _ := keypair.GenerateKeyPair(keypair.PK_ECDSA, keypair.P256)
680 key := keypair.SerializePublicKey(testPub)
681 err := binary.Read(bytes.NewBuffer(key[:8]), binary.LittleEndian, &(testID))
682 assert.Nil(t, err)
683
684 remotePeer := peer.NewPeer()
685 assert.NotNil(t, remotePeer)
686 remotePeer.UpdateInfo(time.Now(), 1, 12345678, 20336,
687 testID, 0, 12345, "1.5.2")
688 remotePeer.Link.SetAddr("127.0.0.1:50010")
689
690 network.AddNbrNode(remotePeer)
691
692 hash := ledger.DefLedger.GetBlockHash(0)
693 assert.NotEqual(t, hash, common.UINT256_EMPTY)
694 buf := msgpack.NewBlkDataReq(hash)
695
696 msg := &types.MsgPayload{
697 Id: testID,
698 Addr: "127.0.0.1:50010",
699 Payload: buf,
700 }
701
702 DataReqHandle(msg, network, nil)
703
704 tempStr := "3369930accc1ddd067245e8edadcd9bea207ba5e1753ac18a51df77a343bfe92"
705 hex, _ := hex.DecodeString(tempStr)
706 var txHash common.Uint256
707 txHash.Deserialize(bytes.NewReader(hex))
708 buf = msgpack.NewTxnDataReq(txHash)
709 msg = &types.MsgPayload{
710 Id: testID,
711 Addr: "127.0.0.1:50010",
712 Payload: buf,
713 }
714
715 DataReqHandle(msg, network, nil)
716
717 network.DelNbrNode(testID)
718}
719
720// TestInvHandle tests Function InvHandle handling an inventory message
721func TestInvHandle(t *testing.T) {

Callers

nothing calls this directly

Calls 8

UpdateInfoMethod · 0.95
DeserializeMethod · 0.95
NewPeerFunction · 0.92
DataReqHandleFunction · 0.85
SetAddrMethod · 0.80
AddNbrNodeMethod · 0.65
GetBlockHashMethod · 0.65
DelNbrNodeMethod · 0.65

Tested by

no test coverage detected