TestPingHandle tests Function PingHandle handling a ping message
(t *testing.T)
| 441 | |
| 442 | // TestPingHandle tests Function PingHandle handling a ping message |
| 443 | func TestPingHandle(t *testing.T) { |
| 444 | // Simulate a remote peer to be added to the neighbor peers |
| 445 | var testID uint64 |
| 446 | _, testPub, _ := keypair.GenerateKeyPair(keypair.PK_ECDSA, keypair.P256) |
| 447 | key := keypair.SerializePublicKey(testPub) |
| 448 | err := binary.Read(bytes.NewBuffer(key[:8]), binary.LittleEndian, &(testID)) |
| 449 | assert.Nil(t, err) |
| 450 | |
| 451 | remotePeer := peer.NewPeer() |
| 452 | assert.NotNil(t, remotePeer) |
| 453 | remotePeer.UpdateInfo(time.Now(), 1, 12345678, 20336, |
| 454 | testID, 0, 12345, "1.5.2") |
| 455 | remotePeer.Link.SetAddr("127.0.0.1:50010") |
| 456 | |
| 457 | network.AddNbrNode(remotePeer) |
| 458 | |
| 459 | // Construct a ping packet |
| 460 | height := ledger.DefLedger.GetCurrentBlockHeight() |
| 461 | assert.Nil(t, err) |
| 462 | |
| 463 | buf := msgpack.NewPingMsg(uint64(height)) |
| 464 | |
| 465 | msg := &types.MsgPayload{ |
| 466 | Id: testID, |
| 467 | Addr: "127.0.0.1:50010", |
| 468 | Payload: buf, |
| 469 | } |
| 470 | |
| 471 | // Invoke PingHandle to handle the msg |
| 472 | PingHandle(msg, network, nil) |
| 473 | |
| 474 | network.DelNbrNode(testID) |
| 475 | } |
| 476 | |
| 477 | // TestPingHandle tests Function PingHandle handling a pong message |
| 478 | func TestPongHandle(t *testing.T) { |
nothing calls this directly
no test coverage detected