TestBlkHeaderHandle tests Function BlkHeaderHandle handling a sync header msg
(t *testing.T)
| 511 | |
| 512 | // TestBlkHeaderHandle tests Function BlkHeaderHandle handling a sync header msg |
| 513 | func 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 |
| 550 | func TestBlockHandle(t *testing.T) { |
nothing calls this directly
no test coverage detected