Skip to content

Commit 91dd7c3

Browse files
committed
fixup Move fixture code out of e2e to enable unit test execution
Also rename avctl to testnetctl to avoid any confusion about its intended purpose.
1 parent 5f731a7 commit 91dd7c3

File tree

16 files changed

+93
-77
lines changed

16 files changed

+93
-77
lines changed

scripts/build_test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
99
# Load the constants
1010
source "$AVALANCHE_PATH"/scripts/constants.sh
1111

12-
go test -shuffle=on -race -timeout="120s" -coverprofile="coverage.out" -covermode="atomic" $(go list ./... | grep -v /mocks | grep -v proto | grep -v tests)
12+
# Ensure execution of fixture unit tests under tests/ but exclude ginkgo tests in tests/e2e and tests/upgrade
13+
go test -shuffle=on -race -timeout="120s" -coverprofile="coverage.out" -covermode="atomic" $(go list ./... | grep -v /mocks | grep -v proto | grep -v tests/e2e | grep -v tests/upgrade)

scripts/build_testnetctl.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
# Avalanchego root folder
8+
AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
9+
# Load the constants
10+
source "$AVALANCHE_PATH"/scripts/constants.sh
11+
12+
echo "Building testnetctl..."
13+
go build -ldflags\
14+
"-X github.com/ava-labs/avalanchego/version.GitCommit=$git_commit $static_ld_flags"\
15+
-o "$AVALANCHE_PATH/build/testnetctl"\
16+
"$AVALANCHE_PATH/tests/fixture/testnet/cmd/"*.go

tests/e2e/README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,26 @@ To use a persistent network:
4848
```bash
4949
# From the root of the avalanchego repo
5050

51-
# Build the avctl binary
52-
$ go build -o build/avctl ./tests/e2e/fixture/cmd/*.go && avctl start
51+
# Build the testnetctl binary
52+
$ scripts/build_testnetctl.sh
5353

5454
# Start a new network
55-
$ ./build/avctl start-network --avalanchego-path=/path/to/avalanchego
55+
$ ./build/testnetctl start-network --avalanchego-path=/path/to/avalanchego
5656
...
57-
Started network 1337 @ /home/me/.avctl/1337-20230705-213938-1707053131
57+
Started network 1337 @ /home/me/.testnetctl/1337-20230705-213938-1707053131
5858

59-
Configure avctl to target this network by default with one of the following statements:
60-
- source /home/me/.avctl/1337-20230705-213938-1707053131/network.env
61-
- export AVCTL_NETWORK_DIR=/home/me/.avctl/1337-20230705-213938-1707053131
59+
Configure testnetctl to target this network by default with one of the following statements:
60+
- source /home/me/.testnetctl/1337-20230705-213938-1707053131/network.env
61+
- export TESTNETCTL_NETWORK_DIR=/home/me/.testnetctl/1337-20230705-213938-1707053131
6262

6363
# Start a new test run to use the persistent network
64-
ginkgo build ./tests/e2e/ && \
65-
./tests/e2e/e2e.test \
64+
ginkgo -v ./tests/e2e -- \
6665
--avalanchego-path=/path/to/avalanchego \
6766
--test-keys-file=$PWD/tests/test.insecure.secp256k1.keys \
6867
--network-dir=/path/to/network \
6968
--ginkgo-focus-file=[name of file containing test] \
7069
--use-persistent-network
7170

7271
# Also possible to set the AVALANCHEGO_PATH env var instead of supplying --avalanchego-path
73-
# Also possible to set the AVCTL_NETWORK_DIR env var instead of supplying --network-dir
72+
# Also possible to set the TESTNETCTL_NETWORK_DIR env var instead of supplying --network-dir
7473
```

tests/e2e/e2e.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616

1717
"github.com/ava-labs/avalanchego/ids"
1818
"github.com/ava-labs/avalanchego/tests"
19-
"github.com/ava-labs/avalanchego/tests/e2e/fixture"
20-
"github.com/ava-labs/avalanchego/tests/e2e/fixture/local"
19+
"github.com/ava-labs/avalanchego/tests/fixture/testnet"
20+
"github.com/ava-labs/avalanchego/tests/fixture/testnet/local"
2121
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
2222
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
2323
)
@@ -279,6 +279,6 @@ func (te *TestEnvironment) Teardown() error {
279279
return nil
280280
}
281281

