Skip to content

Commit a29c191

Browse files
committed
e2e: Add local network fixture
To better enable e2e test development, this changeset adds a new orchestration mechanism for local test networks. Nodes are launched as independent processes and all configuration is serialized to disk to avoid requiring a persistent rpc daemon. Please review the README changes for more details.
1 parent 60fff56 commit a29c191

File tree

23 files changed

+2270
-376
lines changed

23 files changed

+2270
-376
lines changed

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ require (
3939
github.com/rs/cors v1.7.0
4040
github.com/shirou/gopsutil v3.21.11+incompatible
4141
github.com/spaolacci/murmur3 v1.1.0
42+
github.com/spf13/cast v1.5.0
43+
github.com/spf13/cobra v1.0.0
4244
github.com/spf13/pflag v1.0.5
4345
github.com/spf13/viper v1.12.0
4446
github.com/stretchr/testify v1.8.1
@@ -101,6 +103,7 @@ require (
101103
github.com/hashicorp/hcl v1.0.0 // indirect
102104
github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e // indirect
103105
github.com/holiman/uint256 v1.2.0 // indirect
106+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
104107
github.com/klauspost/compress v1.15.15 // indirect
105108
github.com/kr/pretty v0.3.1 // indirect
106109
github.com/kr/text v0.2.0 // indirect
@@ -122,7 +125,6 @@ require (
122125
github.com/russross/blackfriday/v2 v2.1.0 // indirect
123126
github.com/sanity-io/litter v1.5.1 // indirect
124127
github.com/spf13/afero v1.8.2 // indirect
125-
github.com/spf13/cast v1.5.0 // indirect
126128
github.com/spf13/jwalterweatherman v1.1.0 // indirect
127129
github.com/status-im/keycard-go v0.2.0 // indirect
128130
github.com/subosito/gotenv v1.3.0 // indirect

go.sum

Lines changed: 64 additions & 0 deletions
Large diffs are not rendered by default.

scripts/tests.e2e.sh

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,6 @@ export CGO_CFLAGS="-O -D__BLST_PORTABLE__"
2727
# clear error due to the default value change in go1.20.
2828
export CGO_ENABLED=1
2929

30-
#################################
31-
# download avalanche-network-runner
32-
# https://github.com/ava-labs/avalanche-network-runner
33-
# TODO: migrate to upstream avalanche-network-runner
34-
GOARCH=$(go env GOARCH)
35-
GOOS=$(go env GOOS)
36-
NETWORK_RUNNER_VERSION=1.3.5-rc.0
37-
DOWNLOAD_PATH=/tmp/avalanche-network-runner.tar.gz
38-
DOWNLOAD_URL="https://github.com/ava-labs/avalanche-network-runner/releases/download/v${NETWORK_RUNNER_VERSION}/avalanche-network-runner_${NETWORK_RUNNER_VERSION}_${GOOS}_${GOARCH}.tar.gz"
39-
40-
rm -f ${DOWNLOAD_PATH}
41-
rm -f /tmp/avalanche-network-runner
42-
43-
echo "downloading avalanche-network-runner ${NETWORK_RUNNER_VERSION} at ${DOWNLOAD_URL} to ${DOWNLOAD_PATH}"
44-
curl --fail -L ${DOWNLOAD_URL} -o ${DOWNLOAD_PATH}
45-
46-
echo "extracting downloaded avalanche-network-runner"
47-
tar xzvf ${DOWNLOAD_PATH} -C /tmp
48-
/tmp/avalanche-network-runner -h
49-
5030
GOPATH="$(go env GOPATH)"
5131
PATH="${GOPATH}/bin:${PATH}"
5232

@@ -57,29 +37,14 @@ go install -v github.com/onsi/ginkgo/v2/ginkgo@v2.1.4
5737
ACK_GINKGO_RC=true ginkgo build ./tests/e2e
5838
./tests/e2e/e2e.test --help
5939

60-
#################################
61-
# run "avalanche-network-runner" server
62-
echo "launch avalanche-network-runner in the background"
63-
/tmp/avalanche-network-runner \
64-
server \
65-
--log-level debug \
66-
--port=":12342" \
67-
--disable-grpc-gateway &
68-
PID=${!}
69-
7040
#################################
7141
echo "running e2e tests against the local cluster with ${AVALANCHEGO_PATH}"
7242
./tests/e2e/e2e.test \
7343
--ginkgo.v \
74-
--log-level debug \
75-
--network-runner-grpc-endpoint="0.0.0.0:12342" \
76-
--network-runner-avalanchego-path=${AVALANCHEGO_PATH} \
77-
--network-runner-avalanchego-log-level="WARN" \
44+
--avalanchego-path=${AVALANCHEGO_PATH} \
7845
--test-keys-file=tests/test.insecure.secp256k1.keys \
7946
&& EXIT_CODE=$? || EXIT_CODE=$?
8047

81-
kill ${PID}
82-
8348
if [[ ${EXIT_CODE} -gt 0 ]]; then
8449
echo "FAILURE with exit code ${EXIT_CODE}"
8550
exit ${EXIT_CODE}

tests/e2e/README.md

Lines changed: 43 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 (currently only local, with kubernetes a future target)
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,47 @@ 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 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"`.
37+
38+
## Testing against a persistent network
39+
40+
By default, a new ephemeral test network will be started before each
41+
test run. When developing e2e tests, it may be helpful to create a
42+
persistent test network to test against. This can increase the speed
43+
of iteration by removing the requirement to start a new network for
44+
every invocation of the test under development.
45+
46+
To use a persistent network:
47+
48+
```bash
49+
# From the root of the avalanchego repo
50+
51+
# Build the avctl binary
52+
$ go build -o build/avctl ./tests/e2e/fixture/cmd/*.go && avctl start
53+
54+
# Start a new network
55+
$ ./build/avctl start-network --avalanchego-path=/path/to/avalanchego
56+
...
57+
Started network 1337 @ /home/me/.avctl/1337-20230705-213938-1707053131
58+
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
62+
63+
# Start a new test run to use the persistent network
64+
ginkgo build ./tests/e2e/ && \
65+
./tests/e2e/e2e.test \
66+
--avalanchego-path=/path/to/avalanchego \
67+
--test-keys-file=$PWD/tests/test.insecure.secp256k1.keys \
68+
--network-dir=/path/to/network \
69+
--ginkgo-focus-file=[name of file containing test] \
70+
--use-persistent-network
71+
72+
# 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
74+
```

tests/e2e/banff/suites.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,19 @@ import (
2424
)
2525

2626
var _ = ginkgo.Describe("[Banff]", func() {
27+
ginkgo.BeforeEach(func() {
28+
e2e.Env.EnsurePristineNetwork()
29+
})
30+
2731
ginkgo.It("can send custom assets X->P and P->X",
2832
// use this for filtering tests by labels
2933
// ref. https://onsi.github.io/ginkgo/#spec-labels
3034
ginkgo.Label(
31-
"require-network-runner",
3235
"xp",
3336
"banff",
3437
),
3538
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()
39+
uris := e2e.Env.GetURIsRW()
4240
gomega.Expect(uris).ShouldNot(gomega.BeEmpty())
4341

4442
kc := secp256k1fx.NewKeychain(genesis.EWOQKey)

0 commit comments

Comments
 (0)