framework

package
v0.0.0-...-198e6eb Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: Apache-2.0, BSD-2-Clause Imports: 32 Imported by: 0

Documentation

Overview

Package framework provides integration test functionality for GoShimmer with a Docker network. It effectively abstracts away all complexity with creating a custom Docker network per test, discovering peers, waiting for them to autopeer and offers easy access to the peers' web API and logs.

Index

Constants

This section is empty.

Variables

View Source
var (
	// GenesisSeedBytes is the seed of the funds created at genesis.
	GenesisSeedBytes = []byte{
		95, 76, 224, 164, 168, 80, 141, 174, 133, 77, 153, 100, 4, 202, 113, 104,
		71, 130, 88, 200, 46, 56, 243, 121, 216, 236, 70, 146, 234, 158, 206, 230,
	}

	// GenesisTime provides the genesis time for the tests, to start close to slot 0.
	GenesisTime = time.Now().Add(-time.Minute).Unix()
)

Functions

func EntryNodeConfig

func EntryNodeConfig() config.GoShimmer

EntryNodeConfig specifies the default config of a standard GoShimmer entry node.

func PeerConfig

func PeerConfig() config.GoShimmer

PeerConfig specifies the default config of a standard GoShimmer peer.

Types

type CfgAlterFunc

type CfgAlterFunc func(peerIndex int, isPeerMaster bool, cfg config.GoShimmer) config.GoShimmer

CfgAlterFunc is a function that alters the configuration for a given peer. To identify the peer the function gets called with the peer's index and its the master peer status. It should returned an updated config for the peer.

type CreateNetworkConfig

type CreateNetworkConfig struct {
	// StartSynced specifies whether all node in the network start synced.
	StartSynced bool
	// Autopeering specifies whether autopeering or manual peering is used.
	Autopeering bool
	// Faucet specifies whether the first peer should have the faucet enabled.
	Faucet bool
	// Activity specifies whether nodes schedule activity blocks in regular intervals.
	Activity bool
	// Snapshot to be generated and rendered available for the network.
	Snapshot []options.Option[snapshotcreator.Options]
}

CreateNetworkConfig is the config for optional plugins passed through NewNetwork.

type DockerContainer

type DockerContainer struct {
	Name string
	Id   string
	// contains filtered or unexported fields
}

DockerContainer is a wrapper object for a Docker container.

func NewDockerContainer

func NewDockerContainer(c *client.Client) *DockerContainer

NewDockerContainer creates a new DockerContainer.

func NewDockerContainerFromExisting

func NewDockerContainerFromExisting(ctx context.Context, c *client.Client, name string) (*DockerContainer, error)

NewDockerContainerFromExisting creates a new DockerContainer from an already existing Docker container by name.

func (*DockerContainer) ConnectToNetwork

func (d *DockerContainer) ConnectToNetwork(ctx context.Context, networkID string) error

ConnectToNetwork connects a container to an existent network in the docker host.

func (*DockerContainer) CreateContainer

func (d *DockerContainer) CreateContainer(ctx context.Context, name string, containerConfig *container.Config, hostConfigs ...*container.HostConfig) error

CreateContainer creates a new container with the given configuration.

func (*DockerContainer) CreateNode

func (d *DockerContainer) CreateNode(ctx context.Context, conf config.GoShimmer) error

CreateNode creates a new GoShimmer container.

func (*DockerContainer) CreatePumba

func (d *DockerContainer) CreatePumba(ctx context.Context, name string, effectedContainerName string, targetIPs []string) error

CreatePumba creates a new container with Pumba configuration blocking all traffic. This blocks all traffic of effectedContainer to targetIPs.

func (*DockerContainer) DisconnectFromNetwork

func (d *DockerContainer) DisconnectFromNetwork(ctx context.Context, networkID string) error

DisconnectFromNetwork disconnects a container from an existent network in the docker host.

func (*DockerContainer) ExitStatus

func (d *DockerContainer) ExitStatus(ctx context.Context) (int, error)

ExitStatus returns the exit status according to the container information.

func (*DockerContainer) IP

func (d *DockerContainer) IP(ctx context.Context, network string) (string, error)

IP returns the IP address according to the container information for the given network.

func (*DockerContainer) Kill

func (d *DockerContainer) Kill(ctx context.Context, signal string) error

Kill sends a signal to the container

func (*DockerContainer) Logs

Logs returns the logs of the container as io.ReadCloser.

func (*DockerContainer) Remove

func (d *DockerContainer) Remove(ctx context.Context) error

Remove kills and removes a container from the docker host.

func (*DockerContainer) Shutdown

func (d *DockerContainer) Shutdown(ctx context.Context, optionalTimeout ...time.Duration) (exitStatus int, err error)

Shutdown stops the container and stores its log. It returns the exit status of the process.

func (*DockerContainer) Start

func (d *DockerContainer) Start(ctx context.Context) error

Start sends a request to the docker daemon to start a container.

func (*DockerContainer) Stop

func (d *DockerContainer) Stop(ctx context.Context, optionalTimeout ...time.Duration) error

Stop stops the container without terminating the process. The process is blocked until the container stops or the timeout expires.

type Framework

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

Framework is a wrapper that provides the integration testing functionality.

func Instance

func Instance() (f *Framework, err error)

Instance returns the singleton Framework instance.

func (*Framework) CreateNetwork

func (f *Framework) CreateNetwork(ctx context.Context, name string, numPeers int, conf CreateNetworkConfig, cfgAlterFunc ...CfgAlterFunc) (*Network, error)

CreateNetwork creates and returns a network that contains numPeers GoShimmer peers. It blocks until all peers are connected.

