relaytester

package
v0.58.13 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: Unlicense Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDeleteEvent

func CreateDeleteEvent(signer *p8k.Signer, eventIDs [][]byte, reason string) (ev *event.E, err error)

CreateDeleteEvent creates a deletion event (kind 5).

func CreateEphemeralEvent

func CreateEphemeralEvent(signer *p8k.Signer, kindNum uint16, content string) (ev *event.E, err error)

CreateEphemeralEvent creates an ephemeral event (kind 20000-29999).

func CreateEvent

func CreateEvent(signer *p8k.Signer, kindNum uint16, content string, tags *tag.S) (ev *event.E, err error)

CreateEvent creates a signed event with the given parameters.

func CreateEventWithTags

func CreateEventWithTags(signer *p8k.Signer, kindNum uint16, content string, tagPairs [][]string) (ev *event.E, err error)

CreateEventWithTags creates an event with specific tags.

func CreateParameterizedReplaceableEvent

func CreateParameterizedReplaceableEvent(signer *p8k.Signer, kindNum uint16, content string, dTag string) (ev *event.E, err error)

CreateParameterizedReplaceableEvent creates a parameterized replaceable event (kind 30000-39999).

func CreateReplaceableEvent

func CreateReplaceableEvent(signer *p8k.Signer, kindNum uint16, content string) (ev *event.E, err error)

CreateReplaceableEvent creates a replaceable event (kind 0-3, 10000-19999).

func FormatJSON

func FormatJSON(results []TestResult) (output string, err error)

FormatJSON formats results as JSON.

func HexID

func HexID(ev *event.E) string

HexID returns the hex-encoded event ID.

func MustHex

func MustHex(s string) []byte

MustHex decodes a hex string or panics.

func RandomID

func RandomID() (id []byte, err error)

RandomID generates a random 32-byte ID.

Types

type Client

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

Client wraps a WebSocket connection to a relay for testing.

func NewClient

func NewClient(url string) (c *Client, err error)

NewClient creates a new test client connected to the relay.

func (*Client) Auth

func (c *Client) Auth(ev *event.E) error

Auth sends an AUTH message with the signed event.

func (*Client) Close

func (c *Client) Close() error

Close closes the client connection.

func (*Client) Count

func (c *Client) Count(filters []interface{}) (count int64, err error)

Count sends a COUNT request and returns the count.

func (*Client) GetEvents

func (c *Client) GetEvents(subID string, filters []interface{}, timeout time.Duration) (events []*event.E, err error)

GetEvents collects all events from a subscription until EOSE.

func (*Client) Publish

func (c *Client) Publish(ev *event.E) (err error)

Publish sends an EVENT message to the relay.

func (*Client) Send

func (c *Client) Send(msg interface{}) (err error)

Send sends a JSON message to the relay.

func (*Client) Subscribe

func (c *Client) Subscribe(subID string, filters []interface{}) (ch chan []byte, err error)

Subscribe creates a subscription and returns a channel for events.

func (*Client) URL added in v0.21.1

func (c *Client) URL() string

URL returns the relay URL.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(subID string) error

Unsubscribe closes a subscription.

func (*Client) WaitForOK

func (c *Client) WaitForOK(eventID []byte, timeout time.Duration) (accepted bool, reason string, err error)

WaitForOK waits for an OK response for the given event ID.

type KeyPair

type KeyPair struct {
	Secret *p8k.Signer
	Pubkey []byte
	Nsec   string
	Npub   string
}

KeyPair represents a test keypair.

func GenerateKeyPair

func GenerateKeyPair() (kp *KeyPair, err error)

GenerateKeyPair generates a new keypair for testing.

type TestCase

type TestCase struct {
	Name         string
	Required     bool
	Func         TestFunc
	Dependencies []string // Names of tests that must run before this one
}

TestCase represents a test case with dependencies.

type TestFunc

type TestFunc func(client *Client, key1, key2 *KeyPair) (result TestResult)

TestFunc is a function that runs a test case.

type TestResult

type TestResult struct {
	Name     string `json:"test"`
	Pass     bool   `json:"pass"`
	Required bool   `json:"required"`
	Info     string `json:"info,omitempty"`
}

TestResult represents the result of a test.

type TestSuite

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

TestSuite runs all tests against a relay.

func NewTestSuite

func NewTestSuite(relayURL string) (suite *TestSuite, err error)

NewTestSuite creates a new test suite.

func (*TestSuite) AddTest

func (s *TestSuite) AddTest(tc *TestCase)

AddTest adds a test case to the suite.

func (*TestSuite) GetResults

func (s *TestSuite) GetResults() map[string]TestResult

GetResults returns all test results.

func (*TestSuite) GetTestNames added in v0.21.1

func (s *TestSuite) GetTestNames() map[string]bool

GetTestNames returns all registered test names as a map (name -> required).

func (*TestSuite) ListTests added in v0.21.1

func (s *TestSuite) ListTests() []string

ListTests returns a list of all test names in execution order.

func (*TestSuite) Run

func (s *TestSuite) Run() (results []TestResult, err error)

Run runs all tests in the suite.

func (*TestSuite) RunTest

func (s *TestSuite) RunTest(testName string) (result TestResult, err error)

RunTest runs a specific test by name.

Jump to

Keyboard shortcuts

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