Skip to content

Commit

Permalink
Rename testnet fixture to ephnet
Browse files Browse the repository at this point in the history
As per the README update, changing the name of the fixture to `ephnet`
(short for 'ephemeral network') is intended to ensure a less
unambiguous name. The original name of `testnet` was chosen in
ignorance of the common use of the term to refer to a persistent
blockchain network used for testing.

Also changed:

 - 'existing' is used instead of 'persistent' in reference to
 ephemeral networks that are started and stopped with the `ephnetctl`
 tool. Referring to an ephemeral network as 'persistent' seemed
 confusing.

 - `TESTNETCTL_*`-prefixed env vars are now prefixed with
 `EPHNET_` (minus the `CTL`) since they are used by both the ephnetctl
 cli and the ginkgo test suite.

 - The root directory for storing local networks becomes `.ephnet`
 instead of `.testnetctl`, also due to the path being shared between
 the ephnetctl cli and the ginkgo test suite.
  • Loading branch information
marun committed Nov 14, 2023
1 parent 7f70fcf commit 9b2643f
Show file tree
Hide file tree
Showing 28 changed files with 251 additions and 233 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test e2e with persistent network
name: Test e2e with existing network

on:
push:
Expand All @@ -15,7 +15,7 @@ permissions:
contents: read

jobs:
test_e2e_persistent:
test_e2e_existing:
runs-on: ubuntu-latest
steps:
- name: Git checkout
Expand All @@ -28,12 +28,12 @@ jobs:
- name: Build the avalanchego binary
shell: bash
run: ./scripts/build.sh -r
- name: Run e2e tests with persistent network
- name: Run e2e tests with existing network
shell: bash
run: E2E_SERIAL=1 ./scripts/tests.e2e.persistent.sh
- name: Upload testnet network dir
run: E2E_SERIAL=1 ./scripts/tests.e2e.existing.sh
- name: Upload ephnet network dir
uses: actions/upload-artifact@v3
if: always()
with:
name: testnet-data
path: ~/.testnetctl/networks/1000
name: ephnet-data
path: ~/.ephnet/networks/1000
6 changes: 3 additions & 3 deletions .github/workflows/test.e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ jobs:
- name: Run e2e tests
shell: bash
run: E2E_SERIAL=1 ./scripts/tests.e2e.sh
- name: Upload testnet network dir
- name: Upload ephnet network dir
uses: actions/upload-artifact@v3
if: always()
with:
name: testnet-data
path: ~/.testnetctl/networks/1000
name: ephnet-data
path: ~/.ephnet/networks/1000
8 changes: 4 additions & 4 deletions .github/workflows/test.upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ jobs:
run: ./scripts/build.sh
- name: Run upgrade tests
shell: bash
# 1.10.7 is the first version compatible with the testnet fixture by
# 1.10.7 is the first version compatible with the ephnet fixture by
# virtue of writing a process context file on node start.
run: ./scripts/tests.upgrade.sh 1.10.7
- name: Upload testnet network dir
- name: Upload ephnet network dir
uses: actions/upload-artifact@v3
if: always()
with:
name: testnet-data
path: ~/.testnetctl/networks/1000
name: ephnet-data
path: ~/.ephnet/networks/1000
6 changes: 3 additions & 3 deletions scripts/build_testnetctl.sh → scripts/build_ephnetctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
# Load the constants
source "$AVALANCHE_PATH"/scripts/constants.sh

echo "Building testnetctl..."
echo "Building ephnetctl..."
go build -ldflags\
"-X github.com/ava-labs/avalanchego/version.GitCommit=$git_commit $static_ld_flags"\
-o "$AVALANCHE_PATH/build/testnetctl"\
"$AVALANCHE_PATH/tests/fixture/testnet/cmd/"*.go
-o "$AVALANCHE_PATH/build/ephnetctl"\
"$AVALANCHE_PATH/tests/fixture/ephnet/cmd/"*.go
63 changes: 63 additions & 0 deletions scripts/tests.e2e.existing.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

set -euo pipefail

################################################################
# This script deploys an ephemeral network and configures
# tests.e2e.sh to execute the e2e suite against it. This
# validates that ephnetctl is capable of starting a network and
# that the e2e suite is capable of executing against a network
# that it did not create.
################################################################

# e.g.,
# ./scripts/build.sh
# ./scripts/tests.e2e.existing.sh --ginkgo.label-filter=x # All arguments are supplied to ginkgo
# E2E_SERIAL=1 ./scripts/tests.e2e.sh # Run tests serially
# AVALANCHEGO_PATH=./build/avalanchego ./scripts/tests.e2e.existing.sh # Customization of avalanchego path
if ! [[ "$0" =~ scripts/tests.e2e.existing.sh ]]; then
echo "must be run from repository root"
exit 255
fi

# Ensure an absolute path to avoid dependency on the working directory
# of script execution.
export AVALANCHEGO_PATH="$(realpath ${AVALANCHEGO_PATH:-./build/avalanchego})"

# Provide visual separation between testing and setup/teardown
function print_separator {
printf '%*s\n' "${COLUMNS:-80}" '' | tr ' '
}

