Skip to content

test(network): add unit tests for eth2network connections and primary messaging#793

Open
zclawz wants to merge 1 commit into
mainfrom
zclawz/issue-159
Open

test(network): add unit tests for eth2network connections and primary messaging#793
zclawz wants to merge 1 commit into
mainfrom
zclawz/issue-159

Conversation

@zclawz

@zclawz zclawz commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Closes #159

Summary

Adds pkgs/network/src/test.zig with 10 unit tests covering the network interface layer without any node dependencies:

Interface encoding

  • GossipEncoding encode/decode roundtrip and unknown-string error
  • GossipTopic encode/decode roundtrip for block, aggregation, and attestation (with subnet_id)
  • GossipTopic decode unknown returns error
  • GossipMessage.getGossipTopic returns correct active tag

GenericGossipHandler (direct)

  • Subscribe and synchronous delivery of a block message
  • Multiple subscribers all receive the same published message
  • Topic filtering: a block subscriber does not receive an attestation message
  • Subscribe and deliver an attestation with matching subnet_id

Mock network

  • Publish attestation and receive via subscriber
  • Topic isolation: block subscriber drops attestation
  • Concurrent block and attestation subscribers each receive only their own type

Testing

  • zig build test passes

Note: an existing PR (#202 by @bomanaps) targeted the same issue but has merge conflicts and uses the old API (GossipTopic was a plain enum; onGossipFn had a different signature). This PR is based on current main and uses the current interface.

… messaging

Adds pkgs/network/src/test.zig with unit tests covering:
- GossipEncoding encode/decode roundtrip and error handling
- GossipTopic encode/decode roundtrip (block, aggregation, attestation
  with subnet_id)
- GossipMessage.getGossipTopic active tag
- GenericGossipHandler: subscribe and synchronous delivery of block msgs
- GenericGossipHandler: multiple subscribers receive the same message
- GenericGossipHandler: topic filtering (unsubscribed topics are dropped)
- GenericGossipHandler: attestation subscribe + deliver
- Mock network: publish attestation and receive via subscriber
- Mock network: topic isolation (block subscriber drops attestation)
- Mock network: concurrent block and attestation subscribers each receive
  only their own type

Tests use only network interface objects (interface.zig, mock.zig,
GenericGossipHandler) — no node dependencies.

Closes #159
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add unit test for testing eth2network connections and primary messaging

1 participant