Documentation ¶
Overview ¶
Package framework provides integration test functionality for Hornet 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
- Variables
- func ShutdownNetwork(t *testing.T, n Shutdowner)
- type AutopeeredNetwork
- func (n *AutopeeredNetwork) AwaitPeering(minimumNeighbors int) error
- func (n *AutopeeredNetwork) CreatePeer(cfg *NodeConfig) (*Node, error)
- func (n *AutopeeredNetwork) DeletePartitions() error
- func (n *AutopeeredNetwork) Partitions() []*Partition
- func (n *AutopeeredNetwork) Shutdown() error
- func (n *AutopeeredNetwork) Split(partitions ...[]*Node) error
- type CfgOverrideFunc
- type CoordinatorConfig
- type DashboardConfig
- type DockerContainer
- func (d *DockerContainer) ConnectToNetwork(networkID string) error
- func (d *DockerContainer) CreateContainer(name string, containerConfig *container.Config, ...) error
- func (d *DockerContainer) CreateNodeContainer(cfg *NodeConfig) error
- func (d *DockerContainer) CreatePumbaContainer(name string, containerName string, targetIPs []string) error
- func (d *DockerContainer) DisconnectFromNetwork(networkID string) error
- func (d *DockerContainer) ExitStatus() (int, error)
- func (d *DockerContainer) IP(network string) (string, error)
- func (d *DockerContainer) Logs() (io.ReadCloser, error)
- func (d *DockerContainer) Remove() error
- func (d *DockerContainer) Start() error
- func (d *DockerContainer) Stop(optionalTimeout ...time.Duration) error
- type Framework
- func (f *Framework) CreateAutopeeredNetwork(name string, peerCount int, minimumNeighbors int, ...) (*AutopeeredNetwork, error)
- func (f *Framework) CreateNetworkWithPartitions(name string, peerCount, partitions, minimumNeighbors int, ...) (*AutopeeredNetwork, error)
- func (f *Framework) CreateStaticNetwork(name string, layout StaticPeeringLayout, cfgOverrideF ...CfgOverrideFunc) (*StaticNetwork, error)
- type Network
- func (n *Network) AwaitAllSync(ctx context.Context) error
- func (n *Network) AwaitOnline(ctx context.Context) error
- func (n *Network) Coordinator() *Node
- func (n *Network) CreateNode(cfg *NodeConfig) (*Node, error)
- func (n *Network) PrefixName(suffix string) string
- func (n *Network) RandomNode() *Node
- func (n *Network) Shutdown() error
- func (n *Network) SpamZeroVal(dur time.Duration, parallelism int, batchSize ...int) error
- func (n *Network) TakeCPUProfiles(dur time.Duration) error
- func (n *Network) TakeHeapSnapshots() error
- type NetworkConfig
- type NetworkType
- type Node
- type NodeConfig
- type Partition
- type PluginConfig
- type Profiler
- type ProfilingConfig
- type Shutdowner
- type SnapshotConfig
- type StaticNetwork
- type StaticPeeringLayout
- type WebAPI
- type WebAPIConfig
Constants ¶
const ( // The seed of the genesis wallet. GenesisSeed = "BCPCHOJNIRZDMNDFSEEBIBGFQRGZL9PRXJQBSGHQAKCTYXBSDQEQIJ9STDFHFKMVSAZOHKSVIUBSZYBUC" // The first address of the genesis wallet. GenesisAddress = "9QJKPJPYTNPF9AFCLGLMAGXOR9ZIPYTRISKOGJPM9ZKKDXGRXWFJZMQTETDJJOGYEVRMLAOECBPWTUZ9B" // The default web API port of every node. WebAPIPort = 14265 )
Variables ¶
var ( // ErrBadRequest defines the "bad request" error. ErrBadRequest = errors.New("bad request") // ErrInternalServerError defines the "internal server error" error. ErrInternalServerError = errors.New("internal server error") // ErrNotFound defines the "not found" error. ErrNotFound = errors.New("not found") ErrUnauthorized = errors.New("unauthorized") // ErrUnknownError defines the "unknown error" error. ErrUnknownError = errors.New("unknown error") // ErrNotImplemented defines the "operation not implemented/supported/available" error. ErrNotImplemented = errors.New("operation not implemented/supported/available") )
var ( ErrNodeMissingInLayout = errors.New("node is missing in layout") ErrSelfPeering = errors.New("a node can not peer to itself") ErrNoStaticPeers = errors.New("nodes must have static nodes") ErrLayoutEmpty = errors.New("layout must not be empty") ErrNodesDidNotPeerInTime = errors.New("nodes did not peer in time") ErrNodesDidNotSyncInTime = errors.New("nodes did not sync in time") ErrNodesNotOnlineInTime = errors.New("nodes did not become online in time") )
Functions ¶
func ShutdownNetwork ¶
func ShutdownNetwork(t *testing.T, n Shutdowner)
ShutdownNetwork shuts down the network and reports errors.
Types ¶
type AutopeeredNetwork ¶
type AutopeeredNetwork struct { *Network // contains filtered or unexported fields }
AutopeeredNetwork is a network consisting out of autopeered nodes. It contains additionally an entry node.
func (*AutopeeredNetwork) AwaitPeering ¶
func (n *AutopeeredNetwork) AwaitPeering(minimumNeighbors int) error
AwaitPeering waits until all peers have reached the minimum amount of neighbors. Returns error if this minimum is not reached after autopeeringMaxTries.
func (*AutopeeredNetwork) CreatePeer ¶
func (n *AutopeeredNetwork) CreatePeer(cfg *NodeConfig) (*Node, error)
CreatePeer creates a new Hornet node initialized with the right entry node.
func (*AutopeeredNetwork) DeletePartitions ¶
func (n *AutopeeredNetwork) DeletePartitions() error
DeletePartitions deletes all partitions of the network. All nodes can communicate with the full network again.
func (*AutopeeredNetwork) Partitions ¶
func (n *AutopeeredNetwork) Partitions() []*Partition
Partitions returns the network's partitions.
func (*AutopeeredNetwork) Shutdown ¶
func (n *AutopeeredNetwork) Shutdown() error
Shutdown shuts down the network.
func (*AutopeeredNetwork) Split ¶
func (n *AutopeeredNetwork) Split(partitions ...[]*Node) error
Split splits the existing network in given partitions.
type CfgOverrideFunc ¶
type CfgOverrideFunc func(index int, cfg *NodeConfig)
CfgOverrideFunc is a function which overrides configuration values.
type CoordinatorConfig ¶
type CoordinatorConfig struct { // Whether to let the node run as the coordinator. RunAsCoo bool // Whether to run the coordinator in bootstrap node. Bootstrap bool // The coo Merkle root address. Address string // The coo seed. Seed string // The MWM/PoW difficulty to use. MWM int // The security level used for milestones. SecurityLevel int // The interval in which to issue new milestones. IssuanceIntervalSeconds int // The depth of the coo merkle tree. MerkleTreeDepth int // The path to the Merkle tree file. MerkleTreeFilePath string }
CoordinatorConfig defines coordinator specific configuration.
func DefaultCoordinatorConfig ¶
func DefaultCoordinatorConfig() CoordinatorConfig
DefaultCoordinatorConfig returns the default coordinator config.
func (*CoordinatorConfig) CLIFlags ¶
func (cooConfig *CoordinatorConfig) CLIFlags() []string
CLIFlags returns the config as CLI flags.
type DashboardConfig ¶
type DashboardConfig struct { // The bind address of the dashboard BindAddress string }
DashboardConfig holds the dashboard specific configuration.
func DefaultDashboardConfig ¶
func DefaultDashboardConfig() DashboardConfig
DefaultDashboardConfig returns the default profiling config.
func (*DashboardConfig) CLIFlags ¶
func (dashboardConfig *DashboardConfig) CLIFlags() []string
CLIFlags returns the config as CLI flags.
type DockerContainer ¶
type DockerContainer struct {
// 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(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(networkID string) error
ConnectToNetwork connects a container to an existent network in the docker host.
func (*DockerContainer) CreateContainer ¶
func (d *DockerContainer) CreateContainer(name string, containerConfig *container.Config, hostConfigs ...*container.HostConfig) error
CreateContainer creates a new container with the given configuration.
func (*DockerContainer) CreateNodeContainer ¶
func (d *DockerContainer) CreateNodeContainer(cfg *NodeConfig) error
CreateNodeContainer creates a new node container.
func (*DockerContainer) CreatePumbaContainer ¶
func (d *DockerContainer) CreatePumbaContainer(name string, containerName string, targetIPs []string) error
CreatePumbaContainer creates a new container with Pumba configuration.
func (*DockerContainer) DisconnectFromNetwork ¶
func (d *DockerContainer) DisconnectFromNetwork(networkID string) error
DisconnectFromNetwork disconnects a container from an existent network in the docker host.
func (*DockerContainer) ExitStatus ¶
func (d *DockerContainer) ExitStatus() (int, error)
ExitStatus returns the exit status according to the container information.
func (*DockerContainer) IP ¶
func (d *DockerContainer) IP(network string) (string, error)
IP returns the IP address according to the container information for the given network.
func (*DockerContainer) Logs ¶
func (d *DockerContainer) Logs() (io.ReadCloser, error)
Logs returns the logs of the container as io.ReadCloser.
func (*DockerContainer) Remove ¶
func (d *DockerContainer) Remove() error
Remove kills and removes a container from the docker host.
func (*DockerContainer) Start ¶
func (d *DockerContainer) Start() error
Start sends a request to the docker daemon to start a container.
type Framework ¶
type Framework struct {
// contains filtered or unexported fields
}
Framework is a wrapper that provides the integration testing functionality.
func (*Framework) CreateAutopeeredNetwork ¶
func (f *Framework) CreateAutopeeredNetwork(name string, peerCount int, minimumNeighbors int, cfgOverrideF ...CfgOverrideFunc) (*AutopeeredNetwork, error)
CreateAutopeeredNetwork creates a network consisting out of peersCount nodes. It waits for the nodes to autopeer until the minimum neighbors criteria is met for every node.
func (*Framework) CreateNetworkWithPartitions ¶
func (f *Framework) CreateNetworkWithPartitions(name string, peerCount, partitions, minimumNeighbors int, cfgOverrideF ...CfgOverrideFunc) (*AutopeeredNetwork, error)
CreateNetworkWithPartitions creates a network consisting out of partitions that contain peerCount nodes per partition. It waits for the peers to autopeer until the minimum neighbors criteria is met for every peer. The entry node is reachable by all nodes at all times.
func (*Framework) CreateStaticNetwork ¶
func (f *Framework) CreateStaticNetwork(name string, layout StaticPeeringLayout, cfgOverrideF ...CfgOverrideFunc) (*StaticNetwork, error)
CreateStaticNetwork creates a network made out of statically peered nodes by the given layout. The first node is initialized with the Coordinator plugin enabled.
type Network ¶
type Network struct { // The ID of the network. ID string // the type of the network. NetworkType NetworkType // The name of the network. Name string // The nodes within the network in the order in which they were spawned. Nodes []*Node // contains filtered or unexported fields }
Network is a network consisting out of Hornet nodes.
func (*Network) AwaitAllSync ¶
AwaitAllSync awaits until all nodes see themselves as synced.
func (*Network) AwaitOnline ¶
AwaitOnline awaits until all nodes are online or the given context is canceled.
func (*Network) Coordinator ¶
Coordinator returns the node with the coordinator plugin enabled.
func (*Network) CreateNode ¶
func (n *Network) CreateNode(cfg *NodeConfig) (*Node, error)
CreateNode creates a new Hornet node in the network and returns it.
func (*Network) PrefixName ¶
PrefixName returns the suffix prefixed with the name.
func (*Network) RandomNode ¶
RandomNode returns a random peer out of the list of peers.
func (*Network) Shutdown ¶
Shutdown stops all nodes, persists their container logs and removes them from Docker.
func (*Network) SpamZeroVal ¶
SpamZeroVal starts spamming zero value transactions on all nodes for the given duration.
func (*Network) TakeCPUProfiles ¶
TakeCPUProfile takes a CPU profile on all nodes within the network.
func (*Network) TakeHeapSnapshots ¶
TakeHeapSnapshot takes a heap snapshot on all nodes within the network.
type NetworkConfig ¶
type NetworkConfig struct { // The seed for the autopeering identity. AutopeeringSeed string // The list of entry nodes. EntryNodes []string // Whether to run the node as entry node. RunAsEntryNode bool // The static peers for this node. StaticPeers []string // Whether to accept any connection. AcceptAnyConnection bool // Max. amount of connected peers via AcceptAnyConnection. MaxPeers int }
NetworkConfig defines the network specific configuration.
func DefaultNetworkConfig ¶
func DefaultNetworkConfig() NetworkConfig
DefaultNetworkConfig returns the default network config.
func (*NetworkConfig) CLIFlags ¶
func (netConfig *NetworkConfig) CLIFlags() []string
CLIFlags returns the config as CLI flags.
type NetworkType ¶
type NetworkType byte
const ( // Defines a network which consists out of autopeered nodes. NetworkTypeAutopeered NetworkType = iota // Defines a network which consists out of statically peered nodes. NetworkTypeStatic )
type Node ¶
type Node struct { // Name of the node derived from the container and hostname. Name string // the IP address of this node within the network. IP string // The configuration with which the node was started. Config *NodeConfig // The autopeering identity of the peer. *identity.Identity // The iota.go web API instance used to communicate with the node. WebAPI *api.API // The more specific web API providing more information for debugging purposes. DebugWebAPI *WebAPI // The profiler instance. Profiler // The DockerContainer that this peer is running in *DockerContainer // contains filtered or unexported fields }
Node represents a Hornet node inside the Docker network.
func (*Node) SetNeighbors ¶
SetNeighbors sets the neighbors of the peer accordingly.
func (*Node) Spam ¶
Spam spams zero value transactions on the node. Returns the number of spammed transactions.
func (*Node) TotalNeighbors ¶
TotalNeighbors returns the total number of neighbors the peer has.
type NodeConfig ¶
type NodeConfig struct { // The name of this node. Name string // Environment variables. Envs []string // Binds for the container. Binds []string // Exposed ports of this container. ExposedPorts nat.PortSet // Network config. Network NetworkConfig // Web API config. WebAPI WebAPIConfig // Snapshot config. Snapshot SnapshotConfig // Coordinator config. Coordinator CoordinatorConfig // Plugin config. Plugins PluginConfig // Profiling config. Profiling ProfilingConfig // Dashboard config. Dashboard DashboardConfig }
NodeConfig defines the config of a Hornet node.
func (*NodeConfig) AsCoo ¶
func (cfg *NodeConfig) AsCoo()
AsCoo adjusts the config to make it usable as the Coordinator's config.
func (*NodeConfig) CLIFlags ¶
func (cfg *NodeConfig) CLIFlags() []string
CLIFlags returns the config as CLI flags.
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 PluginConfig ¶
type PluginConfig struct { // Holds explicitly enabled plugins. Enabled []string // Holds explicitly disabled plugins. Disabled []string }
PluginConfig defines plugin specific configuration.
func DefaultPluginConfig ¶
func DefaultPluginConfig() PluginConfig
DefaultPluginConfig returns the default plugin config.
func (*PluginConfig) CLIFlags ¶
func (pluginConfig *PluginConfig) CLIFlags() []string
CLIFlags returns the config as CLI flags.
type Profiler ¶
Profiler profiles a node for metrics.
func (*Profiler) GraphMetrics ¶
GraphMetrics graphs metrics about TPS, memory consumption, confirmation rate of the node and saves it into the log dir.
func (*Profiler) TakeCPUProfile ¶
TakeCPUProfile takes a CPU profile for the given duration and then saves it to the log directory.
func (*Profiler) TakeHeapSnapshot ¶
TakeHeapSnapshot takes a snapshot of the heap memory and then saves it to the log directory.
type ProfilingConfig ¶
type ProfilingConfig struct { // The bind address of the pprof server. BindAddress string }
ProfilingConfig defines the profiling specific configuration.
func DefaultProfilingConfig ¶
func DefaultProfilingConfig() ProfilingConfig
DefaultProfilingConfig returns the default profiling config.
func (*ProfilingConfig) CLIFlags ¶
func (profilingConfig *ProfilingConfig) CLIFlags() []string
CLIFlags returns the config as CLI flags.
type SnapshotConfig ¶
type SnapshotConfig struct { // The load type of the snapshot. LoadType string // The path to the global snapshot file. GlobalSnapshotFilePath string // The index of the global snapshot. GlobalSnapshotIndex int // The path to the local snapshot file. LocalSnapshotFilePath string // The file paths to the epoch spent address files. EpochSpentAddressesFilePath []string }
SnapshotConfig defines snapshot specific configuration.
func DefaultSnapshotConfig ¶
func DefaultSnapshotConfig() SnapshotConfig
DefaultSnapshotConfig returns the default snapshot config.
func (*SnapshotConfig) CLIFlags ¶
func (snapshotConfig *SnapshotConfig) CLIFlags() []string
CLIFlags returns the config as CLI flags.
type StaticNetwork ¶
type StaticNetwork struct { *Network // contains filtered or unexported fields }
StaticNetwork defines a network made out of statically peered nodes.
func (*StaticNetwork) AwaitPeering ¶
func (n *StaticNetwork) AwaitPeering(ctx context.Context) error
AwaitPeering awaits until all nodes are peered according to the peering layout.
func (*StaticNetwork) ConnectNodes ¶
func (n *StaticNetwork) ConnectNodes() error
ConnectNodes peers the nodes of the network according to the given layout with each other.
type StaticPeeringLayout ¶
StaticPeeringLayout defines how in a statically peered network nodes are peered to each other.
var DefaultStaticPeeringLayout StaticPeeringLayout = map[int]map[int]connected{ 0: {1: false, 2: false, 3: false}, 1: {0: false, 2: false, 3: false}, 2: {0: false, 1: false, 3: false}, 3: {0: false, 1: false, 2: false}, }
DefaultStaticPeeringLayout defines a static peering layout with 4 nodes which are all statically peered to each other.
func (StaticPeeringLayout) Validate ¶
func (spl StaticPeeringLayout) Validate() error
Validate validates whether the static peering layout is valid by checking:
- the layout isn't empty
- keys must be continuous numbers reflecting the ID of the node
- a node must hold nodes to peer to and they must exist in the map
- a node doesn't peer to itself
type WebAPI ¶
type WebAPI struct {
// contains filtered or unexported fields
}
WebAPI is an API wrapper over the web API.
type WebAPIConfig ¶
type WebAPIConfig struct { // The bind address for the web API. BindAddress string // Explicit permitted API calls. PermittedAPICalls []string }
WebAPIConfig defines the web API specific configuration.
func DefaultWebAPIConfig ¶
func DefaultWebAPIConfig() WebAPIConfig
DefaultWebAPIConfig returns the default web API config.
func (*WebAPIConfig) CLIFlags ¶
func (webAPIConfig *WebAPIConfig) CLIFlags() []string
CLIFlags returns the config as CLI flags.