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 ¶
- Variables
- func EntryNodeConfig() config.GoShimmer
- func PeerConfig() config.GoShimmer
- type CfgAlterFunc
- type CreateNetworkConfig
- type DockerContainer
- func (d *DockerContainer) ConnectToNetwork(ctx context.Context, networkID string) error
- func (d *DockerContainer) CreateContainer(ctx context.Context, name string, containerConfig *container.Config, ...) error
- func (d *DockerContainer) CreateNode(ctx context.Context, conf config.GoShimmer) error
- func (d *DockerContainer) CreatePumba(ctx context.Context, name string, effectedContainerName string, ...) error
- func (d *DockerContainer) DisconnectFromNetwork(ctx context.Context, networkID string) error
- func (d *DockerContainer) ExitStatus(ctx context.Context) (int, error)
- func (d *DockerContainer) IP(ctx context.Context, network string) (string, error)
- func (d *DockerContainer) Kill(ctx context.Context, signal string) error
- func (d *DockerContainer) Logs(ctx context.Context) (io.ReadCloser, error)
- func (d *DockerContainer) Remove(ctx context.Context) error
- func (d *DockerContainer) Shutdown(ctx context.Context, optionalTimeout ...time.Duration) (exitStatus int, err error)
- func (d *DockerContainer) Start(ctx context.Context) error
- func (d *DockerContainer) Stop(ctx context.Context, optionalTimeout ...time.Duration) error
- type Framework
- func (f *Framework) CreateNetwork(ctx context.Context, name string, numPeers int, conf CreateNetworkConfig, ...) (*Network, error)
- func (f *Framework) CreateNetworkNoAutomaticManualPeering(ctx context.Context, name string, numPeers int, conf CreateNetworkConfig, ...) (*Network, error)
- func (f *Framework) CreateNetworkWithPartitions(ctx context.Context, name string, numPeers, numPartitions int, ...) (*Network, error)
- type Network
- func (n *Network) CreatePartitionsManualPeering(ctx context.Context, partitions ...[]*Node) error
- func (n *Network) CreatePeer(ctx context.Context, conf config.GoShimmer) (*Node, error)
- func (n *Network) DeletePartitions(ctx context.Context) error
- func (n *Network) DoManualPeering(ctx context.Context, nodes ...*Node) error
- func (n *Network) Partitions() []*Partition
- func (n *Network) Peers() []*Node
- func (n *Network) Shutdown(ctx context.Context) error
- func (n *Network) Split(ctx context.Context, partitions ...[]*Node) error
- func (n *Network) WaitForAutopeering(ctx context.Context) error
- func (n *Network) WaitForPeerDiscovery(ctx context.Context) error
- type Node
- type Nodes
- type Partition
- type SnapshotInfo
Constants ¶
This section is empty.
Variables ¶
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 ¶
EntryNodeConfig specifies the default config of a standard GoShimmer entry node.
func PeerConfig ¶
PeerConfig specifies the default config of a standard GoShimmer peer.
Types ¶
type CfgAlterFunc ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (d *DockerContainer) Logs(ctx context.Context) (io.ReadCloser, error)
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.
type Framework ¶
type Framework struct {
// contains filtered or unexported fields
}
Framework is a wrapper that provides the integration testing functionality.
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 ¶
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 ¶
CreatePeer creates and returns a new GoShimmer peer. It blocks until this peer has started.
func (*Network) DeletePartitions ¶
DeletePartitions deletes all partitions of the network. All nodes can communicate with the full network again.
func (*Network) DoManualPeering ¶
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 ¶
Partitions returns the network's partitions.
func (*Network) Shutdown ¶
Shutdown creates logs and removes network and containers. Should always be called when a network is not needed anymore.
func (*Network) WaitForAutopeering ¶
WaitForAutopeering blocks until a fully connected network of neighbors has been found.
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.
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.
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