testeventsquery

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package testeventsquery provides helper functions for constructing real (e.g. localnet) and mock EventsQueryClient objects with pre-configured and/or parameterized call arguments, return value(s), and/or expectations thereof. Intended for use in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAnyTimesEventsBytesEventsQueryClient

func NewAnyTimesEventsBytesEventsQueryClient(
	ctx context.Context,
	t *testing.T,
	expectedQuery string,
	expectedEventBytes []byte,
) client.EventsQueryClient

NewAnyTimesEventsBytesEventsQueryClient returns a new events query client which is configured to return the expected event bytes when queried with the expected query, any number of times. The returned client also expects to be closed once.

func NewAnyTimesMockDailer

func NewAnyTimesMockDailer(
	t *testing.T,
	connMock *mockclient.MockConnection,
) *mockclient.MockDialer

NewAnyTimesMockDailer returns a mock dialer that will return the given connection mock when DialContext is called. The mock dialer will expect DialContext to be called any number of times.

func NewLocalnetClient

NewLocalnetClient creates and returns a new events query client that's configured for use with the LocalNet validator. Any options provided are applied to the client.

func NewNTimesReconnectConnectionMock

func NewNTimesReconnectConnectionMock(
	t *testing.T,
	n int,
	connClosed *atomic.Bool,
	delayEvent *atomic.Bool,
) *mockclient.MockConnection

NewNTimesReconnectConnectionMock returns a mock connection that will expect Close and Send to be called exactly N times. The connection mock will set the connClosed atomic to true when Close is called and false when Send is called. The connection mock will set the delayEvent atomic to false when Send is called. This is to allow the caller to subscribe to the first event emitted

func NewNTimesReconnectMockConnAndDialer

func NewNTimesReconnectMockConnAndDialer(
	t *testing.T,
	n int,
	connClosed *atomic.Bool,
	delayEvent *atomic.Bool,
) (*mockclient.MockConnection, *mockclient.MockDialer)

NewNTimesReconnectMockConnAndDialer returns a new mock connection and mock dialer that will return the mock connection when DialContext is called. The mock dialer will expect DialContext to be called any times. The connection mock will expect Close and Send to be called exactly N times.

func NewOneTimeEventsQuery

func NewOneTimeEventsQuery(
	ctx context.Context,
	t *testing.T,
	query string,
	publishChMu *sync.Mutex,
	publishCh *chan<- either.Bytes,
) *mockclient.MockEventsQueryClient

NewOneTimeEventsQuery creates a mock of the EventsQueryClient which expects a single call to the EventsBytes method. It returns a mock client whose event bytes method always constructs a new observable. query is the query string for which event bytes subscription is expected to be for. The caller can simulate blockchain events by sending on publishCh, the value of which is set to the publish channel of the events bytes observable publish channel.

func NewOneTimeMockConnAndDialer

func NewOneTimeMockConnAndDialer(t *testing.T) (
	*mockclient.MockConnection,
	*mockclient.MockDialer,
)

NewOneTimeMockConnAndDialer returns a new mock connection and mock dialer that will return the mock connection when DialContext is called. The mock dialer will expect DialContext to be called exactly once. The connection mock will expect Close to be called exactly once. Callers must mock the Receive method with an EXPECT call before the connection mock can be used.

func NewOneTimeMockDialer

func NewOneTimeMockDialer(
	t *testing.T,
	eitherConnMock either.Either[*mockclient.MockConnection],
) *mockclient.MockDialer

NewOneTimeMockDialer returns a mock dialer that will return either the given connection mock or error when DialContext is called. The mock dialer will expect DialContext to be called exactly once.

func NewOneTimeTxEventsQueryClient

func NewOneTimeTxEventsQueryClient(
	ctx context.Context,
	t *testing.T,
	key *cosmoskeyring.Record,
	publishChMu *sync.Mutex,
	publishCh *chan<- either.Bytes,
) *mockclient.MockEventsQueryClient

NewOneTimeTxEventsQueryClient creates a mock of the Events that expects to to a single call to the EventsBytes method where the query is for transaction events for sender address matching that of the given key. The caller can simulate blockchain events by sending on publishCh, the value of which is set to the publish channel of the events bytes observable publish channel.

Types

This section is empty.

Jump to

Keyboard shortcuts

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