282-
func (te *TestEnvironment) GetNetwork() (fixture.Network, error) {
282+
func (te *TestEnvironment) GetNetwork() (testnet.Network, error) {
283283
return local.LoadNetwork(te.networkDir)
284284
}

tests/e2e/e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/onsi/gomega"
1515

1616
"github.com/ava-labs/avalanchego/tests/e2e"
17-
"github.com/ava-labs/avalanchego/tests/e2e/fixture/local"
17+
"github.com/ava-labs/avalanchego/tests/fixture/testnet/local"
1818

1919
// ensure test packages are scanned by ginkgo
2020
_ "github.com/ava-labs/avalanchego/tests/e2e/banff"

tests/e2e/fixture/README.md renamed to tests/fixture/testnet/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Network Fixture
1+
# Test Network Fixture
22

33
This package contains configuration and interfaces that are
44
independent of a given orchestration mechanism

tests/e2e/fixture/cmd/main.go renamed to tests/fixture/testnet/cmd/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import (
99

1010
"github.com/spf13/cobra"
1111

12-
"github.com/ava-labs/avalanchego/tests/e2e/fixture/local"
12+
"github.com/ava-labs/avalanchego/tests/fixture/testnet/local"
1313
)
1414

1515
func main() {
1616
var networkDir string
1717
var rootDir string
1818
rootCmd := &cobra.Command{
19-
Use: "avctl",
20-
Short: "avctl commands",
19+
Use: "testnetctl",
20+
Short: "testnetctl commands",
2121
}
2222
rootCmd.PersistentFlags().StringVar(&networkDir, "network-dir", os.Getenv(local.NetworkDirEnvName), "The path to the configuration directory of a local network")
2323
rootCmd.PersistentFlags().StringVar(&rootDir, "root-dir", os.Getenv(local.RootDirEnvName), "The path to the root directory for local networks")
@@ -46,7 +46,7 @@ func main() {
4646
return err
4747
}
4848

49-
fmt.Fprintf(os.Stdout, "\nConfigure avctl to target this network by default with one of the following statements:")
49+
fmt.Fprintf(os.Stdout, "\nConfigure testnetctl to target this network by default with one of the following statements:")
5050
fmt.Fprintf(os.Stdout, "\n - source %s\n", network.EnvFilePath())
5151
fmt.Fprintf(os.Stdout, " - %s\n", network.EnvFileContents())
5252

@@ -80,7 +80,7 @@ func main() {
8080
rootCmd.AddCommand(stopNetworkCmd)
8181

8282
if err := rootCmd.Execute(); err != nil {
83-
fmt.Fprintf(os.Stderr, "avctl failed %v\n", err)
83+
fmt.Fprintf(os.Stderr, "testnetctl failed %v\n", err)
8484
os.Exit(1)
8585
}
8686
os.Exit(0)

tests/e2e/fixture/config.go renamed to tests/fixture/testnet/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
22
// See the file LICENSE for licensing terms.
33

4-
package fixture
4+
package testnet
55

66
import (
77
"encoding/base64"
@@ -80,7 +80,7 @@ func (c *NetworkConfig) PopulateNetworkConfig(networkID uint32, validatorIDs []i
8080
// - Randomly generate the network id (making sure it isn't a reserved ID)
8181
// - Use only the network id (without a datetime suffix) on the filesystem
8282
// - Support referring to a network by just the id against a default path
83-
// - e.g. ~/.avctl/[network id]
83+
// - e.g. ~/.testnetctl/[network id]
8484
networkID = uint32(1337)
8585
}
8686

tests/e2e/fixture/interfaces.go renamed to tests/fixture/testnet/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
22
// See the file LICENSE for licensing terms.
33

4-
package fixture
4+
package testnet
55

66
import "github.com/ava-labs/avalanchego/ids"
77

tests/e2e/fixture/local/README.md renamed to tests/fixture/testnet/local/README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ This package implements a simple orchestrator for the avalanchego
44
nodes of a local network. Configuration is stored on disk, and nodes
55
run as independent processes whose runtime state is also written to
66
disk. Using persistent storage for configuration and runtime state
7-
allows for both the avctl cli tool and e2e test fixture to orchestrate
8-
the local networks without the use of an rpc daemon.
7+
allows for both the testnetctl cli tool and e2e test fixture to
8+
orchestrate the local networks without the use of an rpc daemon.
99

1010
## Package details
1111

@@ -27,27 +27,27 @@ shared configuration abstractions without complication.
2727

2828
## Usage
2929

30-
### Via avctl
30+
### Via testnetctl
3131

32-
A local network can be managed by the avctl cli tool:
32+
A local network can be managed by the testnetctl cli tool:
3333

3434
```bash
3535
# From the root of the avalanchego repo
3636

37-
# Build the avctl binary
38-
$ go build -o build/avctl ./tests/e2e/fixture/cmd/*.go
37+
# Build the testnetctl binary
38+
$ scripts/build_testnetctl.sh
3939

4040
# Start a new network
41-
$ ./build/avctl start-network --avalanchego-path=/path/to/avalanchego
41+
$ ./build/testnetctl start-network --avalanchego-path=/path/to/avalanchego
4242
...
43-
Started network 1337 @ /home/me/.avctl/1337-20230705-213938-1707053131
43+
Started network 1337 @ /home/me/.testnetctl/1337-20230705-213938-1707053131
4444

45-
Configure avctl to target this network by default with one of the following statements:
46-
- source /home/me/.avctl/1337-20230705-213938-1707053131/network.env
47-
- export AVCTL_NETWORK_DIR=/home/me/.avctl/1337-20230705-213938-1707053131
45+
Configure testnetctl to target this network by default with one of the following statements:
46+
- source /home/me/.testnetctl/1337-20230705-213938-1707053131/network.env
47+
- export TESTNETCTL_NETWORK_DIR=/home/me/.testnetctl/1337-20230705-213938-1707053131
4848

4949
# Stop the network
50-
$ ./build/avctl stop-network --network-dir=/path/to/network
50+
$ ./build/testnetctl stop-network --network-dir=/path/to/network
5151
```
5252

5353
### Via code
@@ -57,7 +57,7 @@ A local network can be managed in code:
5757
```golang
5858
network, _ := local.StartNetwork(
5959
ginkgo.GinkgoWriter,
60-
"", // Use default root dir (~/.avctl)
60+
"", // Use default root dir (~/.testnetctl)
6161
&local.LocalNetwork{
6262
LocalConfig: local.LocalConfig{
6363
ExecPath: "/path/to/avalanchego", // Defining the avalanchego exec path is required
@@ -82,7 +82,7 @@ configuration and by supplying a nodeCount argument of `0`:
8282
```golang
8383
network, _ := local.StartNetwork(
8484
ginkgo.GinkgoWriter,
85-
"", // Use default root dir (~/.avctl)
85+
"", // Use default root dir (~/.testnetctl)
8686
&local.LocalNetwork{
8787
LocalConfig: local.LocalConfig{
8888
ExecPath: "/path/to/avalanchego", // Default avalanchego path
@@ -121,7 +121,7 @@ A local network relies on configuration written to disk in the following structu
121121

122122
```
123123
HOME
124-
└── .avctl // Default parent directory for local networks
124+
└── .testnetctl // Default parent directory for local networks
125125
└── 1337-20230630-203525-2336789419 // Network path with form [network-id]-[timestamp]
126126
├── NodeID-37E8UK3x2YFsHE3RdALmfWcppcZ1eTuj9 // The id of a node is the name of its data dir
127127
│ ├── chainData
@@ -171,11 +171,11 @@ at `[chain-config-dir]/C/cchain_config.json`.
171171

172172
### Network env
173173

174-
A shell script that sets the `AVCTL_NETWORK_DIR` env var to the path
175-
of the network is stored at `[network-dir]/network.env`. Sourcing this
176-
file (i.e. `. network.env`) in a shell will configure ginkgo e2e and
177-
the avctl command to implicitly target the network path specified in
178-
the env var.
174+
A shell script that sets the `TESTNETCTL_NETWORK_DIR` env var to the
175+
path of the network is stored at `[network-dir]/network.env`. Sourcing
176+
this file (i.e. `. network.env`) in a shell will configure ginkgo e2e
177+
and the testnetctl command to implicitly target the network path
178+
specified in the env var.
179179

180180
### Node configuration
181181

0 commit comments

Comments
 (0)