MCPcopy
hub / github.com/canopy-network/canopy / TestGetInboxStats

Function TestGetInboxStats

p2p/p2p_test.go:569–691  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

567}
568
569func TestGetInboxStats(t *testing.T) {
570 tests := []struct {
571 name string
572 detail string
573 setup func(*P2P)
574 expected map[lib.Topic]int
575 }{
576 {
577 name: "empty inboxes",
578 detail: "all inboxes are empty",
579 setup: func(p *P2P) {},
580 expected: map[lib.Topic]int{
581 lib.Topic_CONSENSUS: 0,
582 lib.Topic_BLOCK: 0,
583 lib.Topic_BLOCK_REQUEST: 0,
584 lib.Topic_TX: 0,
585 lib.Topic_PEERS_RESPONSE: 0,
586 lib.Topic_PEERS_REQUEST: 0,
587 lib.Topic_HEARTBEAT: 0,
588 },
589 },
590 {
591 name: "single message in TX inbox",
592 detail: "one transaction message queued",
593 setup: func(p *P2P) {
594 // Create a fake peer info
595 peerInfo := &lib.PeerInfo{
596 Address: &lib.PeerAddress{
597 PublicKey: []byte("test-peer"),
598 NetAddress: "localhost:9001",
599 PeerMeta: &lib.PeerMeta{NetworkId: 1, ChainId: 1},
600 },
601 }
602 // Send a message to TX channel
603 txMsg := &lib.TxMessage{ChainId: 1, Txs: [][]byte{[]byte("test-tx")}}
604 msgBytes, _ := lib.Marshal(txMsg)
605 p.channels[lib.Topic_TX] <- &lib.MessageAndMetadata{
606 Message: msgBytes,
607 Sender: peerInfo,
608 }
609 },
610 expected: map[lib.Topic]int{
611 lib.Topic_CONSENSUS: 0,
612 lib.Topic_BLOCK: 0,
613 lib.Topic_BLOCK_REQUEST: 0,
614 lib.Topic_TX: 1,
615 lib.Topic_PEERS_RESPONSE: 0,
616 lib.Topic_PEERS_REQUEST: 0,
617 lib.Topic_HEARTBEAT: 0,
618 },
619 },
620 {
621 name: "multiple messages in different inboxes",
622 detail: "messages spread across multiple topics",
623 setup: func(p *P2P) {
624 peerInfo := &lib.PeerInfo{
625 Address: &lib.PeerAddress{
626 PublicKey: []byte("test-peer"),

Callers

nothing calls this directly

Calls 6

MarshalFunction · 0.92
newTestP2PNodeFunction · 0.85
RunMethod · 0.80
GetInboxStatsMethod · 0.80
EqualMethod · 0.80
StopMethod · 0.45

Tested by

no test coverage detected