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

Function TestInvHandle

p2pserver/message/utils/msg_handler_test.go:721–752  ·  view source on GitHub ↗

TestInvHandle tests Function InvHandle handling an inventory message

(t *testing.T)

Source from the content-addressed store, hash-verified

719
720// TestInvHandle tests Function InvHandle handling an inventory message
721func TestInvHandle(t *testing.T) {
722 var testID uint64
723 _, testPub, _ := keypair.GenerateKeyPair(keypair.PK_ECDSA, keypair.P256)
724 key := keypair.SerializePublicKey(testPub)
725 err := binary.Read(bytes.NewBuffer(key[:8]), binary.LittleEndian, &(testID))
726 assert.Nil(t, err)
727
728 remotePeer := peer.NewPeer()
729 assert.NotNil(t, remotePeer)
730 remotePeer.UpdateInfo(time.Now(), 1, 12345678, 20336,
731 testID, 0, 12345, "1.5.2")
732 remotePeer.Link.SetAddr("127.0.0.1:50010")
733
734 network.AddNbrNode(remotePeer)
735
736 hash := ledger.DefLedger.GetBlockHash(0)
737 assert.NotEqual(t, hash, common.UINT256_EMPTY)
738
739 buf := bytes.NewBuffer([]byte{})
740 hash.Serialize(buf)
741 invPayload := msgpack.NewInvPayload(common.BLOCK, []common.Uint256{hash})
742 buffer := msgpack.NewInv(invPayload)
743 msg := &types.MsgPayload{
744 Id: testID,
745 Addr: "127.0.0.1:50010",
746 Payload: buffer,
747 }
748
749 InvHandle(msg, network, nil)
750
751 network.DelNbrNode(testID)
752}
753
754// TestDisconnectHandle tests Function DisconnectHandle handling a disconnect event
755func TestDisconnectHandle(t *testing.T) {

Callers

nothing calls this directly

Calls 8

UpdateInfoMethod · 0.95
NewPeerFunction · 0.92
InvHandleFunction · 0.85
SetAddrMethod · 0.80
AddNbrNodeMethod · 0.65
GetBlockHashMethod · 0.65
SerializeMethod · 0.65
DelNbrNodeMethod · 0.65

Tested by

no test coverage detected