testutil

package
v8.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: Apache-2.0 Imports: 15 Imported by: 26

Documentation

Overview

Package testutil includes convenience functions and types to help with testing

Index

Constants

View Source
const (
	TestSimd    = "ibc-go-simd"
	SimdVersion = "v8.5.1"
)

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

func GzipIt

func GzipIt(input []byte) ([]byte, error)

GzipIt compresses the input ([]byte).

func ModifyTomlConfigFile

func ModifyTomlConfigFile(
	ctx context.Context,
	logger *zap.Logger,
	dockerClient *client.Client,
	testName string,
	volumeName string,
	filePath string,
	modifications Toml,
) error

ModifyTomlConfigFile reads, modifies, then overwrites a toml config file, useful for config.toml, app.toml, etc.

func NodesInSync added in v8.3.0

func NodesInSync(ctx context.Context, chain ChainHeighter, nodes []ChainHeighter) error

NodesInSync returns an error if the nodes are not in sync with the chain.

func PollForAck

func PollForAck(ctx context.Context, chain ChainAcker, startHeight, maxHeight int64, packet ibc.Packet) (ibc.PacketAcknowledgement, error)

PollForAck attempts to find an acknowledgement containing a packet equal to the packet argument. Polling starts at startHeight and continues until maxHeight. It is safe to call this function even if the chain has yet to produce blocks for the target min/max height range. Polling delays until heights exist on the chain. Returns an error if acknowledgement not found or problems getting height or acknowledgements.

func PollForTimeout

func PollForTimeout(ctx context.Context, chain ChainTimeouter, startHeight, maxHeight int64, packet ibc.Packet) (ibc.PacketTimeout, error)

PollForTimeout attempts to find a timeout containing a packet equal to the packet argument. Otherwise, works identically to PollForAck.

func RecursiveModifyToml added in v8.3.0

func RecursiveModifyToml(c map[string]any, modifications Toml) error

RecursiveModifyToml will apply toml modifications at the current depth, then recurse for new depths.

func WaitForBlocks

func WaitForBlocks(ctx context.Context, delta int, chains ...ChainHeighter) error

WaitForBlocks blocks until all chains reach a block height delta equal to or greater than the delta argument. If a ChainHeighter does not monotonically increase the height, this function may block program execution indefinitely.

func WaitForBlocksUtil

func WaitForBlocksUtil(maxBlocks int, fn func(i int) error) error

WaitForBlocksUtil iterates from 0 to maxBlocks and calls fn function with the current iteration index as a parameter. If fn returns nil, the loop is terminated and the function returns nil. If fn returns an error and the loop has iterated over all maxBlocks without success, the error is returned.

func WaitForCondition

func WaitForCondition(timeoutAfter, pollingInterval time.Duration, fn func() (bool, error)) error

WaitForCondition periodically executes the given function fn based on the provided pollingInterval. The function fn should return true of the desired condition is met. If the function never returns true within the timeoutAfter period, or fn returns an error, the condition will not have been met.

func WaitForInSync

func WaitForInSync(ctx context.Context, chain ChainHeighter, nodes ...ChainHeighter) error

WaitForInSync blocks until all nodes have heights greater than or equal to the chain height.

Types

type BlockPoller

type BlockPoller[T any] struct {
	CurrentHeight func(ctx context.Context) (int64, error)
	PollFunc      func(ctx context.Context, height int64) (T, error)
}

func (BlockPoller[T]) DoPoll

func (p BlockPoller[T]) DoPoll(ctx context.Context, startHeight, maxHeight int64) (T, error)

type ChainAcker

type ChainAcker interface {
	ChainHeighter
	Acknowledgements(ctx context.Context, height int64) ([]ibc.PacketAcknowledgement, error)
}

ChainAcker is a chain that can get its acknowledgements at a specified height.

type ChainHeighter

type ChainHeighter interface {
	Height(ctx context.Context) (int64, error)
}

ChainHeighter fetches the current chain block height.

type ChainTimeouter

type ChainTimeouter interface {
	ChainHeighter
	Timeouts(ctx context.Context, height int64) ([]ibc.PacketTimeout, error)
}

ChainTimeouter is a chain that can get its timeouts at a specified height.

type Toml

type Toml map[string]any

Toml is used for holding the decoded state of a toml config file.

Jump to

Keyboard shortcuts

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