ntu

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

README

Network Test Utilities

Helpers for exercising network protocols in-memory without real transports.

Documentation

Overview

Package ntu provides helpers for exercising network protocols in-memory without real transports.

See README.md for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CBORRoundTrip

func CBORRoundTrip[T any](tb testing.TB, v T) T

CBORRoundTrip serialises and deserialises a value, asserting round-trip fidelity.

func MakeRandomQuorum

func MakeRandomQuorum(tb testing.TB, prng io.Reader, n int) network.Quorum

MakeRandomQuorum samples a random quorum of distinct non-zero sharing IDs.

func MakeRandomSessionID

func MakeRandomSessionID(tb testing.TB, prng io.Reader) network.SID

MakeRandomSessionID reads 32 random bytes into an SID.

func MapBroadcastO2I

func MapBroadcastO2I[
	P interface {
		SharingID() sharing.ID
	}, BcastT network.Message,
](
	tb testing.TB,
	participants []P,
	broadcastOutputs map[sharing.ID]BcastT,
) (
	broadcastInputs map[sharing.ID]network.RoundMessages[BcastT],
)

MapBroadcastO2I maps the broadcasts of all participants in a round of a protocol to the inputs of the next round with serialising and deserializing them throughout the process.

func MapO2I

func MapO2I[
	P TestParticipant, BcastT, UnicastT network.Message,
](
	tb testing.TB,
	participants []P,
	broadcastOutputs map[sharing.ID]BcastT,
	UnicastOutputs map[sharing.ID]network.RoundMessages[UnicastT],
) (
	broadcastInputs map[sharing.ID]network.RoundMessages[BcastT],
	UnicastInputs map[sharing.ID]network.RoundMessages[UnicastT],
)

MapO2I maps the outputs of all participants in a round of a protocol to the inputs of the next round with serialising and deserializing them throughout the process.

func MapUnicastO2I

func MapUnicastO2I[
	P interface {
		SharingID() sharing.ID
	}, UnicastT network.Message,
](
	tb testing.TB,
	participants []P,
	p2pOutputs map[sharing.ID]network.RoundMessages[UnicastT],
) (
	p2pInputs map[sharing.ID]network.RoundMessages[UnicastT],
)

MapUnicastO2I maps the P2P messages of all participants in a round of a protocol to the inputs of the next round with serialising and deserializing them throughout the process.

func TestExecuteRunners

func TestExecuteRunners[O any](tb testing.TB, runners map[sharing.ID]network.Runner[O]) map[sharing.ID]O

TestExecuteRunners concurrently executes the given runners with mock deliveries and collects their outputs.

Types

type MockCoordinator

type MockCoordinator struct {
	// contains filtered or unexported fields
}

MockCoordinator simulates a reliable message hub using buffered channels.

func NewMockCoordinator

func NewMockCoordinator(quorum ...sharing.ID) *MockCoordinator

NewMockCoordinator allocates buffered in-memory channels for each party in the quorum.

func (*MockCoordinator) DeliveryFor

func (c *MockCoordinator) DeliveryFor(sharingID sharing.ID) network.Delivery

DeliveryFor returns a Delivery implementation bound to the given party.

type TestParticipant

type TestParticipant interface {
	SharingID() sharing.ID
}

TestParticipant is the minimal interface needed to route messages in helpers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL