Skip to content

Commit 5c01cfa

Browse files
committed
e2e: Switch from ANR to testnet fixture
1 parent 30e0b72 commit 5c01cfa

File tree

17 files changed

+447
-592
lines changed

17 files changed

+447
-592
lines changed

scripts/tests.e2e.persistent.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ if ! [[ "$0" =~ scripts/tests.e2e.persistent.sh ]]; then
1616
exit 255
1717
fi
1818

19-
export AVALANCHEGO_PATH="${1-${AVALANCHEGO_PATH}}"
19+
AVALANCHEGO_PATH="${1-${AVALANCHEGO_PATH}}"
2020
if [[ -z "${AVALANCHEGO_PATH}" ]]; then
2121
echo "Missing AVALANCHEGO_PATH argument!"
2222
echo "Usage: ${0} [AVALANCHEGO_PATH]" >>/dev/stderr
2323
exit 255
2424
fi
25+
export AVALANCHEGO_PATH="$(realpath ${AVALANCHEGO_PATH})"
2526

2627
# Create a temporary directory to store persistent network
2728
ROOT_DIR="$(mktemp -d -t e2e-testnet.XXXXX)"
@@ -52,4 +53,6 @@ else
5253
fi
5354

5455
echo "───────────────────────────────────────────────────────────────────────────────────────────────────────────────"
55-
# TODO(marun) Enable e2e testing
56+
# Setting E2E_USE_PERSISTENT_NETWORK configures tests.e2e.sh to use
57+
# the persistent network identified by TESTNETCTL_NETWORK_DIR.
58+
E2E_USE_PERSISTENT_NETWORK=1 ./scripts/tests.e2e.sh

scripts/tests.e2e.sh

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,7 @@ if ! [[ "$0" =~ scripts/tests.e2e.sh ]]; then
1111
exit 255
1212
fi
1313

14-
AVALANCHEGO_PATH="${1-}"
15-
if [[ -z "${AVALANCHEGO_PATH}" ]]; then
16-
echo "Missing AVALANCHEGO_PATH argument!"
17-
echo "Usage: ${0} [AVALANCHEGO_PATH]" >>/dev/stderr
18-
exit 255
19-
fi
20-
2114
#################################
22-
echo "installing avalanche-network-runner"
23-
ANR_WORKDIR="/tmp"
24-
./scripts/install_anr.sh
25-
2615
# Sourcing constants.sh ensures that the necessary CGO flags are set to
2716
# build the portable version of BLST. Without this, ginkgo may fail to
2817
# build the test binary if run on a host (e.g. github worker) that lacks
@@ -37,27 +26,29 @@ ACK_GINKGO_RC=true ginkgo build ./tests/e2e
3726
./tests/e2e/e2e.test --help
3827

3928
#################################
40-
# run "avalanche-network-runner" server
41-
echo "launch avalanche-network-runner in the background"
42-
$ANR_WORKDIR/avalanche-network-runner \
43-
server \
44-
--log-level debug \
45-
--port=":12342" \
46-
--disable-grpc-gateway &
47-
PID=${!}
29+
E2E_USE_PERSISTENT_NETWORK="${E2E_USE_PERSISTENT_NETWORK:-}"
30+
TESTNETCTL_NETWORK_DIR="${TESTNETCTL_NETWORK_DIR:-}"
31+
if [[ -n "${E2E_USE_PERSISTENT_NETWORK}" && -n "${TESTNETCTL_NETWORK_DIR}" ]]; then
32+
echo "running e2e tests against a persistent network configured at ${TESTNETCTL_NETWORK_DIR}"
33+
E2E_ARGS="--use-persistent-network"
34+
else
35+
AVALANCHEGO_PATH="${1-}"
36+
if [[ -z "${AVALANCHEGO_PATH}" ]]; then
37+
echo "Missing AVALANCHEGO_PATH argument!"
38+
echo "Usage: ${0} [AVALANCHEGO_PATH]" >>/dev/stderr
39+
exit 255
40+
fi
41+
echo "running e2e tests against an ephemeral local cluster deployed with ${AVALANCHEGO_PATH}"
42+
AVALANCHEGO_PATH="$(realpath ${AVALANCHEGO_PATH})"
43+
E2E_ARGS="--avalanchego-path=${AVALANCHEGO_PATH}"
44+
fi
4845

4946
#################################
50-
echo "running e2e tests against the local cluster with ${AVALANCHEGO_PATH}"
51-
./tests/e2e/e2e.test \
52-
--ginkgo.v \
53-
--log-level debug \
54-
--network-runner-grpc-endpoint="0.0.0.0:12342" \
55-
--network-runner-avalanchego-path=${AVALANCHEGO_PATH} \
56-
--network-runner-avalanchego-log-level="WARN" \
57-
--test-keys-file=tests/test.insecure.secp256k1.keys &&
58-
EXIT_CODE=$? || EXIT_CODE=$?
59-
60-
kill ${PID}
47+
# - Execute in parallel (-p) with the ginkgo cli to minimize execution time.
48+
# The test binary by itself isn't capable of running specs in parallel.
49+
# - Execute in random order to identify unwanted dependency
50+
ginkgo -p -v --randomize-all ./tests/e2e/e2e.test -- ${E2E_ARGS} \
51+
&& EXIT_CODE=$? || EXIT_CODE=$?
6152

6253
if [[ ${EXIT_CODE} -gt 0 ]]; then
6354
echo "FAILURE with exit code ${EXIT_CODE}"

tests/e2e/README.md

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Avalanche e2e test suites
22

3-
- Works for any environments (e.g., local, test network).
3+
- Works with fixture-managed networks.
44
- Compiles to a single binary with customizable configurations.
55