# Ensure network cleanup on teardown
function cleanup {
print_separator
echo "cleaning up ephemeral network"
if [[ -n "${EPHNET_NETWORK_DIR:-}" ]]; then
./build/ephnetctl stop-network
fi
}
trap cleanup EXIT

# Start an ephemeral network
./scripts/build_ephnetctl.sh
print_separator
./build/ephnetctl start-network

# Determine the network configuration path from the latest symlink
LATEST_SYMLINK_PATH="${HOME}/.ephnet/networks/latest"
if [[ -h "${LATEST_SYMLINK_PATH}" ]]; then
export EPHNET_NETWORK_DIR="$(realpath ${LATEST_SYMLINK_PATH})"
else
echo "failed to find configuration path: ${LATEST_SYMLINK_PATH} symlink not found"
exit 255
fi

print_separator
# - Setting E2E_USE_EXISTING_NETWORK configures tests.e2e.sh to use
# the ephemeral network identified by EPHNET_NETWORK_DIR.
# - Only a single test (selected with --ginkgo.focus-file) is required
# to validate that an existing network can be used by an e2e test
# suite run. Executing more tests would be duplicative of the testing
# performed against a network created by the test suite.
E2E_USE_EXISTING_NETWORK=1 ./scripts/tests.e2e.sh --ginkgo.focus-file=permissionless_subnets.go
60 changes: 0 additions & 60 deletions scripts/tests.e2e.persistent.sh

This file was deleted.

12 changes: 6 additions & 6 deletions scripts/tests.e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -euo pipefail
# ./scripts/tests.e2e.sh --ginkgo.label-filter=x # All arguments are supplied to ginkgo
# E2E_SERIAL=1 ./scripts/tests.e2e.sh # Run tests serially
# AVALANCHEGO_PATH=./build/avalanchego ./scripts/tests.e2e.sh # Customization of avalanchego path
# E2E_USE_PERSISTENT_NETWORK=1 TESTNETCTL_NETWORK_DIR=/path/to ./scripts/tests.e2e.sh # Execute against a persistent network
# E2E_USE_EXISTING_NETWORK=1 EPHNET_NETWORK_DIR=/path/to ./scripts/tests.e2e.sh # Execute against an existing network
if ! [[ "$0" =~ scripts/tests.e2e.sh ]]; then
echo "must be run from repository root"
exit 255
Expand All @@ -28,11 +28,11 @@ ACK_GINKGO_RC=true ginkgo build ./tests/e2e
./tests/e2e/e2e.test --help

#################################
# Since TESTNETCTL_NETWORK_DIR may be persistently set in the environment (e.g. to configure
# ginkgo or testnetctl), configuring the use of a persistent network with this script
# requires the extra step of setting E2E_USE_PERSISTENT_NETWORK=1.
if [[ -n "${E2E_USE_PERSISTENT_NETWORK:-}" && -n "${TESTNETCTL_NETWORK_DIR:-}" ]]; then
E2E_ARGS="--use-persistent-network"
# Since EPHNET_NETWORK_DIR may be set in the environment (e.g. to configure ginkgo
# or ephnetctl), configuring the use of an existing network with this script
# requires the extra step of setting E2E_USE_EXISTING_NETWORK=1.
if [[ -n "${E2E_USE_EXISTING_NETWORK:-}" && -n "${EPHNET_NETWORK_DIR:-}" ]]; then
E2E_ARGS="--use-existing-network"
else
AVALANCHEGO_PATH="$(realpath ${AVALANCHEGO_PATH:-./build/avalanchego})"
E2E_ARGS="--avalanchego-path=${AVALANCHEGO_PATH}"
Expand Down
40 changes: 21 additions & 19 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Avalanche e2e test suites

- Works with fixture-managed networks.
- Works with fixture-managed ephemeral networks.
- Compiles to a single binary with customizable configurations.

## Running tests
Expand Down Expand Up @@ -57,44 +57,46 @@ packages. `x/transfer/virtuous.go` defines X-Chain transfer tests,
labeled with `x`, which can be selected by `./tests/e2e/e2e.test
--ginkgo.label-filter "x"`.

## Testing against a persistent network
## Testing against an existing network

By default, a new ephemeral test network will be started before each
test run. When developing e2e tests, it may be helpful to create a
persistent test network to test against. This can increase the speed
of iteration by removing the requirement to start a new network for
every invocation of the test under development.
test run and stopped at the end of the run. When developing e2e tests,
it may be helpful to create an ephemeral network that can be used
across multiple test runs. This can increase the speed of iteration by
removing the requirement to start a new network for every invocation
of the test under development.

To use a persistent network:
To create an ephemeral network for use across test runs:

