Documentation
¶
Overview ¶
Package helpers provides utilities for integration testing the HORNETS relay
Package helpers provides utilities for integration testing the HORNETS relay ¶
Package helpers provides utilities for integration testing the HORNETS relay ¶
Package helpers provides utilities for integration testing the HORNETS relay ¶
Package helpers provides utilities for integration testing the HORNETS relay
Index ¶
- func CreateContactList(kp *TestKeyPair, contacts []string) (*nostr.Event, error)
- func CreateDeletionEvent(kp *TestKeyPair, eventIDs []string, reason string) (*nostr.Event, error)
- func CreateFixture(baseDir string, fixture TestFixture) (string, error)
- func CreateGenericEvent(kp *TestKeyPair, kind int, content string, tags nostr.Tags) (*nostr.Event, error)
- func CreateMetadata(kp *TestKeyPair, name, about, picture string) (*nostr.Event, error)
- func CreateParameterizedReplaceableEvent(kp *TestKeyPair, kind int, dTag, content string) (*nostr.Event, error)
- func CreateReaction(kp *TestKeyPair, eventID, eventPubKey, reaction string) (*nostr.Event, error)
- func CreateReplaceableEvent(kp *TestKeyPair, kind int, content string) (*nostr.Event, error)
- func CreateRepost(kp *TestKeyPair, eventID, eventPubKey, relayURL string, ...) (*nostr.Event, error)
- func CreateTextNote(kp *TestKeyPair, content string, tags ...nostr.Tag) (*nostr.Event, error)
- func GetDAGLeafByIndex(dag *merkle_dag.Dag, index int) (*merkle_dag.DagLeaf, error)
- func GetDAGLeafHashes(dag *merkle_dag.Dag) []string
- func GetDirectoryLeafHashes(dag *merkle_dag.Dag) []string
- func GetFileLeafHashes(dag *merkle_dag.Dag) []string
- func GetLeafTypeCount(dag *merkle_dag.Dag) map[string]int
- func RunTestWithAllFixtures(t *testing.T, testFunc func(*testing.T, *FixtureDAG))
- func RunTestWithFixture(t *testing.T, fixtureName string, testFunc func(*testing.T, *FixtureDAG))
- func RunTestWithMultiFileFixtures(t *testing.T, testFunc func(*testing.T, *FixtureDAG))
- func SignDAG(dag *merkle_dag.Dag, kp *TestDAGKeyPair) (string, error)
- func VerifyDAGSignature(root string, signatureHex string, publicKey *secp256k1.PublicKey) error
- type FixtureDAG
- type TestConnectionNotifier
- func (n *TestConnectionNotifier) Connected(net network.Network, conn network.Conn)
- func (n *TestConnectionNotifier) Disconnected(net network.Network, conn network.Conn)
- func (n *TestConnectionNotifier) Listen(net network.Network, multiaddr multiaddr.Multiaddr)
- func (n *TestConnectionNotifier) ListenClose(net network.Network, multiaddr multiaddr.Multiaddr)
- type TestDAG
- type TestDAGKeyPair
- type TestFixture
- func DeepHierarchy() TestFixture
- func FlatDirectory() TestFixture
- func GetAllFixtures() []TestFixture
- func GetChunkingFixtures() []TestFixture
- func GetFixtureByName(name string) (TestFixture, bool)
- func GetHierarchyFixtures() []TestFixture
- func GetMultiFileFixtures() []TestFixture
- func GetSingleFileFixtures() []TestFixture
- func ManySmallFiles() TestFixture
- func MixedSizes() TestFixture
- func NestedDirectory() TestFixture
- func SingleLargeFile() TestFixture
- func SingleSmallFile() TestFixture
- type TestKeyPair
- type TestLibp2pRelay
- type TestLibp2pRelayConfig
- type TestRelay
- func NewTestRelay(cfg TestRelayConfig) (*TestRelay, error)
- func NewTestRelayWithAirlock(cfg TestRelayConfig) (*TestRelay, error)
- func NewTestRelayWithBlossom(cfg TestRelayConfig) (*TestRelay, error)
- func NewTestRelayWithHornets(cfg TestRelayConfig) (*TestRelay, error)
- func NewTestRelayWithServices(cfg TestRelayConfig) (*TestRelay, error)
- type TestRelayConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateContactList ¶
func CreateContactList(kp *TestKeyPair, contacts []string) (*nostr.Event, error)
CreateContactList creates a kind 3 contact list event
func CreateDeletionEvent ¶
CreateDeletionEvent creates a kind 5 deletion event
func CreateFixture ¶
func CreateFixture(baseDir string, fixture TestFixture) (string, error)
CreateFixture creates a test fixture in the specified directory Returns the path to the created fixture directory
func CreateGenericEvent ¶
func CreateGenericEvent(kp *TestKeyPair, kind int, content string, tags nostr.Tags) (*nostr.Event, error)
CreateGenericEvent creates an event of any kind
func CreateMetadata ¶
func CreateMetadata(kp *TestKeyPair, name, about, picture string) (*nostr.Event, error)
CreateMetadata creates a kind 0 metadata event
func CreateParameterizedReplaceableEvent ¶
func CreateParameterizedReplaceableEvent(kp *TestKeyPair, kind int, dTag, content string) (*nostr.Event, error)
CreateParameterizedReplaceableEvent creates a parameterized replaceable event (kinds 30000-39999)
func CreateReaction ¶
func CreateReaction(kp *TestKeyPair, eventID, eventPubKey, reaction string) (*nostr.Event, error)
CreateReaction creates a kind 7 reaction event
func CreateReplaceableEvent ¶
CreateReplaceableEvent creates a replaceable event (kinds 0, 3, or 10000-19999)
func CreateRepost ¶
func CreateRepost(kp *TestKeyPair, eventID, eventPubKey, relayURL string, originalEvent *nostr.Event) (*nostr.Event, error)
CreateRepost creates a kind 6 repost event
func CreateTextNote ¶
CreateTextNote creates a kind 1 text note event
func GetDAGLeafByIndex ¶
func GetDAGLeafByIndex(dag *merkle_dag.Dag, index int) (*merkle_dag.DagLeaf, error)
GetDAGLeafByIndex returns a leaf by its index in the Leafs map Note: Map ordering is not guaranteed, so this returns any leaf at the given position
func GetDAGLeafHashes ¶
func GetDAGLeafHashes(dag *merkle_dag.Dag) []string
GetDAGLeafHashes returns all leaf hashes in the DAG
func GetDirectoryLeafHashes ¶
func GetDirectoryLeafHashes(dag *merkle_dag.Dag) []string
GetDirectoryLeafHashes returns all directory leaf hashes from a DAG in a deterministic order
func GetFileLeafHashes ¶
func GetFileLeafHashes(dag *merkle_dag.Dag) []string
GetFileLeafHashes returns all file leaf hashes from a DAG in a deterministic order
func GetLeafTypeCount ¶
func GetLeafTypeCount(dag *merkle_dag.Dag) map[string]int
GetLeafTypeCount returns a map of leaf types to their counts (for debugging)
func RunTestWithAllFixtures ¶
func RunTestWithAllFixtures(t *testing.T, testFunc func(*testing.T, *FixtureDAG))
RunTestWithAllFixtures runs a test function against all fixtures
func RunTestWithFixture ¶
RunTestWithFixture runs a test function against a specific fixture
func RunTestWithMultiFileFixtures ¶
func RunTestWithMultiFileFixtures(t *testing.T, testFunc func(*testing.T, *FixtureDAG))
RunTestWithMultiFileFixtures runs a test against fixtures with multiple files
func SignDAG ¶
func SignDAG(dag *merkle_dag.Dag, kp *TestDAGKeyPair) (string, error)
SignDAG signs the DAG root with the provided key pair
Types ¶
type FixtureDAG ¶
type FixtureDAG struct {
Dag *merkle_dag.Dag
Fixture TestFixture
FixturePath string
TempDir string
}
FixtureDAG holds a DAG created from a fixture along with metadata
func CreateDAGFromFixture ¶
func CreateDAGFromFixture(fixture TestFixture) (*FixtureDAG, error)
CreateDAGFromFixture creates a DAG from a specific fixture
func CreateDAGFromFixtureName ¶
func CreateDAGFromFixtureName(name string) (*FixtureDAG, error)
CreateDAGFromFixtureName creates a DAG from a fixture by name
func (*FixtureDAG) Cleanup ¶
func (fd *FixtureDAG) Cleanup() error
Cleanup removes the temporary directory
type TestConnectionNotifier ¶
type TestConnectionNotifier struct {
ConnectedChan chan struct{}
DisconnectedChan chan struct{}
}
TestConnectionNotifier is a connection notifier for testing
func NewTestConnectionNotifier ¶
func NewTestConnectionNotifier() *TestConnectionNotifier
func (*TestConnectionNotifier) Connected ¶
func (n *TestConnectionNotifier) Connected(net network.Network, conn network.Conn)
func (*TestConnectionNotifier) Disconnected ¶
func (n *TestConnectionNotifier) Disconnected(net network.Network, conn network.Conn)
func (*TestConnectionNotifier) Listen ¶
func (n *TestConnectionNotifier) Listen(net network.Network, multiaddr multiaddr.Multiaddr)
func (*TestConnectionNotifier) ListenClose ¶
func (n *TestConnectionNotifier) ListenClose(net network.Network, multiaddr multiaddr.Multiaddr)
type TestDAG ¶
type TestDAG struct {
Dag *merkle_dag.Dag
Root string
LeafCount int
TempDir string // Temp directory used to create the DAG (cleanup after)
}
TestDAG represents a test DAG with metadata
func CreateLargeTestDAG ¶
CreateLargeTestDAG creates a DAG with multiple files for testing chunked operations
func CreateNestedTestDAG ¶
CreateNestedTestDAG creates a DAG with nested directory structure
func CreateTestDAGFromContent ¶
CreateTestDAGFromContent creates a DAG from string content
func CreateTestDAGFromFiles ¶
CreateTestDAGFromFiles creates a DAG from multiple files
type TestDAGKeyPair ¶
type TestDAGKeyPair struct {
PrivateKey *secp256k1.PrivateKey
PublicKey *secp256k1.PublicKey
PrivateHex string
PublicHex string
}
TestDAGKeyPair represents a secp256k1 key pair for DAG signing
func GenerateDAGKeyPair ¶
func GenerateDAGKeyPair() (*TestDAGKeyPair, error)
GenerateDAGKeyPair generates a new secp256k1 key pair for DAG operations
type TestFixture ¶
type TestFixture struct {
Name string
Description string
Setup func(baseDir string) error
ExpectedFiles int
ExpectedDirs int
ExpectedChunks int
}
TestFixture represents a deterministic test data structure
func DeepHierarchy ¶
func DeepHierarchy() TestFixture
DeepHierarchy creates a deeply nested directory structure Use case: Testing deep path traversal, verification paths through multiple levels
func FlatDirectory ¶
func FlatDirectory() TestFixture
FlatDirectory creates a directory with multiple files at the same level Use case: Testing parent-child relationships, merkle proofs for siblings
func GetAllFixtures ¶
func GetAllFixtures() []TestFixture
GetAllFixtures returns all available test fixtures
func GetChunkingFixtures ¶
func GetChunkingFixtures() []TestFixture
GetChunkingFixtures returns fixtures that test chunking behavior
func GetFixtureByName ¶
func GetFixtureByName(name string) (TestFixture, bool)
GetFixtureByName returns a specific fixture by name
func GetHierarchyFixtures ¶
func GetHierarchyFixtures() []TestFixture
GetHierarchyFixtures returns fixtures with nested directory structures
func GetMultiFileFixtures ¶
func GetMultiFileFixtures() []TestFixture
GetMultiFileFixtures returns fixtures that have multiple files (useful for partial DAG tests)
func GetSingleFileFixtures ¶
func GetSingleFileFixtures() []TestFixture
GetSingleFileFixtures returns fixtures with only one file
func ManySmallFiles ¶
func ManySmallFiles() TestFixture
ManySmallFiles creates a directory with many small files Use case: Testing batching, many sibling merkle proofs
func MixedSizes ¶
func MixedSizes() TestFixture
MixedSizes creates a structure with both small and large files requiring chunking Use case: Testing mixed scenarios with and without chunking
func NestedDirectory ¶
func NestedDirectory() TestFixture
NestedDirectory creates a two-level directory structure Use case: Testing directory traversal, multiple parent-child levels
func SingleLargeFile ¶
func SingleLargeFile() TestFixture
SingleLargeFile creates a single file above the chunk size requiring chunking Use case: Testing file chunking, merkle tree construction for chunks
func SingleSmallFile ¶
func SingleSmallFile() TestFixture
SingleSmallFile creates a single file well below the chunk size (4KB default) Use case: Testing basic file DAG creation, single leaf DAGs
type TestKeyPair ¶
TestKeyPair represents a key pair for testing
func GenerateKeyPair ¶
func GenerateKeyPair() (*TestKeyPair, error)
GenerateKeyPair generates a new key pair for testing
type TestLibp2pRelay ¶
type TestLibp2pRelay struct {
Store *badgerhold.BadgerholdStore
Host host.Host
Multiaddr string // Full multiaddr including peer ID
DataDir string
PrivateKey string
PublicKey string
// contains filtered or unexported fields
}
TestLibp2pRelay represents a test relay instance with libp2p support
func NewTestLibp2pRelay ¶
func NewTestLibp2pRelay(cfg TestLibp2pRelayConfig) (*TestLibp2pRelay, error)
NewTestLibp2pRelay creates and starts a new test libp2p relay
func (*TestLibp2pRelay) Cleanup ¶
func (r *TestLibp2pRelay) Cleanup() error
Cleanup stops the relay and removes all test data
func (*TestLibp2pRelay) GetConnectionManager ¶
func (r *TestLibp2pRelay) GetConnectionManager(ctx context.Context) (*connmgr.GenericConnectionManager, error)
GetConnectionManager creates a connection manager connected to this relay
func (*TestLibp2pRelay) Stop ¶
func (r *TestLibp2pRelay) Stop() error
Stop stops the test relay and cleans up resources
func (*TestLibp2pRelay) WaitForReady ¶
func (r *TestLibp2pRelay) WaitForReady(timeout time.Duration) error
WaitForReady waits for the relay to be ready to accept connections
type TestLibp2pRelayConfig ¶
type TestLibp2pRelayConfig struct {
DataDir string
PrivateKey string // Optional - will generate if empty
}
TestLibp2pRelayConfig holds configuration for a test libp2p relay
func DefaultTestLibp2pConfig ¶
func DefaultTestLibp2pConfig() TestLibp2pRelayConfig
DefaultTestLibp2pConfig returns a default test configuration for libp2p relay
type TestRelay ¶
type TestRelay struct {
Store *badgerhold.BadgerholdStore
App *fiber.App
Port int
BlossomPort int // Port for blossom/web services
URL string
DataDir string
PrivateKey string
PublicKey string
// contains filtered or unexported fields
}
TestRelay represents a test relay instance
func NewTestRelay ¶
func NewTestRelay(cfg TestRelayConfig) (*TestRelay, error)
NewTestRelay creates and starts a new test relay
func NewTestRelayWithAirlock ¶
func NewTestRelayWithAirlock(cfg TestRelayConfig) (*TestRelay, error)
NewTestRelayWithAirlock creates a test relay with airlock service configured
func NewTestRelayWithBlossom ¶
func NewTestRelayWithBlossom(cfg TestRelayConfig) (*TestRelay, error)
NewTestRelayWithBlossom creates a test relay with blossom service enabled This starts both the WebSocket server and a separate HTTP server for blossom routes
func NewTestRelayWithHornets ¶
func NewTestRelayWithHornets(cfg TestRelayConfig) (*TestRelay, error)
NewTestRelayWithHornets creates a test relay with hornets (libp2p) service configured
func NewTestRelayWithServices ¶
func NewTestRelayWithServices(cfg TestRelayConfig) (*TestRelay, error)
NewTestRelayWithServices creates a test relay with web and blossom services enabled
type TestRelayConfig ¶
type TestRelayConfig struct {
Port int
DataDir string
PrivateKey string // Optional - will generate if empty
EnableAuth bool
AllowedKinds []int
ModerationMode string // strict, moderate, relaxed
}
TestRelayConfig holds configuration for a test relay
func DefaultTestConfig ¶
func DefaultTestConfig() TestRelayConfig
DefaultTestConfig returns a default test configuration