From 0a28ac2bfabc8c0bcd1ef55d3a56970f24ed66fc Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Tue, 14 Nov 2023 17:53:29 +0100 Subject: [PATCH 1/2] Rename `testnet` fixture to `ephnet` 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. --- ...e.persistent.yml => test.e2e.existing.yml} | 14 ++--- .github/workflows/test.e2e.yml | 6 +- .github/workflows/test.upgrade.yml | 8 +-- ...build_testnetctl.sh => build_ephnetctl.sh} | 6 +- scripts/tests.e2e.existing.sh | 63 +++++++++++++++++++ scripts/tests.e2e.persistent.sh | 60 ------------------ scripts/tests.e2e.sh | 12 ++-- tests/e2e/README.md | 40 ++++++------ tests/e2e/c/dynamic_fees.go | 4 +- tests/e2e/faultinjection/duplicate_node_id.go | 10 +-- tests/e2e/p/interchain_workflow.go | 6 +- tests/e2e/p/staking_rewards.go | 8 +-- tests/e2e/p/workflow.go | 2 +- tests/fixture/e2e/env.go | 21 +++---- tests/fixture/e2e/flags.go | 35 ++++++----- tests/fixture/e2e/helpers.go | 22 +++---- tests/fixture/ephnet/README.md | 20 ++++++ tests/fixture/{testnet => ephnet}/cmd/main.go | 16 ++--- tests/fixture/{testnet => ephnet}/common.go | 2 +- tests/fixture/{testnet => ephnet}/config.go | 2 +- .../fixture/{testnet => ephnet}/interfaces.go | 2 +- .../{testnet => ephnet}/local/README.md | 44 ++++++------- .../{testnet => ephnet}/local/config.go | 16 ++--- .../{testnet => ephnet}/local/network.go | 36 +++++------ .../{testnet => ephnet}/local/network_test.go | 0 .../fixture/{testnet => ephnet}/local/node.go | 22 +++---- .../{testnet => ephnet}/local/node_test.go | 0 tests/fixture/testnet/README.md | 8 --- 28 files changed, 252 insertions(+), 233 deletions(-) rename .github/workflows/{test.e2e.persistent.yml => test.e2e.existing.yml} (67%) rename scripts/{build_testnetctl.sh => build_ephnetctl.sh} (71%) create mode 100755 scripts/tests.e2e.existing.sh delete mode 100755 scripts/tests.e2e.persistent.sh create mode 100644 tests/fixture/ephnet/README.md rename tests/fixture/{testnet => ephnet}/cmd/main.go (86%) rename tests/fixture/{testnet => ephnet}/common.go (98%) rename tests/fixture/{testnet => ephnet}/config.go (99%) rename tests/fixture/{testnet => ephnet}/interfaces.go (97%) rename tests/fixture/{testnet => ephnet}/local/README.md (86%) rename tests/fixture/{testnet => ephnet}/local/config.go (79%) rename tests/fixture/{testnet => ephnet}/local/network.go (95%) rename tests/fixture/{testnet => ephnet}/local/network_test.go (100%) rename tests/fixture/{testnet => ephnet}/local/node.go (95%) rename tests/fixture/{testnet => ephnet}/local/node_test.go (100%) delete mode 100644 tests/fixture/testnet/README.md diff --git a/.github/workflows/test.e2e.persistent.yml b/.github/workflows/test.e2e.existing.yml similarity index 67% rename from .github/workflows/test.e2e.persistent.yml rename to .github/workflows/test.e2e.existing.yml index d3448904d4c5..7b0cdeb0787d 100644 --- a/.github/workflows/test.e2e.persistent.yml +++ b/.github/workflows/test.e2e.existing.yml @@ -1,4 +1,4 @@ -name: Test e2e with persistent network +name: Test e2e with existing network on: push: @@ -15,7 +15,7 @@ permissions: contents: read jobs: - test_e2e_persistent: + test_e2e_existing: runs-on: ubuntu-latest steps: - name: Git checkout @@ -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 diff --git a/.github/workflows/test.e2e.yml b/.github/workflows/test.e2e.yml index 4e7c70ad8a11..3597dceaac02 100644 --- a/.github/workflows/test.e2e.yml +++ b/.github/workflows/test.e2e.yml @@ -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 diff --git a/.github/workflows/test.upgrade.yml b/.github/workflows/test.upgrade.yml index e564a51f5630..61be20787900 100644 --- a/.github/workflows/test.upgrade.yml +++ b/.github/workflows/test.upgrade.yml @@ -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 diff --git a/scripts/build_testnetctl.sh b/scripts/build_ephnetctl.sh similarity index 71% rename from scripts/build_testnetctl.sh rename to scripts/build_ephnetctl.sh index b84c9e40577d..2fd3026c70d3 100755 --- a/scripts/build_testnetctl.sh +++ b/scripts/build_ephnetctl.sh @@ -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 diff --git a/scripts/tests.e2e.existing.sh b/scripts/tests.e2e.existing.sh new file mode 100755 index 000000000000..ed4b3c999769 --- /dev/null +++ b/scripts/tests.e2e.existing.sh @@ -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 diff --git a/scripts/tests.e2e.persistent.sh b/scripts/tests.e2e.persistent.sh deleted file mode 100755 index fec3b3db0f88..000000000000 --- a/scripts/tests.e2e.persistent.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -################################################################ -# This script deploys a persistent local network and configures -# tests.e2e.sh to execute the e2e suite against it. -################################################################ - -# e.g., -# ./scripts/build.sh -# ./scripts/tests.e2e.persistent.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.persistent.sh # Customization of avalanchego path -if ! [[ "$0" =~ scripts/tests.e2e.persistent.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 persistent network" - if [[ -n "${TESTNETCTL_NETWORK_DIR:-}" ]]; then - ./build/testnetctl stop-network - fi -} -trap cleanup EXIT - -# Start a persistent network -./scripts/build_testnetctl.sh -print_separator -./build/testnetctl start-network - -# Determine the network configuration path from the latest symlink -LATEST_SYMLINK_PATH="${HOME}/.testnetctl/networks/latest" -if [[ -h "${LATEST_SYMLINK_PATH}" ]]; then - export TESTNETCTL_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_PERSISTENT_NETWORK configures tests.e2e.sh to use -# the persistent network identified by TESTNETCTL_NETWORK_DIR. -# - Only a single test (selected with --ginkgo.focus-file) is required -# to validate that a persistent network can be used by an e2e test -# suite run. Executing more tests would be duplicative of the testing -# performed against an ephemeral test network. -E2E_USE_PERSISTENT_NETWORK=1 ./scripts/tests.e2e.sh --ginkgo.focus-file=permissionless_subnets.go diff --git a/scripts/tests.e2e.sh b/scripts/tests.e2e.sh index c9acd924ae20..b81b3e22a66b 100755 --- a/scripts/tests.e2e.sh +++ b/scripts/tests.e2e.sh @@ -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 @@ -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}" diff --git a/tests/e2e/README.md b/tests/e2e/README.md index da7ca7a82612..913782260a61 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -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 @@ -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 diff --git a/tests/e2e/c/dynamic_fees.go b/tests/e2e/c/dynamic_fees.go index 8f15b6d43caf..28f86ebdc759 100644 --- a/tests/e2e/c/dynamic_fees.go +++ b/tests/e2e/c/dynamic_fees.go @@ -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" ) @@ -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, } diff --git a/tests/e2e/faultinjection/duplicate_node_id.go b/tests/e2e/faultinjection/duplicate_node_id.go index 1d865d840f51..e3b80c4a77d1 100644 --- a/tests/e2e/faultinjection/duplicate_node_id.go +++ b/tests/e2e/faultinjection/duplicate_node_id.go @@ -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" ) @@ -27,7 +27,7 @@ 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") @@ -35,7 +35,7 @@ var _ = ginkgo.Describe("Duplicate node handling", func() { 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 @@ -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") @@ -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 diff --git a/tests/e2e/p/interchain_workflow.go b/tests/e2e/p/interchain_workflow.go index 44a6912715ef..2210cced062f 100644 --- a/tests/e2e/p/interchain_workflow.go +++ b/tests/e2e/p/interchain_workflow.go @@ -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" @@ -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") @@ -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") diff --git a/tests/e2e/p/staking_rewards.go b/tests/e2e/p/staking_rewards.go index 41a77985729b..c03806a0983d 100644 --- a/tests/e2e/p/staking_rewards.go +++ b/tests/e2e/p/staking_rewards.go @@ -20,7 +20,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "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/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/units" @@ -43,13 +43,13 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() { 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("adding alpha node, whose uptime should result in a staking reward") - alphaNode := e2e.AddEphemeralNode(network, testnet.FlagsMap{}) + alphaNode := e2e.AddEphemeralNode(network, ephnet.FlagsMap{}) ginkgo.By("adding beta node, whose uptime should not result in a staking reward") - betaNode := e2e.AddEphemeralNode(network, testnet.FlagsMap{}) + betaNode := e2e.AddEphemeralNode(network, ephnet.FlagsMap{}) // Wait to check health until both nodes have started to minimize the duration // required for both nodes to report healthy. diff --git a/tests/e2e/p/workflow.go b/tests/e2e/p/workflow.go index 3f0440ac49b6..8cc7c109d3a4 100644 --- a/tests/e2e/p/workflow.go +++ b/tests/e2e/p/workflow.go @@ -73,7 +73,7 @@ var _ = e2e.DescribePChain("[Workflow]", func() { vdrStartTime := time.Now().Add(validatorStartTimeDiff) // Use a random node ID to ensure that repeated test runs - // will succeed against a persistent network. + // will succeed against a network that persists across runs. validatorID, err := ids.ToNodeID(utils.RandomBytes(ids.NodeIDLen)) require.NoError(err) diff --git a/tests/fixture/e2e/env.go b/tests/fixture/e2e/env.go index 54a4676482e1..5406377f186a 100644 --- a/tests/fixture/e2e/env.go +++ b/tests/fixture/e2e/env.go @@ -16,8 +16,8 @@ import ( "github.com/ava-labs/avalanchego/tests" "github.com/ava-labs/avalanchego/tests/fixture" - "github.com/ava-labs/avalanchego/tests/fixture/testnet" - "github.com/ava-labs/avalanchego/tests/fixture/testnet/local" + "github.com/ava-labs/avalanchego/tests/fixture/ephnet" + "github.com/ava-labs/avalanchego/tests/fixture/ephnet/local" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/perms" "github.com/ava-labs/avalanchego/vms/secp256k1fx" @@ -40,7 +40,7 @@ type TestEnvironment struct { // The directory where the test network configuration is stored NetworkDir string // URIs used to access the API endpoints of nodes of the network - URIs []testnet.NodeURI + URIs []ephnet.NodeURI // The URI used to access the http server that allocates test data TestDataServerURI string @@ -57,16 +57,15 @@ func (te *TestEnvironment) Marshal() []byte { func NewTestEnvironment(flagVars *FlagVars) *TestEnvironment { require := require.New(ginkgo.GinkgoT()) - persistentNetworkDir := flagVars.PersistentNetworkDir() + networkDir := flagVars.NetworkDir() // Load or create a test network var network *local.LocalNetwork - if len(persistentNetworkDir) > 0 { - tests.Outf("{{yellow}}Using a persistent network configured at %s{{/}}\n", persistentNetworkDir) - + if len(networkDir) > 0 { var err error - network, err = local.ReadNetwork(persistentNetworkDir) + network, err = local.ReadNetwork(networkDir) require.NoError(err) + tests.Outf("{{yellow}}Using an existing network configured at %s{{/}}\n", network.Dir) } else { network = StartLocalNetwork(flagVars.AvalancheGoExecPath(), DefaultNetworkDir) } @@ -90,7 +89,7 @@ func NewTestEnvironment(flagVars *FlagVars) *TestEnvironment { // Retrieve a random URI to naively attempt to spread API load across // nodes. -func (te *TestEnvironment) GetRandomNodeURI() testnet.NodeURI { +func (te *TestEnvironment) GetRandomNodeURI() ephnet.NodeURI { r := rand.New(rand.NewSource(time.Now().Unix())) //#nosec G404 nodeURI := te.URIs[r.Intn(len(te.URIs))] tests.Outf("{{blue}} targeting node %s with URI: %s{{/}}\n", nodeURI.NodeID, nodeURI.URI) @@ -98,7 +97,7 @@ func (te *TestEnvironment) GetRandomNodeURI() testnet.NodeURI { } // Retrieve the network to target for testing. -func (te *TestEnvironment) GetNetwork() testnet.Network { +func (te *TestEnvironment) GetNetwork() ephnet.Network { network, err := local.ReadNetwork(te.NetworkDir) te.require.NoError(err) return network @@ -124,7 +123,7 @@ func (te *TestEnvironment) NewKeychain(count int) *secp256k1fx.Keychain { } // Create a new private network that is not shared with other tests. -func (te *TestEnvironment) NewPrivateNetwork() testnet.Network { +func (te *TestEnvironment) NewPrivateNetwork() ephnet.Network { // Load the shared network to retrieve its path and exec path sharedNetwork, err := local.ReadNetwork(te.NetworkDir) te.require.NoError(err) diff --git a/tests/fixture/e2e/flags.go b/tests/fixture/e2e/flags.go index c7838cb7c761..a3fba5093ebb 100644 --- a/tests/fixture/e2e/flags.go +++ b/tests/fixture/e2e/flags.go @@ -8,28 +8,31 @@ import ( "fmt" "os" - "github.com/ava-labs/avalanchego/tests/fixture/testnet/local" + "github.com/ava-labs/avalanchego/tests/fixture/ephnet/local" ) type FlagVars struct { - avalancheGoExecPath string - persistentNetworkDir string - usePersistentNetwork bool + avalancheGoExecPath string + networkDir string + useExistingNetwork bool } -func (v *FlagVars) PersistentNetworkDir() string { - if v.usePersistentNetwork && len(v.persistentNetworkDir) == 0 { - return os.Getenv(local.NetworkDirEnvName) +func (v *FlagVars) NetworkDir() string { + if !v.useExistingNetwork { + return "" } - return v.persistentNetworkDir + if len(v.networkDir) > 0 { + return v.networkDir + } + return os.Getenv(local.NetworkDirEnvName) } func (v *FlagVars) AvalancheGoExecPath() string { return v.avalancheGoExecPath } -func (v *FlagVars) UsePersistentNetwork() bool { - return v.usePersistentNetwork +func (v *FlagVars) UseExistingNetwork() bool { + return v.useExistingNetwork } func RegisterFlags() *FlagVars { @@ -38,19 +41,19 @@ func RegisterFlags() *FlagVars { &vars.avalancheGoExecPath, "avalanchego-path", os.Getenv(local.AvalancheGoPathEnvName), - fmt.Sprintf("avalanchego executable path (required if not using a persistent network). Also possible to configure via the %s env variable.", local.AvalancheGoPathEnvName), + fmt.Sprintf("avalanchego executable path (required if not using an existing network). Also possible to configure via the %s env variable.", local.AvalancheGoPathEnvName), ) flag.StringVar( - &vars.persistentNetworkDir, + &vars.networkDir, "network-dir", "", - fmt.Sprintf("[optional] the dir containing the configuration of a persistent network to target for testing. Useful for speeding up test development. Also possible to configure via the %s env variable.", local.NetworkDirEnvName), + fmt.Sprintf("[optional] the dir containing the configuration of an existing network to target for testing. Will only be used if --use-existing-network is specified. Also possible to configure via the %s env variable.", local.NetworkDirEnvName), ) flag.BoolVar( - &vars.usePersistentNetwork, - "use-persistent-network", + &vars.useExistingNetwork, + "use-existing-network", false, - "[optional] whether to target the persistent network identified by --network-dir.", + "[optional] whether to target the existing network identified by --network-dir.", ) return &vars diff --git a/tests/fixture/e2e/helpers.go b/tests/fixture/e2e/helpers.go index 15da611324e0..6ba7bb47c807 100644 --- a/tests/fixture/e2e/helpers.go +++ b/tests/fixture/e2e/helpers.go @@ -22,8 +22,8 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/tests" - "github.com/ava-labs/avalanchego/tests/fixture/testnet" - "github.com/ava-labs/avalanchego/tests/fixture/testnet/local" + "github.com/ava-labs/avalanchego/tests/fixture/ephnet" + "github.com/ava-labs/avalanchego/tests/fixture/ephnet/local" "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/subnet/primary" @@ -62,7 +62,7 @@ const ( ) // Create a new wallet for the provided keychain against the specified node URI. -func NewWallet(keychain *secp256k1fx.Keychain, nodeURI testnet.NodeURI) primary.Wallet { +func NewWallet(keychain *secp256k1fx.Keychain, nodeURI ephnet.NodeURI) primary.Wallet { tests.Outf("{{blue}} initializing a new wallet for node %s with URI: %s {{/}}\n", nodeURI.NodeID, nodeURI.URI) baseWallet, err := primary.MakeWallet(DefaultContext(), &primary.WalletConfig{ URI: nodeURI.URI, @@ -81,7 +81,7 @@ func NewWallet(keychain *secp256k1fx.Keychain, nodeURI testnet.NodeURI) primary. } // Create a new eth client targeting the specified node URI. -func NewEthClient(nodeURI testnet.NodeURI) ethclient.Client { +func NewEthClient(nodeURI ephnet.NodeURI) ethclient.Client { tests.Outf("{{blue}} initializing a new eth client for node %s with URI: %s {{/}}\n", nodeURI.NodeID, nodeURI.URI) nodeAddress := strings.Split(nodeURI.URI, "//")[1] uri := fmt.Sprintf("ws://%s/ext/bc/C/ws", nodeAddress) @@ -128,7 +128,7 @@ func Eventually(condition func() bool, waitFor time.Duration, tick time.Duration // Add an ephemeral node that is only intended to be used by a single test. Its ID and // URI are not intended to be returned from the Network instance to minimize // accessibility from other tests. -func AddEphemeralNode(network testnet.Network, flags testnet.FlagsMap) testnet.Node { +func AddEphemeralNode(network ephnet.Network, flags ephnet.FlagsMap) ephnet.Node { require := require.New(ginkgo.GinkgoT()) node, err := network.AddEphemeralNode(ginkgo.GinkgoWriter, flags) @@ -145,11 +145,11 @@ func AddEphemeralNode(network testnet.Network, flags testnet.FlagsMap) testnet.N } // Wait for the given node to report healthy. -func WaitForHealthy(node testnet.Node) { +func WaitForHealthy(node ephnet.Node) { // Need to use explicit context (vs DefaultContext()) to support use with DeferCleanup ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout) defer cancel() - require.NoError(ginkgo.GinkgoT(), testnet.WaitForHealthy(ctx, node)) + require.NoError(ginkgo.GinkgoT(), ephnet.WaitForHealthy(ctx, node)) } // Sends an eth transaction, waits for the transaction receipt to be issued @@ -197,7 +197,7 @@ func WithSuggestedGasPrice(ethClient ethclient.Client) common.Option { } // Verify that a new node can bootstrap into the network. -func CheckBootstrapIsPossible(network testnet.Network) { +func CheckBootstrapIsPossible(network ephnet.Network) { require := require.New(ginkgo.GinkgoT()) if len(os.Getenv(SkipBootstrapChecksEnvName)) > 0 { @@ -210,7 +210,7 @@ func CheckBootstrapIsPossible(network testnet.Network) { // checking for bootstrap implicitly on teardown via a function registered // with ginkgo.DeferCleanup. It's not possible to call DeferCleanup from // within a function called by DeferCleanup. - node, err := network.AddEphemeralNode(ginkgo.GinkgoWriter, testnet.FlagsMap{}) + node, err := network.AddEphemeralNode(ginkgo.GinkgoWriter, ephnet.FlagsMap{}) require.NoError(err) defer func() { @@ -234,8 +234,8 @@ func StartLocalNetwork(avalancheGoExecPath string, networkDir string) *local.Loc ExecPath: avalancheGoExecPath, }, }, - testnet.DefaultNodeCount, - testnet.DefaultFundedKeyCount, + ephnet.DefaultNodeCount, + ephnet.DefaultFundedKeyCount, ) require.NoError(err) ginkgo.DeferCleanup(func() { diff --git a/tests/fixture/ephnet/README.md b/tests/fixture/ephnet/README.md new file mode 100644 index 000000000000..49a8e6fcace3 --- /dev/null +++ b/tests/fixture/ephnet/README.md @@ -0,0 +1,20 @@ +# ephnet (ephemeral network fixture) + +This package contains configuration and interfaces that are +independent of a given orchestration mechanism +(e.g. [local](local/README.md)). The intent is to enable tests to be +written against the interfaces defined in this package and for +implementation-specific details of test network orchestration to be +limited to test setup and teardown. + +## What's in a name? + +The name of this package was originally `testnet` and its cli was +`testnetctl`. This name was chosen in ignorance that `testnet` +commonly refers to a persistent blockchain network used for testing. + +To avoid confusion, the name was changed to `ephnet` and its cli +`ephnetctl`. `ephnet` is short for `ephemeral network` since the +networks it deploys are likely to live for a limited duration in +support of the development and testing of avalanchego and its related +repositories. diff --git a/tests/fixture/testnet/cmd/main.go b/tests/fixture/ephnet/cmd/main.go similarity index 86% rename from tests/fixture/testnet/cmd/main.go rename to tests/fixture/ephnet/cmd/main.go index 92dc846edca8..419d77c6bddc 100644 --- a/tests/fixture/testnet/cmd/main.go +++ b/tests/fixture/ephnet/cmd/main.go @@ -13,8 +13,8 @@ import ( "github.com/spf13/cobra" - "github.com/ava-labs/avalanchego/tests/fixture/testnet" - "github.com/ava-labs/avalanchego/tests/fixture/testnet/local" + "github.com/ava-labs/avalanchego/tests/fixture/ephnet" + "github.com/ava-labs/avalanchego/tests/fixture/ephnet/local" "github.com/ava-labs/avalanchego/version" ) @@ -27,8 +27,8 @@ var ( func main() { rootCmd := &cobra.Command{ - Use: "testnetctl", - Short: "testnetctl commands", + Use: "ephnetctl", + Short: "ephnetctl commands", } versionCmd := &cobra.Command{ @@ -84,7 +84,7 @@ func main() { return err } - fmt.Fprintf(os.Stdout, "\nConfigure testnetctl to target this network by default with one of the following statements:") + fmt.Fprintf(os.Stdout, "\nConfigure ephnetctl to target this network by default with one of the following statements:") fmt.Fprintf(os.Stdout, "\n - source %s\n", network.EnvFilePath()) fmt.Fprintf(os.Stdout, " - %s\n", network.EnvFileContents()) fmt.Fprintf(os.Stdout, " - export %s=%s\n", local.NetworkDirEnvName, latestSymlinkPath) @@ -94,8 +94,8 @@ func main() { } startNetworkCmd.PersistentFlags().StringVar(&rootDir, "root-dir", os.Getenv(local.RootDirEnvName), "The path to the root directory for local networks") startNetworkCmd.PersistentFlags().StringVar(&execPath, "avalanchego-path", os.Getenv(local.AvalancheGoPathEnvName), "The path to an avalanchego binary") - startNetworkCmd.PersistentFlags().Uint8Var(&nodeCount, "node-count", testnet.DefaultNodeCount, "Number of nodes the network should initially consist of") - startNetworkCmd.PersistentFlags().Uint8Var(&fundedKeyCount, "funded-key-count", testnet.DefaultFundedKeyCount, "Number of funded keys the network should start with") + startNetworkCmd.PersistentFlags().Uint8Var(&nodeCount, "node-count", ephnet.DefaultNodeCount, "Number of nodes the network should initially consist of") + startNetworkCmd.PersistentFlags().Uint8Var(&fundedKeyCount, "funded-key-count", ephnet.DefaultFundedKeyCount, "Number of funded keys the network should start with") rootCmd.AddCommand(startNetworkCmd) var networkDir string @@ -117,7 +117,7 @@ func main() { rootCmd.AddCommand(stopNetworkCmd) if err := rootCmd.Execute(); err != nil { - fmt.Fprintf(os.Stderr, "testnetctl failed: %v\n", err) + fmt.Fprintf(os.Stderr, "ephnetctl failed: %v\n", err) os.Exit(1) } os.Exit(0) diff --git a/tests/fixture/testnet/common.go b/tests/fixture/ephnet/common.go similarity index 98% rename from tests/fixture/testnet/common.go rename to tests/fixture/ephnet/common.go index ab983e893e46..385575b9a402 100644 --- a/tests/fixture/testnet/common.go +++ b/tests/fixture/ephnet/common.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package testnet +package ephnet import ( "context" diff --git a/tests/fixture/testnet/config.go b/tests/fixture/ephnet/config.go similarity index 99% rename from tests/fixture/testnet/config.go rename to tests/fixture/ephnet/config.go index 425aa646a690..471c2fab2408 100644 --- a/tests/fixture/testnet/config.go +++ b/tests/fixture/ephnet/config.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package testnet +package ephnet import ( "encoding/base64" diff --git a/tests/fixture/testnet/interfaces.go b/tests/fixture/ephnet/interfaces.go similarity index 97% rename from tests/fixture/testnet/interfaces.go rename to tests/fixture/ephnet/interfaces.go index 2c1479ec48bd..214f693c9ee9 100644 --- a/tests/fixture/testnet/interfaces.go +++ b/tests/fixture/ephnet/interfaces.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package testnet +package ephnet import ( "context" diff --git a/tests/fixture/testnet/local/README.md b/tests/fixture/ephnet/local/README.md similarity index 86% rename from tests/fixture/testnet/local/README.md rename to tests/fixture/ephnet/local/README.md index fdfbbdb4d58b..2634364cdd13 100644 --- a/tests/fixture/testnet/local/README.md +++ b/tests/fixture/ephnet/local/README.md @@ -4,7 +4,7 @@ This package implements a simple orchestrator for the avalanchego nodes of a local network. Configuration is stored on disk, and nodes run as independent processes whose process details are also written to disk. Using the filesystem to store configuration and process details -allows for the `testnetctl` cli and e2e test fixture to orchestrate +allows for the `ephnetctl` cli and e2e test fixture to orchestrate the same local networks without the use of an rpc daemon. ## Package details @@ -27,36 +27,36 @@ abstractions. ## Usage -### Via testnetctl +### Via ephnetctl -A local network can be managed by the `testnetctl` cli tool: +A local network can be managed by the `ephnetctl` cli tool: ```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 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 # Stop the network -$ ./build/testnetctl stop-network --network-dir=/path/to/network +$ ./build/ephnetctl stop-network --network-dir=/path/to/network ``` Note the export of the path ending in `latest`. This is a symlink that -set to the last network created by `testnetctl start-network`. Setting -the `TESTNETCTL_NETWORK_DIR` env var to this symlink ensures that -`testnetctl` commands and e2e execution with -`--use-persistent-network` will target the most recently deployed -local network. +is set to the last network created by `ephnetctl start-network`. Setting +the `EPHNET_NETWORK_DIR` env var to this symlink ensures that +`ephnetctl` commands and e2e execution with +`--use-existing-network` will target the most recently deployed local +network. ### Via code @@ -66,7 +66,7 @@ A local network can be managed in code: network, _ := local.StartNetwork( ctx, // Context used to limit duration of waiting for network health ginkgo.GinkgoWriter, // Writer to report progress of network start - "", // Use default root dir (~/.testnetctl) + "", // Use default root dir (~/.ephnet) &local.LocalNetwork{ LocalConfig: local.LocalConfig{ ExecPath: "/path/to/avalanchego", // Defining the avalanchego exec path is required @@ -121,7 +121,7 @@ tests](../../../e2e/e2e_test.go). By default, nodes in a local network will be started with staking and API ports set to `0` to ensure that ports will be dynamically -chosen. The testnet fixture discovers the ports used by a given node +chosen. The ephnet fixture discovers the ports used by a given node by reading the `[base-data-dir]/process.json` file written by avalanchego on node start. The use of dynamic ports supports testing with many local networks without having to manually select compatible @@ -133,7 +133,7 @@ A local network relies on configuration written to disk in the following structu ``` HOME -└── .testnetctl // Root path for tool +└── .ephnet // Root path for the ephemeral network fixture └── networks // Default parent directory for local networks └── 1000 // The networkID is used to name the network dir and starts at 1000 ├── NodeID-37E8UK3x2YFsHE3RdALmfWcppcZ1eTuj9 // The ID of a node is the name of its data dir @@ -189,10 +189,10 @@ TODO(marun) Enable configuration of X-Chain and P-Chain. ### Network env -A shell script that sets the `TESTNETCTL_NETWORK_DIR` env var to the +A shell script that sets the `EPHNET_NETWORK_DIR` env var to the path of the network is stored at `[network-dir]/network.env`. Sourcing this file (i.e. `source network.env`) in a shell will configure ginkgo -e2e and the `testnetctl` cli to target the network path specified in +e2e and the `ephnetctl` cli to target the network path specified in the env var. ### Node configuration diff --git a/tests/fixture/testnet/local/config.go b/tests/fixture/ephnet/local/config.go similarity index 79% rename from tests/fixture/testnet/local/config.go rename to tests/fixture/ephnet/local/config.go index 317975a2395c..462cd30cd7cd 100644 --- a/tests/fixture/testnet/local/config.go +++ b/tests/fixture/ephnet/local/config.go @@ -7,15 +7,15 @@ import ( "time" "github.com/ava-labs/avalanchego/config" - "github.com/ava-labs/avalanchego/tests/fixture/testnet" + "github.com/ava-labs/avalanchego/tests/fixture/ephnet" ) const ( // Constants defining the names of shell variables whose value can // configure local network orchestration. AvalancheGoPathEnvName = "AVALANCHEGO_PATH" - NetworkDirEnvName = "TESTNETCTL_NETWORK_DIR" - RootDirEnvName = "TESTNETCTL_ROOT_DIR" + NetworkDirEnvName = "EPHNET_NETWORK_DIR" + RootDirEnvName = "EPHNET_ROOT_DIR" DefaultNetworkStartTimeout = 2 * time.Minute DefaultNodeInitTimeout = 10 * time.Second @@ -23,9 +23,9 @@ const ( ) // A set of flags appropriate for local testing. -func LocalFlags() testnet.FlagsMap { +func LocalFlags() ephnet.FlagsMap { // Supply only non-default configuration to ensure that default values will be used. - return testnet.FlagsMap{ + return ephnet.FlagsMap{ config.NetworkPeerListGossipFreqKey: "250ms", config.NetworkMaxReconnectDelayKey: "1s", config.PublicIPKey: "127.0.0.1", @@ -37,16 +37,16 @@ func LocalFlags() testnet.FlagsMap { config.IndexEnabledKey: true, config.LogDisplayLevelKey: "INFO", config.LogLevelKey: "DEBUG", - config.MinStakeDurationKey: testnet.DefaultMinStakeDuration.String(), + config.MinStakeDurationKey: ephnet.DefaultMinStakeDuration.String(), } } // C-Chain config for local testing. -func LocalCChainConfig() testnet.FlagsMap { +func LocalCChainConfig() ephnet.FlagsMap { // Supply only non-default configuration to ensure that default // values will be used. Available C-Chain configuration options are // defined in the `github.com/ava-labs/coreth/evm` package. - return testnet.FlagsMap{ + return ephnet.FlagsMap{ "log-level": "trace", } } diff --git a/tests/fixture/testnet/local/network.go b/tests/fixture/ephnet/local/network.go similarity index 95% rename from tests/fixture/testnet/local/network.go rename to tests/fixture/ephnet/local/network.go index 836a1489c2dd..2a4f9d01f335 100644 --- a/tests/fixture/testnet/local/network.go +++ b/tests/fixture/ephnet/local/network.go @@ -18,7 +18,7 @@ import ( "github.com/ava-labs/avalanchego/config" "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" - "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/perms" @@ -48,7 +48,7 @@ func GetDefaultRootDir() (string, error) { if err != nil { return "", err } - return filepath.Join(homeDir, ".testnetctl", "networks"), nil + return filepath.Join(homeDir, ".ephnet", "networks"), nil } // Find the next available network ID by attempting to create a @@ -83,7 +83,7 @@ func FindNextNetworkID(rootDir string) (uint32, string, error) { // Defines the configuration required for a local network (i.e. one composed of local processes). type LocalNetwork struct { - testnet.NetworkConfig + ephnet.NetworkConfig LocalConfig // Nodes with local configuration @@ -94,13 +94,13 @@ type LocalNetwork struct { } // Returns the configuration of the network in backend-agnostic form. -func (ln *LocalNetwork) GetConfig() testnet.NetworkConfig { +func (ln *LocalNetwork) GetConfig() ephnet.NetworkConfig { return ln.NetworkConfig } // Returns the nodes of the network in backend-agnostic form. -func (ln *LocalNetwork) GetNodes() []testnet.Node { - nodes := make([]testnet.Node, 0, len(ln.Nodes)) +func (ln *LocalNetwork) GetNodes() []ephnet.Node { + nodes := make([]ephnet.Node, 0, len(ln.Nodes)) for _, node := range ln.Nodes { nodes = append(nodes, node) } @@ -108,12 +108,12 @@ func (ln *LocalNetwork) GetNodes() []testnet.Node { } // Adds a backend-agnostic ephemeral node to the network -func (ln *LocalNetwork) AddEphemeralNode(w io.Writer, flags testnet.FlagsMap) (testnet.Node, error) { +func (ln *LocalNetwork) AddEphemeralNode(w io.Writer, flags ephnet.FlagsMap) (ephnet.Node, error) { if flags == nil { - flags = testnet.FlagsMap{} + flags = ephnet.FlagsMap{} } return ln.AddLocalNode(w, &LocalNode{ - NodeConfig: testnet.NodeConfig{ + NodeConfig: ephnet.NodeConfig{ Flags: flags, }, }, true /* isEphemeral */) @@ -298,7 +298,7 @@ func (ln *LocalNetwork) PopulateNodeConfig(node *LocalNode, nodeParentDir string // Set values common to all nodes flags.SetDefaults(ln.DefaultFlags) - flags.SetDefaults(testnet.FlagsMap{ + flags.SetDefaults(ephnet.FlagsMap{ config.GenesisFileKey: ln.GetGenesisPath(), config.ChainConfigDirKey: ln.GetChainConfigDir(), }) @@ -385,7 +385,7 @@ func (ln *LocalNetwork) WaitForHealthy(ctx context.Context, w io.Writer) error { } healthy, err := node.IsHealthy(ctx) - if err != nil && !errors.Is(err, testnet.ErrNotRunning) { + if err != nil && !errors.Is(err, ephnet.ErrNotRunning) { return err } if !healthy { @@ -409,14 +409,14 @@ func (ln *LocalNetwork) WaitForHealthy(ctx context.Context, w io.Writer) error { // Retrieve API URIs for all running primary validator nodes. URIs for // ephemeral nodes are not returned. -func (ln *LocalNetwork) GetURIs() []testnet.NodeURI { - uris := make([]testnet.NodeURI, 0, len(ln.Nodes)) +func (ln *LocalNetwork) GetURIs() []ephnet.NodeURI { + uris := make([]ephnet.NodeURI, 0, len(ln.Nodes)) for _, node := range ln.Nodes { // Only append URIs that are not empty. A node may have an // empty URI if it was not running at the time // node.ReadProcessContext() was called. if len(node.URI) > 0 { - uris = append(uris, testnet.NodeURI{ + uris = append(uris, ephnet.NodeURI{ NodeID: node.NodeID, URI: node.URI, }) @@ -458,7 +458,7 @@ func (ln *LocalNetwork) ReadGenesis() error { } func (ln *LocalNetwork) WriteGenesis() error { - bytes, err := testnet.DefaultJSONMarshal(ln.Genesis) + bytes, err := ephnet.DefaultJSONMarshal(ln.Genesis) if err != nil { return fmt.Errorf("failed to marshal genesis: %w", err) } @@ -477,7 +477,7 @@ func (ln *LocalNetwork) GetCChainConfigPath() string { } func (ln *LocalNetwork) ReadCChainConfig() error { - chainConfig, err := testnet.ReadFlagsMap(ln.GetCChainConfigPath(), "C-Chain config") + chainConfig, err := ephnet.ReadFlagsMap(ln.GetCChainConfigPath(), "C-Chain config") if err != nil { return err } @@ -496,7 +496,7 @@ func (ln *LocalNetwork) WriteCChainConfig() error { // Used to marshal/unmarshal persistent local network defaults. type localDefaults struct { - Flags testnet.FlagsMap + Flags ephnet.FlagsMap ExecPath string FundedKeys []*secp256k1.PrivateKey } @@ -526,7 +526,7 @@ func (ln *LocalNetwork) WriteDefaults() error { ExecPath: ln.ExecPath, FundedKeys: ln.FundedKeys, } - bytes, err := testnet.DefaultJSONMarshal(defaults) + bytes, err := ephnet.DefaultJSONMarshal(defaults) if err != nil { return fmt.Errorf("failed to marshal defaults: %w", err) } diff --git a/tests/fixture/testnet/local/network_test.go b/tests/fixture/ephnet/local/network_test.go similarity index 100% rename from tests/fixture/testnet/local/network_test.go rename to tests/fixture/ephnet/local/network_test.go diff --git a/tests/fixture/testnet/local/node.go b/tests/fixture/ephnet/local/node.go similarity index 95% rename from tests/fixture/testnet/local/node.go rename to tests/fixture/ephnet/local/node.go index 2de516825677..11fd20fed79c 100644 --- a/tests/fixture/testnet/local/node.go +++ b/tests/fixture/ephnet/local/node.go @@ -23,7 +23,7 @@ import ( "github.com/ava-labs/avalanchego/config" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/node" - "github.com/ava-labs/avalanchego/tests/fixture/testnet" + "github.com/ava-labs/avalanchego/tests/fixture/ephnet" "github.com/ava-labs/avalanchego/utils/perms" ) @@ -42,7 +42,7 @@ type LocalConfig struct { // Stores the configuration and process details of a node in a local network. type LocalNode struct { - testnet.NodeConfig + ephnet.NodeConfig LocalConfig node.NodeProcessContext @@ -51,8 +51,8 @@ type LocalNode struct { func NewLocalNode(dataDir string) *LocalNode { return &LocalNode{ - NodeConfig: testnet.NodeConfig{ - Flags: testnet.FlagsMap{ + NodeConfig: ephnet.NodeConfig{ + Flags: ephnet.FlagsMap{ config.DataDirKey: dataDir, }, }, @@ -76,7 +76,7 @@ func (n *LocalNode) GetID() ids.NodeID { } // Retrieve backend-agnostic node configuration. -func (n *LocalNode) GetConfig() testnet.NodeConfig { +func (n *LocalNode) GetConfig() ephnet.NodeConfig { return n.NodeConfig } @@ -98,11 +98,11 @@ func (n *LocalNode) ReadConfig() error { if err != nil { return fmt.Errorf("failed to read local node config: %w", err) } - flags := testnet.FlagsMap{} + flags := ephnet.FlagsMap{} if err := json.Unmarshal(bytes, &flags); err != nil { return fmt.Errorf("failed to unmarshal local node config: %w", err) } - config := testnet.NodeConfig{Flags: flags} + config := ephnet.NodeConfig{Flags: flags} if err := config.EnsureNodeID(); err != nil { return err } @@ -115,7 +115,7 @@ func (n *LocalNode) WriteConfig() error { return fmt.Errorf("failed to create node dir: %w", err) } - bytes, err := testnet.DefaultJSONMarshal(n.Flags) + bytes, err := ephnet.DefaultJSONMarshal(n.Flags) if err != nil { return fmt.Errorf("failed to marshal local node config: %w", err) } @@ -265,7 +265,7 @@ func (n *LocalNode) Stop() error { } // Wait for the node process to stop - ticker := time.NewTicker(testnet.DefaultNodeTickerInterval) + ticker := time.NewTicker(ephnet.DefaultNodeTickerInterval) defer ticker.Stop() ctx, cancel := context.WithTimeout(context.Background(), DefaultNodeStopTimeout) defer cancel() @@ -295,7 +295,7 @@ func (n *LocalNode) IsHealthy(ctx context.Context) (bool, error) { return false, fmt.Errorf("failed to determine process status: %w", err) } if proc == nil { - return false, testnet.ErrNotRunning + return false, ephnet.ErrNotRunning } // Check that the node is reporting healthy @@ -321,7 +321,7 @@ func (n *LocalNode) IsHealthy(ctx context.Context) (bool, error) { } func (n *LocalNode) WaitForProcessContext(ctx context.Context) error { - ticker := time.NewTicker(testnet.DefaultNodeTickerInterval) + ticker := time.NewTicker(ephnet.DefaultNodeTickerInterval) defer ticker.Stop() ctx, cancel := context.WithTimeout(ctx, DefaultNodeInitTimeout) diff --git a/tests/fixture/testnet/local/node_test.go b/tests/fixture/ephnet/local/node_test.go similarity index 100% rename from tests/fixture/testnet/local/node_test.go rename to tests/fixture/ephnet/local/node_test.go diff --git a/tests/fixture/testnet/README.md b/tests/fixture/testnet/README.md deleted file mode 100644 index ef2e5fb4df75..000000000000 --- a/tests/fixture/testnet/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Test Network Fixture - -This package contains configuration and interfaces that are -independent of a given orchestration mechanism -(e.g. [local](local/README.md)). The intent is to enable tests to be -written against the interfaces defined in this package and for -implementation-specific details of test network orchestration to be -limited to test setup and teardown. From 0529a0247bd568c9495a222b59235b25336a510f Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Mon, 27 Nov 2023 20:25:48 +0100 Subject: [PATCH 2/2] fixup: rename to tmpnet --- .github/workflows/test.e2e.existing.yml | 6 +-- .github/workflows/test.e2e.yml | 6 +-- ...{build_ephnetctl.sh => build_tmpnetctl.sh} | 6 +-- scripts/tests.e2e.existing.sh | 22 +++++----- scripts/tests.e2e.sh | 8 ++-- tests/e2e/README.md | 28 ++++++------- tests/e2e/c/dynamic_fees.go | 4 +- tests/e2e/faultinjection/duplicate_node_id.go | 10 ++--- tests/e2e/p/interchain_workflow.go | 6 +-- tests/e2e/p/staking_rewards.go | 8 ++-- tests/fixture/e2e/env.go | 12 +++--- tests/fixture/e2e/flags.go | 2 +- tests/fixture/e2e/helpers.go | 22 +++++----- tests/fixture/{ephnet => tmpnet}/README.md | 6 +-- tests/fixture/{ephnet => tmpnet}/cmd/main.go | 16 ++++---- tests/fixture/{ephnet => tmpnet}/common.go | 2 +- tests/fixture/{ephnet => tmpnet}/config.go | 2 +- .../fixture/{ephnet => tmpnet}/interfaces.go | 2 +- .../{ephnet => tmpnet}/local/README.md | 40 +++++++++---------- .../{ephnet => tmpnet}/local/config.go | 16 ++++---- .../{ephnet => tmpnet}/local/network.go | 36 ++++++++--------- .../{ephnet => tmpnet}/local/network_test.go | 0 .../fixture/{ephnet => tmpnet}/local/node.go | 22 +++++----- .../{ephnet => tmpnet}/local/node_test.go | 0 24 files changed, 141 insertions(+), 141 deletions(-) rename scripts/{build_ephnetctl.sh => build_tmpnetctl.sh} (72%) rename tests/fixture/{ephnet => tmpnet}/README.md (81%) rename tests/fixture/{ephnet => tmpnet}/cmd/main.go (89%) rename tests/fixture/{ephnet => tmpnet}/common.go (98%) rename tests/fixture/{ephnet => tmpnet}/config.go (99%) rename tests/fixture/{ephnet => tmpnet}/interfaces.go (97%) rename tests/fixture/{ephnet => tmpnet}/local/README.md (87%) rename tests/fixture/{ephnet => tmpnet}/local/config.go (80%) rename tests/fixture/{ephnet => tmpnet}/local/network.go (95%) rename tests/fixture/{ephnet => tmpnet}/local/network_test.go (100%) rename tests/fixture/{ephnet => tmpnet}/local/node.go (95%) rename tests/fixture/{ephnet => tmpnet}/local/node_test.go (100%) diff --git a/.github/workflows/test.e2e.existing.yml b/.github/workflows/test.e2e.existing.yml index 7b0cdeb0787d..a50943888f48 100644 --- a/.github/workflows/test.e2e.existing.yml +++ b/.github/workflows/test.e2e.existing.yml @@ -31,9 +31,9 @@ jobs: - name: Run e2e tests with existing network shell: bash run: E2E_SERIAL=1 ./scripts/tests.e2e.existing.sh - - name: Upload ephnet network dir + - name: Upload tmpnet network dir uses: actions/upload-artifact@v3 if: always() with: - name: ephnet-data - path: ~/.ephnet/networks/1000 + name: tmpnet-data + path: ~/.tmpnet/networks/1000 diff --git a/.github/workflows/test.e2e.yml b/.github/workflows/test.e2e.yml index 3597dceaac02..0edc46afebb0 100644 --- a/.github/workflows/test.e2e.yml +++ b/.github/workflows/test.e2e.yml @@ -31,9 +31,9 @@ jobs: - name: Run e2e tests shell: bash run: E2E_SERIAL=1 ./scripts/tests.e2e.sh - - name: Upload ephnet network dir + - name: Upload tmpnet network dir uses: actions/upload-artifact@v3 if: always() with: - name: ephnet-data - path: ~/.ephnet/networks/1000 + name: tmpnet-data + path: ~/.tmpnet/networks/1000 diff --git a/scripts/build_ephnetctl.sh b/scripts/build_tmpnetctl.sh similarity index 72% rename from scripts/build_ephnetctl.sh rename to scripts/build_tmpnetctl.sh index 2fd3026c70d3..132cf09ee38d 100755 --- a/scripts/build_ephnetctl.sh +++ b/scripts/build_tmpnetctl.sh @@ -7,8 +7,8 @@ AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd ) # Load the constants source "$AVALANCHE_PATH"/scripts/constants.sh -echo "Building ephnetctl..." +echo "Building tmpnetctl..." go build -ldflags\ "-X github.com/ava-labs/avalanchego/version.GitCommit=$git_commit $static_ld_flags"\ - -o "$AVALANCHE_PATH/build/ephnetctl"\ - "$AVALANCHE_PATH/tests/fixture/ephnet/cmd/"*.go + -o "$AVALANCHE_PATH/build/tmpnetctl"\ + "$AVALANCHE_PATH/tests/fixture/tmpnet/cmd/"*.go diff --git a/scripts/tests.e2e.existing.sh b/scripts/tests.e2e.existing.sh index ed4b3c999769..bc1f8104977b 100755 --- a/scripts/tests.e2e.existing.sh +++ b/scripts/tests.e2e.existing.sh @@ -3,9 +3,9 @@ set -euo pipefail ################################################################ -# This script deploys an ephemeral network and configures +# This script deploys a temporary network and configures # tests.e2e.sh to execute the e2e suite against it. This -# validates that ephnetctl is capable of starting a network and +# validates that tmpnetctl is capable of starting a network and # that the e2e suite is capable of executing against a network # that it did not create. ################################################################ @@ -32,22 +32,22 @@ function print_separator { # Ensure network cleanup on teardown function cleanup { print_separator - echo "cleaning up ephemeral network" - if [[ -n "${EPHNET_NETWORK_DIR:-}" ]]; then - ./build/ephnetctl stop-network + echo "cleaning up temporary network" + if [[ -n "${TMPNET_NETWORK_DIR:-}" ]]; then + ./build/tmpnetctl stop-network fi } trap cleanup EXIT -# Start an ephemeral network -./scripts/build_ephnetctl.sh +# Start a temporary network +./scripts/build_tmpnetctl.sh print_separator -./build/ephnetctl start-network +./build/tmpnetctl start-network # Determine the network configuration path from the latest symlink -LATEST_SYMLINK_PATH="${HOME}/.ephnet/networks/latest" +LATEST_SYMLINK_PATH="${HOME}/.tmpnet/networks/latest" if [[ -h "${LATEST_SYMLINK_PATH}" ]]; then - export EPHNET_NETWORK_DIR="$(realpath ${LATEST_SYMLINK_PATH})" + export TMPNET_NETWORK_DIR="$(realpath ${LATEST_SYMLINK_PATH})" else echo "failed to find configuration path: ${LATEST_SYMLINK_PATH} symlink not found" exit 255 @@ -55,7 +55,7 @@ fi print_separator # - Setting E2E_USE_EXISTING_NETWORK configures tests.e2e.sh to use -# the ephemeral network identified by EPHNET_NETWORK_DIR. +# the temporary network identified by TMPNET_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 diff --git a/scripts/tests.e2e.sh b/scripts/tests.e2e.sh index b81b3e22a66b..638700c9cc47 100755 --- a/scripts/tests.e2e.sh +++ b/scripts/tests.e2e.sh @@ -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_EXISTING_NETWORK=1 EPHNET_NETWORK_DIR=/path/to ./scripts/tests.e2e.sh # Execute against an existing network +# E2E_USE_EXISTING_NETWORK=1 TMPNET_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 @@ -28,10 +28,10 @@ ACK_GINKGO_RC=true ginkgo build ./tests/e2e ./tests/e2e/e2e.test --help ################################# -# 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 +# Since TMPNET_NETWORK_DIR may be set in the environment (e.g. to configure ginkgo +# or tmpnetctl), 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 +if [[ -n "${E2E_USE_EXISTING_NETWORK:-}" && -n "${TMPNET_NETWORK_DIR:-}" ]]; then E2E_ARGS="--use-existing-network" else AVALANCHEGO_PATH="$(realpath ${AVALANCHEGO_PATH:-./build/avalanchego})" diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 913782260a61..032795b6436e 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -1,6 +1,6 @@ # Avalanche e2e test suites -- Works with fixture-managed ephemeral networks. +- Works with fixture-managed temporary networks. - Compiles to a single binary with customizable configurations. ## Running tests @@ -59,31 +59,31 @@ labeled with `x`, which can be selected by `./tests/e2e/e2e.test ## Testing against an existing network -By default, a new ephemeral test network will be started before each +By default, a new temporary test network will be started before each 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 +it may be helpful to create a temporary 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 create an ephemeral network for use across test runs: +To create an temporary network for use across test runs: ```bash # From the root of the avalanchego repo -# Build the ephnetctl binary -$ ./scripts/build_ephnetctl.sh +# Build the tmpnetctl binary +$ ./scripts/build_tmpnetctl.sh # Start a new network -$ ./build/ephnetctl start-network --avalanchego-path=/path/to/avalanchego +$ ./build/tmpnetctl start-network --avalanchego-path=/path/to/avalanchego ... -Started network 1000 @ /home/me/.ephnet/networks/1000 +Started network 1000 @ /home/me/.tmpnet/networks/1000 -Configure ephnetctl and the test suite to target this network by default +Configure tmpnetctl 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 + - source /home/me/.tmpnet/networks/1000/network.env + - export TMPNET_NETWORK_DIR=/home/me/.tmpnet/networks/1000 + - export TMPNET_NETWORK_DIR=/home/me/.tmpnet/networks/latest # Start a new test run using the existing network ginkgo -v ./tests/e2e -- \ @@ -93,10 +93,10 @@ ginkgo -v ./tests/e2e -- \ --network-dir=/path/to/network # It is also possible to set the AVALANCHEGO_PATH env var instead of supplying --avalanchego-path -# and to set EPHNET_NETWORK_DIR instead of supplying --network-dir. +# and to set TMPNET_NETWORK_DIR instead of supplying --network-dir. ``` -See the ephnet fixture [README](../fixture/ephnet/README.md) for more details. +See the tmpnet fixture [README](../fixture/tmpnet/README.md) for more details. ## Skipping bootstrap checks diff --git a/tests/e2e/c/dynamic_fees.go b/tests/e2e/c/dynamic_fees.go index 28f86ebdc759..38bbd668079b 100644 --- a/tests/e2e/c/dynamic_fees.go +++ b/tests/e2e/c/dynamic_fees.go @@ -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/ephnet" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" ) @@ -47,7 +47,7 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() { ginkgo.By("initializing a coreth client") node := privateNetwork.GetNodes()[0] - nodeURI := ephnet.NodeURI{ + nodeURI := tmpnet.NodeURI{ NodeID: node.GetID(), URI: node.GetProcessContext().URI, } diff --git a/tests/e2e/faultinjection/duplicate_node_id.go b/tests/e2e/faultinjection/duplicate_node_id.go index e3b80c4a77d1..9278c1bd5b8d 100644 --- a/tests/e2e/faultinjection/duplicate_node_id.go +++ b/tests/e2e/faultinjection/duplicate_node_id.go @@ -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/ephnet" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" "github.com/ava-labs/avalanchego/utils/set" ) @@ -27,7 +27,7 @@ var _ = ginkgo.Describe("Duplicate node handling", func() { nodes := network.GetNodes() ginkgo.By("creating new node") - node1 := e2e.AddEphemeralNode(network, ephnet.FlagsMap{}) + node1 := e2e.AddEphemeralNode(network, tmpnet.FlagsMap{}) e2e.WaitForHealthy(node1) ginkgo.By("checking that the new node is connected to its peers") @@ -35,7 +35,7 @@ var _ = ginkgo.Describe("Duplicate node handling", func() { ginkgo.By("creating a second new node with the same staking keypair as the first new node") node1Flags := node1.GetConfig().Flags - node2Flags := ephnet.FlagsMap{ + node2Flags := tmpnet.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 @@ -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 := ephnet.WaitForHealthy(e2e.DefaultContext(), node2) + err := tmpnet.WaitForHealthy(e2e.DefaultContext(), node2) require.ErrorIs(err, context.DeadlineExceeded) ginkgo.By("stopping the first new node") @@ -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 []ephnet.Node, newNode ephnet.Node) { +func checkConnectedPeers(existingNodes []tmpnet.Node, newNode tmpnet.Node) { require := require.New(ginkgo.GinkgoT()) // Collect the node ids of the new node's peers diff --git a/tests/e2e/p/interchain_workflow.go b/tests/e2e/p/interchain_workflow.go index 2210cced062f..678f9b5cc204 100644 --- a/tests/e2e/p/interchain_workflow.go +++ b/tests/e2e/p/interchain_workflow.go @@ -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/ephnet" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/set" @@ -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(ephnet.DefaultMinStakeDuration, minStakeDuration) + require.Equal(tmpnet.DefaultMinStakeDuration, minStakeDuration) }) ginkgo.By("creating wallet with a funded key to send from and recipient key to deliver to") @@ -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, ephnet.FlagsMap{}) + node := e2e.AddEphemeralNode(network, tmpnet.FlagsMap{}) e2e.WaitForHealthy(node) ginkgo.By("retrieving new node's id and pop") diff --git a/tests/e2e/p/staking_rewards.go b/tests/e2e/p/staking_rewards.go index c03806a0983d..f05b3bfbf64a 100644 --- a/tests/e2e/p/staking_rewards.go +++ b/tests/e2e/p/staking_rewards.go @@ -20,7 +20,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/tests" "github.com/ava-labs/avalanchego/tests/fixture/e2e" - "github.com/ava-labs/avalanchego/tests/fixture/ephnet" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/units" @@ -43,13 +43,13 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() { ginkgo.By("checking that the network has a compatible minimum stake duration", func() { minStakeDuration := cast.ToDuration(network.GetConfig().DefaultFlags[config.MinStakeDurationKey]) - require.Equal(ephnet.DefaultMinStakeDuration, minStakeDuration) + require.Equal(tmpnet.DefaultMinStakeDuration, minStakeDuration) }) ginkgo.By("adding alpha node, whose uptime should result in a staking reward") - alphaNode := e2e.AddEphemeralNode(network, ephnet.FlagsMap{}) + alphaNode := e2e.AddEphemeralNode(network, tmpnet.FlagsMap{}) ginkgo.By("adding beta node, whose uptime should not result in a staking reward") - betaNode := e2e.AddEphemeralNode(network, ephnet.FlagsMap{}) + betaNode := e2e.AddEphemeralNode(network, tmpnet.FlagsMap{}) // Wait to check health until both nodes have started to minimize the duration // required for both nodes to report healthy. diff --git a/tests/fixture/e2e/env.go b/tests/fixture/e2e/env.go index 5406377f186a..07c24866a9f0 100644 --- a/tests/fixture/e2e/env.go +++ b/tests/fixture/e2e/env.go @@ -16,8 +16,8 @@ import ( "github.com/ava-labs/avalanchego/tests" "github.com/ava-labs/avalanchego/tests/fixture" - "github.com/ava-labs/avalanchego/tests/fixture/ephnet" - "github.com/ava-labs/avalanchego/tests/fixture/ephnet/local" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet/local" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/perms" "github.com/ava-labs/avalanchego/vms/secp256k1fx" @@ -40,7 +40,7 @@ type TestEnvironment struct { // The directory where the test network configuration is stored NetworkDir string // URIs used to access the API endpoints of nodes of the network - URIs []ephnet.NodeURI + URIs []tmpnet.NodeURI // The URI used to access the http server that allocates test data TestDataServerURI string @@ -89,7 +89,7 @@ func NewTestEnvironment(flagVars *FlagVars) *TestEnvironment { // Retrieve a random URI to naively attempt to spread API load across // nodes. -func (te *TestEnvironment) GetRandomNodeURI() ephnet.NodeURI { +func (te *TestEnvironment) GetRandomNodeURI() tmpnet.NodeURI { r := rand.New(rand.NewSource(time.Now().Unix())) //#nosec G404 nodeURI := te.URIs[r.Intn(len(te.URIs))] tests.Outf("{{blue}} targeting node %s with URI: %s{{/}}\n", nodeURI.NodeID, nodeURI.URI) @@ -97,7 +97,7 @@ func (te *TestEnvironment) GetRandomNodeURI() ephnet.NodeURI { } // Retrieve the network to target for testing. -func (te *TestEnvironment) GetNetwork() ephnet.Network { +func (te *TestEnvironment) GetNetwork() tmpnet.Network { network, err := local.ReadNetwork(te.NetworkDir) te.require.NoError(err) return network @@ -123,7 +123,7 @@ func (te *TestEnvironment) NewKeychain(count int) *secp256k1fx.Keychain { } // Create a new private network that is not shared with other tests. -func (te *TestEnvironment) NewPrivateNetwork() ephnet.Network { +func (te *TestEnvironment) NewPrivateNetwork() tmpnet.Network { // Load the shared network to retrieve its path and exec path sharedNetwork, err := local.ReadNetwork(te.NetworkDir) te.require.NoError(err) diff --git a/tests/fixture/e2e/flags.go b/tests/fixture/e2e/flags.go index a3fba5093ebb..23952b5dcd91 100644 --- a/tests/fixture/e2e/flags.go +++ b/tests/fixture/e2e/flags.go @@ -8,7 +8,7 @@ import ( "fmt" "os" - "github.com/ava-labs/avalanchego/tests/fixture/ephnet/local" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet/local" ) type FlagVars struct { diff --git a/tests/fixture/e2e/helpers.go b/tests/fixture/e2e/helpers.go index 6ba7bb47c807..8b7eb5260b8c 100644 --- a/tests/fixture/e2e/helpers.go +++ b/tests/fixture/e2e/helpers.go @@ -22,8 +22,8 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/tests" - "github.com/ava-labs/avalanchego/tests/fixture/ephnet" - "github.com/ava-labs/avalanchego/tests/fixture/ephnet/local" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet/local" "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor" "github.com/ava-labs/avalanchego/vms/secp256k1fx" "github.com/ava-labs/avalanchego/wallet/subnet/primary" @@ -62,7 +62,7 @@ const ( ) // Create a new wallet for the provided keychain against the specified node URI. -func NewWallet(keychain *secp256k1fx.Keychain, nodeURI ephnet.NodeURI) primary.Wallet { +func NewWallet(keychain *secp256k1fx.Keychain, nodeURI tmpnet.NodeURI) primary.Wallet { tests.Outf("{{blue}} initializing a new wallet for node %s with URI: %s {{/}}\n", nodeURI.NodeID, nodeURI.URI) baseWallet, err := primary.MakeWallet(DefaultContext(), &primary.WalletConfig{ URI: nodeURI.URI, @@ -81,7 +81,7 @@ func NewWallet(keychain *secp256k1fx.Keychain, nodeURI ephnet.NodeURI) primary.W } // Create a new eth client targeting the specified node URI. -func NewEthClient(nodeURI ephnet.NodeURI) ethclient.Client { +func NewEthClient(nodeURI tmpnet.NodeURI) ethclient.Client { tests.Outf("{{blue}} initializing a new eth client for node %s with URI: %s {{/}}\n", nodeURI.NodeID, nodeURI.URI) nodeAddress := strings.Split(nodeURI.URI, "//")[1] uri := fmt.Sprintf("ws://%s/ext/bc/C/ws", nodeAddress) @@ -128,7 +128,7 @@ func Eventually(condition func() bool, waitFor time.Duration, tick time.Duration // Add an ephemeral node that is only intended to be used by a single test. Its ID and // URI are not intended to be returned from the Network instance to minimize // accessibility from other tests. -func AddEphemeralNode(network ephnet.Network, flags ephnet.FlagsMap) ephnet.Node { +func AddEphemeralNode(network tmpnet.Network, flags tmpnet.FlagsMap) tmpnet.Node { require := require.New(ginkgo.GinkgoT()) node, err := network.AddEphemeralNode(ginkgo.GinkgoWriter, flags) @@ -145,11 +145,11 @@ func AddEphemeralNode(network ephnet.Network, flags ephnet.FlagsMap) ephnet.Node } // Wait for the given node to report healthy. -func WaitForHealthy(node ephnet.Node) { +func WaitForHealthy(node tmpnet.Node) { // Need to use explicit context (vs DefaultContext()) to support use with DeferCleanup ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout) defer cancel() - require.NoError(ginkgo.GinkgoT(), ephnet.WaitForHealthy(ctx, node)) + require.NoError(ginkgo.GinkgoT(), tmpnet.WaitForHealthy(ctx, node)) } // Sends an eth transaction, waits for the transaction receipt to be issued @@ -197,7 +197,7 @@ func WithSuggestedGasPrice(ethClient ethclient.Client) common.Option { } // Verify that a new node can bootstrap into the network. -func CheckBootstrapIsPossible(network ephnet.Network) { +func CheckBootstrapIsPossible(network tmpnet.Network) { require := require.New(ginkgo.GinkgoT()) if len(os.Getenv(SkipBootstrapChecksEnvName)) > 0 { @@ -210,7 +210,7 @@ func CheckBootstrapIsPossible(network ephnet.Network) { // checking for bootstrap implicitly on teardown via a function registered // with ginkgo.DeferCleanup. It's not possible to call DeferCleanup from // within a function called by DeferCleanup. - node, err := network.AddEphemeralNode(ginkgo.GinkgoWriter, ephnet.FlagsMap{}) + node, err := network.AddEphemeralNode(ginkgo.GinkgoWriter, tmpnet.FlagsMap{}) require.NoError(err) defer func() { @@ -234,8 +234,8 @@ func StartLocalNetwork(avalancheGoExecPath string, networkDir string) *local.Loc ExecPath: avalancheGoExecPath, }, }, - ephnet.DefaultNodeCount, - ephnet.DefaultFundedKeyCount, + tmpnet.DefaultNodeCount, + tmpnet.DefaultFundedKeyCount, ) require.NoError(err) ginkgo.DeferCleanup(func() { diff --git a/tests/fixture/ephnet/README.md b/tests/fixture/tmpnet/README.md similarity index 81% rename from tests/fixture/ephnet/README.md rename to tests/fixture/tmpnet/README.md index 49a8e6fcace3..ca48d553105e 100644 --- a/tests/fixture/ephnet/README.md +++ b/tests/fixture/tmpnet/README.md @@ -1,4 +1,4 @@ -# ephnet (ephemeral network fixture) +# tmpnet (temporary network fixture) This package contains configuration and interfaces that are independent of a given orchestration mechanism @@ -13,8 +13,8 @@ The name of this package was originally `testnet` and its cli was `testnetctl`. This name was chosen in ignorance that `testnet` commonly refers to a persistent blockchain network used for testing. -To avoid confusion, the name was changed to `ephnet` and its cli -`ephnetctl`. `ephnet` is short for `ephemeral network` since the +To avoid confusion, the name was changed to `tmpnet` and its cli +`tmpnetctl`. `tmpnet` is short for `temporary network` since the networks it deploys are likely to live for a limited duration in support of the development and testing of avalanchego and its related repositories. diff --git a/tests/fixture/ephnet/cmd/main.go b/tests/fixture/tmpnet/cmd/main.go similarity index 89% rename from tests/fixture/ephnet/cmd/main.go rename to tests/fixture/tmpnet/cmd/main.go index 419d77c6bddc..a9f5c1865291 100644 --- a/tests/fixture/ephnet/cmd/main.go +++ b/tests/fixture/tmpnet/cmd/main.go @@ -13,8 +13,8 @@ import ( "github.com/spf13/cobra" - "github.com/ava-labs/avalanchego/tests/fixture/ephnet" - "github.com/ava-labs/avalanchego/tests/fixture/ephnet/local" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet/local" "github.com/ava-labs/avalanchego/version" ) @@ -27,8 +27,8 @@ var ( func main() { rootCmd := &cobra.Command{ - Use: "ephnetctl", - Short: "ephnetctl commands", + Use: "tmpnetctl", + Short: "tmpnetctl commands", } versionCmd := &cobra.Command{ @@ -84,7 +84,7 @@ func main() { return err } - fmt.Fprintf(os.Stdout, "\nConfigure ephnetctl to target this network by default with one of the following statements:") + fmt.Fprintf(os.Stdout, "\nConfigure tmpnetctl to target this network by default with one of the following statements:") fmt.Fprintf(os.Stdout, "\n - source %s\n", network.EnvFilePath()) fmt.Fprintf(os.Stdout, " - %s\n", network.EnvFileContents()) fmt.Fprintf(os.Stdout, " - export %s=%s\n", local.NetworkDirEnvName, latestSymlinkPath) @@ -94,8 +94,8 @@ func main() { } startNetworkCmd.PersistentFlags().StringVar(&rootDir, "root-dir", os.Getenv(local.RootDirEnvName), "The path to the root directory for local networks") startNetworkCmd.PersistentFlags().StringVar(&execPath, "avalanchego-path", os.Getenv(local.AvalancheGoPathEnvName), "The path to an avalanchego binary") - startNetworkCmd.PersistentFlags().Uint8Var(&nodeCount, "node-count", ephnet.DefaultNodeCount, "Number of nodes the network should initially consist of") - startNetworkCmd.PersistentFlags().Uint8Var(&fundedKeyCount, "funded-key-count", ephnet.DefaultFundedKeyCount, "Number of funded keys the network should start with") + startNetworkCmd.PersistentFlags().Uint8Var(&nodeCount, "node-count", tmpnet.DefaultNodeCount, "Number of nodes the network should initially consist of") + startNetworkCmd.PersistentFlags().Uint8Var(&fundedKeyCount, "funded-key-count", tmpnet.DefaultFundedKeyCount, "Number of funded keys the network should start with") rootCmd.AddCommand(startNetworkCmd) var networkDir string @@ -117,7 +117,7 @@ func main() { rootCmd.AddCommand(stopNetworkCmd) if err := rootCmd.Execute(); err != nil { - fmt.Fprintf(os.Stderr, "ephnetctl failed: %v\n", err) + fmt.Fprintf(os.Stderr, "tmpnetctl failed: %v\n", err) os.Exit(1) } os.Exit(0) diff --git a/tests/fixture/ephnet/common.go b/tests/fixture/tmpnet/common.go similarity index 98% rename from tests/fixture/ephnet/common.go rename to tests/fixture/tmpnet/common.go index 385575b9a402..4b0281f45242 100644 --- a/tests/fixture/ephnet/common.go +++ b/tests/fixture/tmpnet/common.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package ephnet +package tmpnet import ( "context" diff --git a/tests/fixture/ephnet/config.go b/tests/fixture/tmpnet/config.go similarity index 99% rename from tests/fixture/ephnet/config.go rename to tests/fixture/tmpnet/config.go index 471c2fab2408..f504eb84d20d 100644 --- a/tests/fixture/ephnet/config.go +++ b/tests/fixture/tmpnet/config.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package ephnet +package tmpnet import ( "encoding/base64" diff --git a/tests/fixture/ephnet/interfaces.go b/tests/fixture/tmpnet/interfaces.go similarity index 97% rename from tests/fixture/ephnet/interfaces.go rename to tests/fixture/tmpnet/interfaces.go index 214f693c9ee9..2fd03cbc2a98 100644 --- a/tests/fixture/ephnet/interfaces.go +++ b/tests/fixture/tmpnet/interfaces.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package ephnet +package tmpnet import ( "context" diff --git a/tests/fixture/ephnet/local/README.md b/tests/fixture/tmpnet/local/README.md similarity index 87% rename from tests/fixture/ephnet/local/README.md rename to tests/fixture/tmpnet/local/README.md index 2634364cdd13..91af35a9b805 100644 --- a/tests/fixture/ephnet/local/README.md +++ b/tests/fixture/tmpnet/local/README.md @@ -4,7 +4,7 @@ This package implements a simple orchestrator for the avalanchego nodes of a local network. Configuration is stored on disk, and nodes run as independent processes whose process details are also written to disk. Using the filesystem to store configuration and process details -allows for the `ephnetctl` cli and e2e test fixture to orchestrate +allows for the `tmpnetctl` cli and e2e test fixture to orchestrate the same local networks without the use of an rpc daemon. ## Package details @@ -27,34 +27,34 @@ abstractions. ## Usage -### Via ephnetctl +### Via tmpnetctl -A local network can be managed by the `ephnetctl` cli tool: +A local network can be managed by the `tmpnetctl` cli tool: ```bash # From the root of the avalanchego repo -# Build the ephnetctl binary -$ ./scripts/build_ephnetctl.sh +# Build the tmpnetctl binary +$ ./scripts/build_tmpnetctl.sh # Start a new network -$ ./build/ephnetctl start-network --avalanchego-path=/path/to/avalanchego +$ ./build/tmpnetctl start-network --avalanchego-path=/path/to/avalanchego ... -Started network 1000 @ /home/me/.ephnet/networks/1000 +Started network 1000 @ /home/me/.tmpnet/networks/1000 -Configure ephnetctl 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 +Configure tmpnetctl to target this network by default with one of the following statements: + - source /home/me/.tmpnet/networks/1000/network.env + - export TMPNET_NETWORK_DIR=/home/me/.tmpnet/networks/1000 + - export TMPNET_NETWORK_DIR=/home/me/.tmpnet/networks/latest # Stop the network -$ ./build/ephnetctl stop-network --network-dir=/path/to/network +$ ./build/tmpnetctl stop-network --network-dir=/path/to/network ``` Note the export of the path ending in `latest`. This is a symlink that -is set to the last network created by `ephnetctl start-network`. Setting -the `EPHNET_NETWORK_DIR` env var to this symlink ensures that -`ephnetctl` commands and e2e execution with +is set to the last network created by `tmpnetctl start-network`. Setting +the `TMPNET_NETWORK_DIR` env var to this symlink ensures that +`tmpnetctl` commands and e2e execution with `--use-existing-network` will target the most recently deployed local network. @@ -66,7 +66,7 @@ A local network can be managed in code: network, _ := local.StartNetwork( ctx, // Context used to limit duration of waiting for network health ginkgo.GinkgoWriter, // Writer to report progress of network start - "", // Use default root dir (~/.ephnet) + "", // Use default root dir (~/.tmpnet) &local.LocalNetwork{ LocalConfig: local.LocalConfig{ ExecPath: "/path/to/avalanchego", // Defining the avalanchego exec path is required @@ -121,7 +121,7 @@ tests](../../../e2e/e2e_test.go). By default, nodes in a local network will be started with staking and API ports set to `0` to ensure that ports will be dynamically -chosen. The ephnet fixture discovers the ports used by a given node +chosen. The tmpnet fixture discovers the ports used by a given node by reading the `[base-data-dir]/process.json` file written by avalanchego on node start. The use of dynamic ports supports testing with many local networks without having to manually select compatible @@ -133,7 +133,7 @@ A local network relies on configuration written to disk in the following structu ``` HOME -└── .ephnet // Root path for the ephemeral network fixture +└── .tmpnet // Root path for the temporary network fixture └── networks // Default parent directory for local networks └── 1000 // The networkID is used to name the network dir and starts at 1000 ├── NodeID-37E8UK3x2YFsHE3RdALmfWcppcZ1eTuj9 // The ID of a node is the name of its data dir @@ -189,10 +189,10 @@ TODO(marun) Enable configuration of X-Chain and P-Chain. ### Network env -A shell script that sets the `EPHNET_NETWORK_DIR` env var to the +A shell script that sets the `TMPNET_NETWORK_DIR` env var to the path of the network is stored at `[network-dir]/network.env`. Sourcing this file (i.e. `source network.env`) in a shell will configure ginkgo -e2e and the `ephnetctl` cli to target the network path specified in +e2e and the `tmpnetctl` cli to target the network path specified in the env var. ### Node configuration diff --git a/tests/fixture/ephnet/local/config.go b/tests/fixture/tmpnet/local/config.go similarity index 80% rename from tests/fixture/ephnet/local/config.go rename to tests/fixture/tmpnet/local/config.go index 462cd30cd7cd..70ef9a443185 100644 --- a/tests/fixture/ephnet/local/config.go +++ b/tests/fixture/tmpnet/local/config.go @@ -7,15 +7,15 @@ import ( "time" "github.com/ava-labs/avalanchego/config" - "github.com/ava-labs/avalanchego/tests/fixture/ephnet" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" ) const ( // Constants defining the names of shell variables whose value can // configure local network orchestration. AvalancheGoPathEnvName = "AVALANCHEGO_PATH" - NetworkDirEnvName = "EPHNET_NETWORK_DIR" - RootDirEnvName = "EPHNET_ROOT_DIR" + NetworkDirEnvName = "TMPNET_NETWORK_DIR" + RootDirEnvName = "TMPNET_ROOT_DIR" DefaultNetworkStartTimeout = 2 * time.Minute DefaultNodeInitTimeout = 10 * time.Second @@ -23,9 +23,9 @@ const ( ) // A set of flags appropriate for local testing. -func LocalFlags() ephnet.FlagsMap { +func LocalFlags() tmpnet.FlagsMap { // Supply only non-default configuration to ensure that default values will be used. - return ephnet.FlagsMap{ + return tmpnet.FlagsMap{ config.NetworkPeerListGossipFreqKey: "250ms", config.NetworkMaxReconnectDelayKey: "1s", config.PublicIPKey: "127.0.0.1", @@ -37,16 +37,16 @@ func LocalFlags() ephnet.FlagsMap { config.IndexEnabledKey: true, config.LogDisplayLevelKey: "INFO", config.LogLevelKey: "DEBUG", - config.MinStakeDurationKey: ephnet.DefaultMinStakeDuration.String(), + config.MinStakeDurationKey: tmpnet.DefaultMinStakeDuration.String(), } } // C-Chain config for local testing. -func LocalCChainConfig() ephnet.FlagsMap { +func LocalCChainConfig() tmpnet.FlagsMap { // Supply only non-default configuration to ensure that default // values will be used. Available C-Chain configuration options are // defined in the `github.com/ava-labs/coreth/evm` package. - return ephnet.FlagsMap{ + return tmpnet.FlagsMap{ "log-level": "trace", } } diff --git a/tests/fixture/ephnet/local/network.go b/tests/fixture/tmpnet/local/network.go similarity index 95% rename from tests/fixture/ephnet/local/network.go rename to tests/fixture/tmpnet/local/network.go index 2a4f9d01f335..70411d4afcde 100644 --- a/tests/fixture/ephnet/local/network.go +++ b/tests/fixture/tmpnet/local/network.go @@ -18,7 +18,7 @@ import ( "github.com/ava-labs/avalanchego/config" "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/tests/fixture/ephnet" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/perms" @@ -48,7 +48,7 @@ func GetDefaultRootDir() (string, error) { if err != nil { return "", err } - return filepath.Join(homeDir, ".ephnet", "networks"), nil + return filepath.Join(homeDir, ".tmpnet", "networks"), nil } // Find the next available network ID by attempting to create a @@ -83,7 +83,7 @@ func FindNextNetworkID(rootDir string) (uint32, string, error) { // Defines the configuration required for a local network (i.e. one composed of local processes). type LocalNetwork struct { - ephnet.NetworkConfig + tmpnet.NetworkConfig LocalConfig // Nodes with local configuration @@ -94,13 +94,13 @@ type LocalNetwork struct { } // Returns the configuration of the network in backend-agnostic form. -func (ln *LocalNetwork) GetConfig() ephnet.NetworkConfig { +func (ln *LocalNetwork) GetConfig() tmpnet.NetworkConfig { return ln.NetworkConfig } // Returns the nodes of the network in backend-agnostic form. -func (ln *LocalNetwork) GetNodes() []ephnet.Node { - nodes := make([]ephnet.Node, 0, len(ln.Nodes)) +func (ln *LocalNetwork) GetNodes() []tmpnet.Node { + nodes := make([]tmpnet.Node, 0, len(ln.Nodes)) for _, node := range ln.Nodes { nodes = append(nodes, node) } @@ -108,12 +108,12 @@ func (ln *LocalNetwork) GetNodes() []ephnet.Node { } // Adds a backend-agnostic ephemeral node to the network -func (ln *LocalNetwork) AddEphemeralNode(w io.Writer, flags ephnet.FlagsMap) (ephnet.Node, error) { +func (ln *LocalNetwork) AddEphemeralNode(w io.Writer, flags tmpnet.FlagsMap) (tmpnet.Node, error) { if flags == nil { - flags = ephnet.FlagsMap{} + flags = tmpnet.FlagsMap{} } return ln.AddLocalNode(w, &LocalNode{ - NodeConfig: ephnet.NodeConfig{ + NodeConfig: tmpnet.NodeConfig{ Flags: flags, }, }, true /* isEphemeral */) @@ -298,7 +298,7 @@ func (ln *LocalNetwork) PopulateNodeConfig(node *LocalNode, nodeParentDir string // Set values common to all nodes flags.SetDefaults(ln.DefaultFlags) - flags.SetDefaults(ephnet.FlagsMap{ + flags.SetDefaults(tmpnet.FlagsMap{ config.GenesisFileKey: ln.GetGenesisPath(), config.ChainConfigDirKey: ln.GetChainConfigDir(), }) @@ -385,7 +385,7 @@ func (ln *LocalNetwork) WaitForHealthy(ctx context.Context, w io.Writer) error { } healthy, err := node.IsHealthy(ctx) - if err != nil && !errors.Is(err, ephnet.ErrNotRunning) { + if err != nil && !errors.Is(err, tmpnet.ErrNotRunning) { return err } if !healthy { @@ -409,14 +409,14 @@ func (ln *LocalNetwork) WaitForHealthy(ctx context.Context, w io.Writer) error { // Retrieve API URIs for all running primary validator nodes. URIs for // ephemeral nodes are not returned. -func (ln *LocalNetwork) GetURIs() []ephnet.NodeURI { - uris := make([]ephnet.NodeURI, 0, len(ln.Nodes)) +func (ln *LocalNetwork) GetURIs() []tmpnet.NodeURI { + uris := make([]tmpnet.NodeURI, 0, len(ln.Nodes)) for _, node := range ln.Nodes { // Only append URIs that are not empty. A node may have an // empty URI if it was not running at the time // node.ReadProcessContext() was called. if len(node.URI) > 0 { - uris = append(uris, ephnet.NodeURI{ + uris = append(uris, tmpnet.NodeURI{ NodeID: node.NodeID, URI: node.URI, }) @@ -458,7 +458,7 @@ func (ln *LocalNetwork) ReadGenesis() error { } func (ln *LocalNetwork) WriteGenesis() error { - bytes, err := ephnet.DefaultJSONMarshal(ln.Genesis) + bytes, err := tmpnet.DefaultJSONMarshal(ln.Genesis) if err != nil { return fmt.Errorf("failed to marshal genesis: %w", err) } @@ -477,7 +477,7 @@ func (ln *LocalNetwork) GetCChainConfigPath() string { } func (ln *LocalNetwork) ReadCChainConfig() error { - chainConfig, err := ephnet.ReadFlagsMap(ln.GetCChainConfigPath(), "C-Chain config") + chainConfig, err := tmpnet.ReadFlagsMap(ln.GetCChainConfigPath(), "C-Chain config") if err != nil { return err } @@ -496,7 +496,7 @@ func (ln *LocalNetwork) WriteCChainConfig() error { // Used to marshal/unmarshal persistent local network defaults. type localDefaults struct { - Flags ephnet.FlagsMap + Flags tmpnet.FlagsMap ExecPath string FundedKeys []*secp256k1.PrivateKey } @@ -526,7 +526,7 @@ func (ln *LocalNetwork) WriteDefaults() error { ExecPath: ln.ExecPath, FundedKeys: ln.FundedKeys, } - bytes, err := ephnet.DefaultJSONMarshal(defaults) + bytes, err := tmpnet.DefaultJSONMarshal(defaults) if err != nil { return fmt.Errorf("failed to marshal defaults: %w", err) } diff --git a/tests/fixture/ephnet/local/network_test.go b/tests/fixture/tmpnet/local/network_test.go similarity index 100% rename from tests/fixture/ephnet/local/network_test.go rename to tests/fixture/tmpnet/local/network_test.go diff --git a/tests/fixture/ephnet/local/node.go b/tests/fixture/tmpnet/local/node.go similarity index 95% rename from tests/fixture/ephnet/local/node.go rename to tests/fixture/tmpnet/local/node.go index 11fd20fed79c..908d3fd5f474 100644 --- a/tests/fixture/ephnet/local/node.go +++ b/tests/fixture/tmpnet/local/node.go @@ -23,7 +23,7 @@ import ( "github.com/ava-labs/avalanchego/config" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/node" - "github.com/ava-labs/avalanchego/tests/fixture/ephnet" + "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" "github.com/ava-labs/avalanchego/utils/perms" ) @@ -42,7 +42,7 @@ type LocalConfig struct { // Stores the configuration and process details of a node in a local network. type LocalNode struct { - ephnet.NodeConfig + tmpnet.NodeConfig LocalConfig node.NodeProcessContext @@ -51,8 +51,8 @@ type LocalNode struct { func NewLocalNode(dataDir string) *LocalNode { return &LocalNode{ - NodeConfig: ephnet.NodeConfig{ - Flags: ephnet.FlagsMap{ + NodeConfig: tmpnet.NodeConfig{ + Flags: tmpnet.FlagsMap{ config.DataDirKey: dataDir, }, }, @@ -76,7 +76,7 @@ func (n *LocalNode) GetID() ids.NodeID { } // Retrieve backend-agnostic node configuration. -func (n *LocalNode) GetConfig() ephnet.NodeConfig { +func (n *LocalNode) GetConfig() tmpnet.NodeConfig { return n.NodeConfig } @@ -98,11 +98,11 @@ func (n *LocalNode) ReadConfig() error { if err != nil { return fmt.Errorf("failed to read local node config: %w", err) } - flags := ephnet.FlagsMap{} + flags := tmpnet.FlagsMap{} if err := json.Unmarshal(bytes, &flags); err != nil { return fmt.Errorf("failed to unmarshal local node config: %w", err) } - config := ephnet.NodeConfig{Flags: flags} + config := tmpnet.NodeConfig{Flags: flags} if err := config.EnsureNodeID(); err != nil { return err } @@ -115,7 +115,7 @@ func (n *LocalNode) WriteConfig() error { return fmt.Errorf("failed to create node dir: %w", err) } - bytes, err := ephnet.DefaultJSONMarshal(n.Flags) + bytes, err := tmpnet.DefaultJSONMarshal(n.Flags) if err != nil { return fmt.Errorf("failed to marshal local node config: %w", err) } @@ -265,7 +265,7 @@ func (n *LocalNode) Stop() error { } // Wait for the node process to stop - ticker := time.NewTicker(ephnet.DefaultNodeTickerInterval) + ticker := time.NewTicker(tmpnet.DefaultNodeTickerInterval) defer ticker.Stop() ctx, cancel := context.WithTimeout(context.Background(), DefaultNodeStopTimeout) defer cancel() @@ -295,7 +295,7 @@ func (n *LocalNode) IsHealthy(ctx context.Context) (bool, error) { return false, fmt.Errorf("failed to determine process status: %w", err) } if proc == nil { - return false, ephnet.ErrNotRunning + return false, tmpnet.ErrNotRunning } // Check that the node is reporting healthy @@ -321,7 +321,7 @@ func (n *LocalNode) IsHealthy(ctx context.Context) (bool, error) { } func (n *LocalNode) WaitForProcessContext(ctx context.Context) error { - ticker := time.NewTicker(ephnet.DefaultNodeTickerInterval) + ticker := time.NewTicker(tmpnet.DefaultNodeTickerInterval) defer ticker.Stop() ctx, cancel := context.WithTimeout(ctx, DefaultNodeInitTimeout) diff --git a/tests/fixture/ephnet/local/node_test.go b/tests/fixture/tmpnet/local/node_test.go similarity index 100% rename from tests/fixture/ephnet/local/node_test.go rename to tests/fixture/tmpnet/local/node_test.go