func (*Framework) CreateNetworkNoAutomaticManualPeering

func (f *Framework) CreateNetworkNoAutomaticManualPeering(ctx context.Context, name string, numPeers int, conf CreateNetworkConfig, cfgAlterFunc ...CfgAlterFunc) (*Network, error)

func (*Framework) CreateNetworkWithPartitions

func (f *Framework) CreateNetworkWithPartitions(ctx context.Context, name string, numPeers, numPartitions int, conf CreateNetworkConfig, cfgAlterFunc ...CfgAlterFunc) (*Network, error)

CreateNetworkWithPartitions creates and returns a network that contains numPeers GoShimmer nodes distributed over numPartitions partitions. It blocks until all peers are connected.

type Network

type Network struct {
	Id string
	// contains filtered or unexported fields
}

Network represents a complete GoShimmer network within Docker. Including an entry node and arbitrary many peers.

func NewNetwork

func NewNetwork(ctx context.Context, dockerClient *client.Client, name string, tester *DockerContainer) (*Network, error)

NewNetwork returns a Network instance, creates its underlying Docker network and adds the tester container to the network.

func (*Network) CreatePartitionsManualPeering

func (n *Network) CreatePartitionsManualPeering(ctx context.Context, partitions ...[]*Node) error

CreatePartitionsManualPeering creates a partitioned network topology between nodes using manual peering. If the optional list of partitioned nodes is not provided an error is returned. CreatePartitionsManualPeering blocks until all connections are established or the ctx has expired.

func (*Network) CreatePeer

func (n *Network) CreatePeer(ctx context.Context, conf config.GoShimmer) (*Node, error)

CreatePeer creates and returns a new GoShimmer peer. It blocks until this peer has started.

func (*Network) DeletePartitions

func (n *Network) DeletePartitions(ctx context.Context) error

DeletePartitions deletes all partitions of the network. All nodes can communicate with the full network again.

func (*Network) DoManualPeering

func (n *Network) DoManualPeering(ctx context.Context, nodes ...*Node) error

DoManualPeering creates a complete network topology between nodes using manual peering. If the optional list of nodes is not provided all network peers are used. DoManualPeering blocks until all connections are established or the ctx has expired.

func (*Network) Partitions

func (n *Network) Partitions() []*Partition

Partitions returns the network's partitions.

func (*Network) Peers

func (n *Network) Peers() []*Node

Peers returns all available peers in the network.

func (*Network) Shutdown

func (n *Network) Shutdown(ctx context.Context) error

Shutdown creates logs and removes network and containers. Should always be called when a network is not needed anymore.

func (*Network) Split

func (n *Network) Split(ctx context.Context, partitions ...[]*Node) error

Split splits the existing network in given partitions.

func (*Network) WaitForAutopeering

func (n *Network) WaitForAutopeering(ctx context.Context) error

WaitForAutopeering blocks until a fully connected network of neighbors has been found.

func (*Network) WaitForPeerDiscovery

func (n *Network) WaitForPeerDiscovery(ctx context.Context) error

WaitForPeerDiscovery waits until all peers have discovered each other.

type Node

type Node struct {

	// GoShimmer identity
	*identity.Identity

	// Web API of this peer
	*client.GoShimmerAPI

	// the DockerContainer that this peer is running in
	*DockerContainer

	// the seed of the node's wallet
	*walletseed.Seed
	// contains filtered or unexported fields
}

Node represents a GoShimmer node inside the Docker network

func NewNode

func NewNode(conf config.GoShimmer, id *identity.Identity, dockerContainer *DockerContainer, seed *walletseed.Seed) *Node

NewNode creates a new instance of Node with the given information. dockerContainer needs to be started in order to determine the container's (and therefore peer's) IP correctly.

func (*Node) Address

func (n *Node) Address(idx int) devnetvm.Address

Address returns the idx-th address of the wallet corresponding to the node.

func (*Node) Config

func (n *Node) Config() config.GoShimmer

Config returns the configuration of the node.

func (*Node) IsRunning

func (n *Node) IsRunning() (bool, error)

IsRunning returns true is the node is running.

func (*Node) Name

func (n *Node) Name() string

Name returns the name of the node.

func (*Node) Restart

func (n *Node) Restart(ctx context.Context) error

Restart restarts the node and blocks until it is running.

func (*Node) Start

func (n *Node) Start(ctx context.Context) error

Start starts the node and blocks until it is running.

func (*Node) String

func (n *Node) String() string

type Nodes

type Nodes = []*Node

Nodes is a slice of Node(s).

type Partition

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

Partition represents a network partition. It contains its peers and the corresponding Pumba instances that block all traffic to peers in other partitions.

func (*Partition) PeerIDs

func (p *Partition) PeerIDs() []string

PeerIDs returns the IDs of the peers in the partition

func (*Partition) Peers

func (p *Partition) Peers() []*Node

Peers returns the peers in the partition.

type SnapshotInfo

type SnapshotInfo struct {
	// FilePath defines the file path of the snapshot, if specified, the snapshot will not be generated.
	FilePath string
	// MasterSeed is the seed of the PeerMaster node where the genesis pledge goes to.
	MasterSeed string
	// GenesisTokenAmount is the amount of tokens left on the Genesis, pledged to Peer Master.
	GenesisTokenAmount uint64
	// PeerSeedBase58 is a slice of Seeds encoded in Base58, one entry per peer.
	PeersSeedBase58 []string
	// PeersAmountsPledges is a slice of amounts to be pledged to the peers, one entry per peer.
	PeersAmountsPledged []uint64
}

SnapshotInfo stores the details about snapshots created for integration tests

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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