TestDataReqHandle tests Function DataReqHandle handling a data req(block/Transaction)
(t *testing.T)
| 675 | |
| 676 | // TestDataReqHandle tests Function DataReqHandle handling a data req(block/Transaction) |
| 677 | func 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 |
| 721 | func TestInvHandle(t *testing.T) { |
nothing calls this directly
no test coverage detected