66
## Running tests
@@ -11,7 +11,6 @@ ACK_GINKGO_RC=true ginkgo build ./tests/e2e
1111
./tests/e2e/e2e.test --help
1212

1313
./tests/e2e/e2e.test \
14-
--network-runner-grpc-endpoint="0.0.0.0:12340" \
1514
--avalanchego-path=./build/avalanchego
1615
```
1716

@@ -29,8 +28,51 @@ Create a new package to implement feature-specific tests, or add tests to an exi
2928
├── README.md
3029
├── e2e.go
3130
├── e2e_test.go
32-
└── ping
33-
└── suites.go
31+
└── x
32+
└── transfer.go
33+
└── virtuous.go
3434
```
3535

36-
`e2e.go` defines common configurations (e.g., network-runner client) for other test packages. `ping/suites.go` defines ping tests, annotated by `[Ping]`, which can be selected by `./tests/e2e/e2e.test --ginkgo.focus "\[Local\] \[Ping\]"`.
36+
`e2e.go` defines common configuration for other test
37+
packages. `x/transfer/virtuous.go` defines X-Chain transfer tests,
38+
labeled with `x`, which can be selected by `./tests/e2e/e2e.test
39+
--ginkgo.label-filter "x"`.
40+
41+
## Testing against a persistent network
42+
43+
By default, a new ephemeral test network will be started before each
44+
test run. When developing e2e tests, it may be helpful to create a
45+
persistent test network to test against. This can increase the speed
46+
of iteration by removing the requirement to start a new network for
47+
every invocation of the test under development.
48+
49+
To use a persistent network:
50+
51+
```bash
52+
# From the root of the avalanchego repo
53+
54+
# Build the testnetctl binary
55+
$ ./scripts/build_testnetctl.sh
56+
57+
# Start a new network
58+
$ ./build/testnetctl start-network --avalanchego-path=/path/to/avalanchego
59+
...
60+
Started network 1000 @ /home/me/.testnetctl/networks/1000
61+
62+
Configure testnetctl to target this network by default with one of the following statements:
63+
- source /home/me/.testnetctl/networks/1000/network.env
64+
- export TESTNETCTL_NETWORK_DIR=/home/me/.testnetctl/networks/1000
65+
- export TESTNETCTL_NETWORK_DIR=/Users/me/.testnetctl/networks/latest
66+
67+
# Start a new test run to use the persistent network
68+
ginkgo -v ./tests/e2e -- \
69+
--avalanchego-path=/path/to/avalanchego \
70+
--ginkgo-focus-file=[name of file containing test] \
71+
--use-persistent-network \
72+
--network-dir=/path/to/network
73+
74+
# Also possible to set the AVALANCHEGO_PATH env var instead of supplying --avalanchego-path
75+
# Also possible to set the TESTNETCTL_NETWORK_DIR env var instead of supplying --network-dir
76+
```
77+
78+
See the testnet fixture [README](../fixture/testnet/local/README.md) for more details.

tests/e2e/banff/suites.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/onsi/gomega"
1313

14-
"github.com/ava-labs/avalanchego/genesis"
1514
"github.com/ava-labs/avalanchego/ids"
1615
"github.com/ava-labs/avalanchego/tests"
1716
"github.com/ava-labs/avalanchego/tests/e2e"
@@ -28,23 +27,15 @@ var _ = ginkgo.Describe("[Banff]", func() {
2827
// use this for filtering tests by labels
2928
// ref. https://onsi.github.io/ginkgo/#spec-labels
3029
ginkgo.Label(
31-
"require-network-runner",
3230
"xp",
3331
"banff",
3432
),
3533
func() {
36-
ginkgo.By("reload initial snapshot for test independence", func() {
37-
err := e2e.Env.RestoreInitialState(true /*switchOffNetworkFirst*/)
38-
gomega.Expect(err).Should(gomega.BeNil())
39-
})
40-
41-
uris := e2e.Env.GetURIs()
42-
gomega.Expect(uris).ShouldNot(gomega.BeEmpty())
43-
44-
kc := secp256k1fx.NewKeychain(genesis.EWOQKey)
34+
key := e2e.Env.AllocateTestKeys(1)[0]
35+
kc := secp256k1fx.NewKeychain(key)
4536
var wallet primary.Wallet
4637
ginkgo.By("initialize wallet", func() {
47-
walletURI := uris[0]
38+
walletURI := e2e.Env.URIs[0]
4839

4940
// 5-second is enough to fetch initial UTXOs for test cluster in "primary.NewWallet"
5041
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultWalletCreationTimeout)
@@ -65,7 +56,7 @@ var _ = ginkgo.Describe("[Banff]", func() {
6556
owner := &secp256k1fx.OutputOwners{
6657
Threshold: 1,
6758
Addrs: []ids.ShortID{
68-
genesis.EWOQKey.PublicKey().Address(),
59+
key.Address(),
6960
},
7061
}
7162

tests/e2e/describe.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ func DescribeXChain(text string, body func()) bool {
1313
return ginkgo.Describe("[X-Chain] "+text, body)
1414
}
1515

16+
// DescribeXChainSerial annotates serial tests for X-Chain.
17+
// Can run with any type of cluster (e.g., local, fuji, mainnet).
18+
func DescribeXChainSerial(text string, body func()) bool {
19+
return ginkgo.Describe("[X-Chain] "+text, ginkgo.Serial, body)
20+
}
21+
1622
// DescribePChain annotates the tests for P-Chain.
1723
// Can run with any type of cluster (e.g., local, fuji, mainnet).
1824
func DescribePChain(text string, body func()) bool {

0 commit comments

Comments
 (0)