TestPingHandle tests Function PingHandle handling a pong message
(t *testing.T)
| 476 | |
| 477 | // TestPingHandle tests Function PingHandle handling a pong message |
| 478 | func TestPongHandle(t *testing.T) { |
| 479 | // Simulate a remote peer to be added to the neighbor peers |
| 480 | var testID uint64 |
| 481 | _, testPub, _ := keypair.GenerateKeyPair(keypair.PK_ECDSA, keypair.P256) |
| 482 | key := keypair.SerializePublicKey(testPub) |
| 483 | err := binary.Read(bytes.NewBuffer(key[:8]), binary.LittleEndian, &(testID)) |
| 484 | assert.Nil(t, err) |
| 485 | |
| 486 | remotePeer := peer.NewPeer() |
| 487 | assert.NotNil(t, remotePeer) |
| 488 | remotePeer.UpdateInfo(time.Now(), 1, 12345678, 20336, |
| 489 | testID, 0, 12345, "1.5.2") |
| 490 | remotePeer.Link.SetAddr("127.0.0.1:50010") |
| 491 | |
| 492 | network.AddNbrNode(remotePeer) |
| 493 | |
| 494 | // Construct a pong packet |
| 495 | height := ledger.DefLedger.GetCurrentBlockHeight() |
| 496 | assert.Nil(t, err) |
| 497 | |
| 498 | buf := msgpack.NewPongMsg(uint64(height)) |
| 499 | |
| 500 | msg := &types.MsgPayload{ |
| 501 | Id: testID, |
| 502 | Addr: "127.0.0.1:50010", |
| 503 | Payload: buf, |
| 504 | } |
| 505 | |
| 506 | // Invoke PingHandle to handle the msg |
| 507 | PongHandle(msg, network, nil) |
| 508 | |
| 509 | network.DelNbrNode(testID) |
| 510 | } |
| 511 | |
| 512 | // TestBlkHeaderHandle tests Function BlkHeaderHandle handling a sync header msg |
| 513 | func TestBlkHeaderHandle(t *testing.T) { |
nothing calls this directly
no test coverage detected