```bash
# From the root of the avalanchego repo

# Build the testnetctl binary
$ ./scripts/build_testnetctl.sh
# Build the ephnetctl binary
$ ./scripts/build_ephnetctl.sh

# Start a new network
$ ./build/testnetctl start-network --avalanchego-path=/path/to/avalanchego
$ ./build/ephnetctl start-network --avalanchego-path=/path/to/avalanchego
...
Started network 1000 @ /home/me/.testnetctl/networks/1000
Started network 1000 @ /home/me/.ephnet/networks/1000

Configure testnetctl to target this network by default with one of the following statements:
- source /home/me/.testnetctl/networks/1000/network.env
- export TESTNETCTL_NETWORK_DIR=/home/me/.testnetctl/networks/1000
- export TESTNETCTL_NETWORK_DIR=/home/me/.testnetctl/networks/latest
Configure ephnetctl and the test suite to target this network by default
with one of the following statements:
- source /home/me/.ephnet/networks/1000/network.env
- export EPHNET_NETWORK_DIR=/home/me/.ephnet/networks/1000
- export EPHNET_NETWORK_DIR=/home/me/.ephnet/networks/latest

# Start a new test run using the persistent network
# Start a new test run using the existing network
ginkgo -v ./tests/e2e -- \
--avalanchego-path=/path/to/avalanchego \
--ginkgo.focus-file=[name of file containing test] \
--use-persistent-network \
--use-existing-network \
--network-dir=/path/to/network

# It is also possible to set the AVALANCHEGO_PATH env var instead of supplying --avalanchego-path
# and to set TESTNETCTL_NETWORK_DIR instead of supplying --network-dir.
# and to set EPHNET_NETWORK_DIR instead of supplying --network-dir.
```

See the testnet fixture [README](../fixture/testnet/README.md) for more details.
See the ephnet fixture [README](../fixture/ephnet/README.md) for more details.

## Skipping bootstrap checks

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/c/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/testnet"
"github.com/ava-labs/avalanchego/tests/fixture/ephnet"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
)

Expand All @@ -47,7 +47,7 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() {

ginkgo.By("initializing a coreth client")
node := privateNetwork.GetNodes()[0]
nodeURI := testnet.NodeURI{
nodeURI := ephnet.NodeURI{
NodeID: node.GetID(),
URI: node.GetProcessContext().URI,
}
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/faultinjection/duplicate_node_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/testnet"
"github.com/ava-labs/avalanchego/tests/fixture/ephnet"
"github.com/ava-labs/avalanchego/utils/set"
)

Expand All @@ -27,15 +27,15 @@ var _ = ginkgo.Describe("Duplicate node handling", func() {
nodes := network.GetNodes()

ginkgo.By("creating new node")
node1 := e2e.AddEphemeralNode(network, testnet.FlagsMap{})
node1 := e2e.AddEphemeralNode(network, ephnet.FlagsMap{})
e2e.WaitForHealthy(node1)

ginkgo.By("checking that the new node is connected to its peers")
checkConnectedPeers(nodes, node1)

ginkgo.By("creating a second new node with the same staking keypair as the first new node")
node1Flags := node1.GetConfig().Flags
node2Flags := testnet.FlagsMap{
node2Flags := ephnet.FlagsMap{
config.StakingTLSKeyContentKey: node1Flags[config.StakingTLSKeyContentKey],
config.StakingCertContentKey: node1Flags[config.StakingCertContentKey],
// Construct a unique data dir to ensure the two nodes' data will be stored
Expand All @@ -46,7 +46,7 @@ var _ = ginkgo.Describe("Duplicate node handling", func() {
node2 := e2e.AddEphemeralNode(network, node2Flags)

ginkgo.By("checking that the second new node fails to become healthy before timeout")
err := testnet.WaitForHealthy(e2e.DefaultContext(), node2)
err := ephnet.WaitForHealthy(e2e.DefaultContext(), node2)
require.ErrorIs(err, context.DeadlineExceeded)

ginkgo.By("stopping the first new node")
Expand All @@ -63,7 +63,7 @@ var _ = ginkgo.Describe("Duplicate node handling", func() {
})

// Check that a new node is connected to existing nodes and vice versa
func checkConnectedPeers(existingNodes []testnet.Node, newNode testnet.Node) {
func checkConnectedPeers(existingNodes []ephnet.Node, newNode ephnet.Node) {
require := require.New(ginkgo.GinkgoT())

// Collect the node ids of the new node's peers
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/p/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/testnet"
"github.com/ava-labs/avalanchego/tests/fixture/ephnet"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/set"
Expand All @@ -44,7 +44,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL

ginkgo.By("checking that the network has a compatible minimum stake duration", func() {
minStakeDuration := cast.ToDuration(network.GetConfig().DefaultFlags[config.MinStakeDurationKey])
require.Equal(testnet.DefaultMinStakeDuration, minStakeDuration)
require.Equal(ephnet.DefaultMinStakeDuration, minStakeDuration)
})

ginkgo.By("creating wallet with a funded key to send from and recipient key to deliver to")
Expand Down Expand Up @@ -87,7 +87,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
}

ginkgo.By("adding new node and waiting for it to report healthy")
node := e2e.AddEphemeralNode(network, testnet.FlagsMap{})
node := e2e.AddEphemeralNode(network, ephnet.FlagsMap{})
e2e.WaitForHealthy(node)

ginkgo.By("retrieving new node's id and pop")
Expand Down
Loading

0 comments on commit 9b2643f

Please sign in to comment.