Skip to content

Commit d84f60a

Browse files
author
Tony Zhang
committed
Adding localnetwork e2e tests: start\status\clean
1 parent 9194d3c commit d84f60a

File tree

20 files changed

+206
-33
lines changed

20 files changed

+206
-33
lines changed

tests/e2e/commands/network.go

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import (
77
"fmt"
88
"os"
99
"os/exec"
10+
"strconv"
1011

1112
"github.com/ava-labs/avalanche-cli/pkg/constants"
1213
"github.com/ava-labs/avalanche-cli/tests/e2e/utils"
1314
"github.com/onsi/gomega"
1415
)
1516

1617
/* #nosec G204 */
17-
func CleanNetwork() {
18+
func CleanNetwork() (string, error) {
1819
cmd := exec.Command(
1920
CLIBinary,
2021
NetworkCmd,
@@ -27,7 +28,7 @@ func CleanNetwork() {
2728
fmt.Println(string(output))
2829
utils.PrintStdErr(err)
2930
}
30-
gomega.Expect(err).Should(gomega.BeNil())
31+
return string(output), err
3132
}
3233

3334
/* #nosec G204 */
@@ -53,17 +54,42 @@ func StartNetwork() string {
5354
return StartNetworkWithVersion("")
5455
}
5556

57+
func StartNetworkWithNodeNumber(numOfNodes uint) string {
58+
return startNetworkWithParams(map[string]string{
59+
"number-of-nodes": strconv.FormatUint(uint64(numOfNodes), 10),
60+
})
61+
}
62+
5663
/* #nosec G204 */
5764
func StartNetworkWithVersion(version string) string {
65+
return startNetworkWithParams(map[string]string{
66+
"version": version,
67+
})
68+
}
69+
70+
func startNetworkWithParams(paramMap map[string]string) string {
5871
cmdArgs := []string{NetworkCmd, "start"}
5972
cmdArgs = append(cmdArgs, "--"+constants.SkipUpdateFlag)
60-
if version != "" {
61-
cmdArgs = append(
62-
cmdArgs,
63-
"--avalanchego-version",
64-
version,
65-
)
73+
74+
for k, v := range paramMap {
75+
switch k {
76+
case "version":
77+
if v != "" {
78+
cmdArgs = append(
79+
cmdArgs,
80+
"--avalanchego-version",
81+
v,
82+
)
83+
}
84+
case "number-of-nodes":
85+
cmdArgs = append(
86+
cmdArgs,
87+
"--num-nodes",
88+
v,
89+
)
90+
}
6691
}
92+
6793
// in case we want to use specific avago for local tests
6894
debugAvalanchegoPath := os.Getenv(constants.E2EDebugAvalancheGoPath)
6995
if debugAvalanchegoPath != "" {

tests/e2e/commandse2e/blockchain/deploy/suite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var _ = ginkgo.Describe("[Blockchain Deploy Flags]", ginkgo.Ordered, func() {
2424
})
2525

2626
ginkgo.AfterEach(func() {
27-
commands.CleanNetwork()
27+
_, _ = commands.CleanNetwork()
2828
// Cleanup test subnet config
2929
commands.DeleteSubnetConfig(subnetName)
3030
})

tests/e2e/e2e_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import (
1818
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/key/list"
1919
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/key/transfer"
2020
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/network"
21+
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/network/clean"
22+
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/network/start"
23+
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/network/status"
2124
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/network/stop"
2225
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/node/create"
2326
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/node/devnet"

tests/e2e/testcases/errhandling/suite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
*/
2626
var _ = ginkgo.Describe("[Error handling]", func() {
2727
ginkgo.AfterEach(func() {
28-
commands.CleanNetwork()
28+
_, _ = commands.CleanNetwork()
2929
err := utils.DeleteConfigs(subnetName)
3030
if err != nil {
3131
fmt.Println("Clean network error:", err)

tests/e2e/testcases/key/transfer/suite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var _ = ginkgo.Describe("[Key] transfer", func() {
3434
})
3535

3636
ginkgo.AfterEach(func() {
37-
commands.CleanNetwork()
37+
_, _ = commands.CleanNetwork()
3838
err := utils.DeleteConfigs(subnetName)
3939
gomega.Expect(err).Should(gomega.BeNil())
4040
utils.DeleteCustomBinary(subnetName)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2025, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package network
5+
6+
import (
7+
"github.com/ava-labs/avalanche-cli/tests/e2e/commands"
8+
ginkgo "github.com/onsi/ginkgo/v2"
9+
"github.com/onsi/gomega"
10+
)
11+
12+
var _ = ginkgo.Describe("[Local Network] Clean", ginkgo.Ordered, func() {
13+
ginkgo.It("can clean a started network", func() {
14+
out := commands.StartNetwork()
15+
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
16+
17+
out, err := commands.CleanNetwork()
18+
gomega.Expect(err).Should(gomega.BeNil())
19+
gomega.Expect(out).Should(gomega.ContainSubstring("Process terminated"))
20+
})
21+
22+
ginkgo.It("should err out when no network is running", func() {
23+
out, err := commands.CleanNetwork()
24+
gomega.Expect(err).Should(gomega.BeNil())
25+
gomega.Expect(out).Should(gomega.ContainSubstring("No network is running"))
26+
})
27+
})
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (C) 2025, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package network
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/ava-labs/avalanche-cli/tests/e2e/commands"
10+
ginkgo "github.com/onsi/ginkgo/v2"
11+
"github.com/onsi/gomega"
12+
)
13+
14+
var _ = ginkgo.Describe("[Local Network] Start", ginkgo.Ordered, func() {
15+
ginkgo.AfterEach(func() {
16+
err := commands.StopNetwork()
17+
gomega.Expect(err).Should(gomega.BeNil())
18+
_, _ = commands.CleanNetwork()
19+
})
20+
21+
ginkgo.It("can start network with default params", func() {
22+
out := commands.StartNetwork()
23+
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
24+
25+
// https://github.com/ava-labs/avalanchego/blob/master/tests/fixture/tmpnet/defaults.go#L27
26+
defaultNodeCount := 2
27+
28+
// check network status
29+
out, err := commands.GetNetworkStatus()
30+
gomega.Expect(err).Should(gomega.BeNil())
31+
gomega.Expect(out).Should(gomega.ContainSubstring("Network is Up"))
32+
gomega.Expect(out).Should(gomega.ContainSubstring(fmt.Sprintf("Number of Nodes: %d", defaultNodeCount)))
33+
gomega.Expect(out).Should(gomega.ContainSubstring("Network Healthy: true"))
34+
gomega.Expect(out).Should(gomega.ContainSubstring("Blockchains Healthy: true"))
35+
})
36+
37+
ginkgo.It("can start network with given number of nodes", func() {
38+
numOfNodes := uint(3)
39+
out := commands.StartNetworkWithNodeNumber(numOfNodes)
40+
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
41+
42+
// check network status
43+
out, err := commands.GetNetworkStatus()
44+
gomega.Expect(err).Should(gomega.BeNil())
45+
gomega.Expect(out).Should(gomega.ContainSubstring("Network is Up"))
46+
gomega.Expect(out).Should(gomega.ContainSubstring(fmt.Sprintf("Number of Nodes: %d", numOfNodes)))
47+
gomega.Expect(out).Should(gomega.ContainSubstring("Network Healthy: true"))
48+
gomega.Expect(out).Should(gomega.ContainSubstring("Blockchains Healthy: true"))
49+
})
50+
51+
ginkgo.It("should not start network with already started network", func() {
52+
out := commands.StartNetwork()
53+
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
54+
55+
out = commands.StartNetwork()
56+
gomega.Expect(out).Should(gomega.ContainSubstring("Network has already been booted"))
57+
58+
out, err := commands.GetNetworkStatus()
59+
gomega.Expect(err).Should(gomega.BeNil())
60+
gomega.Expect(out).Should(gomega.ContainSubstring("Network is Up"))
61+
})
62+
})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (C) 2025, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package network
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/ava-labs/avalanche-cli/tests/e2e/commands"
10+
ginkgo "github.com/onsi/ginkgo/v2"
11+
"github.com/onsi/gomega"
12+
)
13+
14+
var _ = ginkgo.Describe("[Local Network] Status", ginkgo.Ordered, func() {
15+
ginkgo.AfterEach(func() {
16+
_ = commands.StopNetwork()
17+
_, _ = commands.CleanNetwork()
18+
})
19+
20+
ginkgo.It("can get status of started network", func() {
21+
out := commands.StartNetwork()
22+
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
23+
24+
// https://github.com/ava-labs/avalanchego/blob/master/tests/fixture/tmpnet/defaults.go#L27
25+
defaultNodeCount := 2
26+
27+
// check network status
28+
out, err := commands.GetNetworkStatus()
29+
gomega.Expect(err).Should(gomega.BeNil())
30+
gomega.Expect(out).Should(gomega.ContainSubstring("Network is Up"))
31+
gomega.Expect(out).Should(gomega.ContainSubstring(fmt.Sprintf("Number of Nodes: %d", defaultNodeCount)))
32+
gomega.Expect(out).Should(gomega.ContainSubstring("Network Healthy: true"))
33+
gomega.Expect(out).Should(gomega.ContainSubstring("Blockchains Healthy: true"))
34+
})
35+
36+
ginkgo.It("can get status when no network is up", func() {
37+
out, err := commands.GetNetworkStatus()
38+
gomega.Expect(err).ShouldNot(gomega.BeNil())
39+
gomega.Expect(out).Should(gomega.ContainSubstring("network is not running"))
40+
})
41+
})

tests/e2e/testcases/network/stop/suite.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
"github.com/onsi/gomega"
1515
)
1616

17-
var _ = ginkgo.Describe("[Local Network]", ginkgo.Ordered, func() {
17+
var _ = ginkgo.Describe("[Local Network] Stop", ginkgo.Ordered, func() {
1818
ginkgo.AfterEach(func() {
19-
commands.CleanNetwork()
19+
_, _ = commands.CleanNetwork()
2020
})
2121

2222
ginkgo.It("can stop a started network", func() {

tests/e2e/testcases/network/suite.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const (
1818

1919
var _ = ginkgo.Describe("[Network]", ginkgo.Ordered, func() {
2020
ginkgo.AfterEach(func() {
21-
commands.CleanNetwork()
21+
_, _ = commands.CleanNetwork()
2222
err := utils.DeleteConfigs(subnetName)
2323
gomega.Expect(err).Should(gomega.BeNil())
2424
})
@@ -133,7 +133,8 @@ var _ = ginkgo.Describe("[Network]", ginkgo.Ordered, func() {
133133
gomega.Expect(len(plugins)).Should(gomega.Equal(1))
134134
gomega.Expect(err).Should(gomega.BeNil())
135135

136-
commands.CleanNetwork()
136+
_, err = commands.CleanNetwork()
137+
gomega.Expect(err).Should(gomega.BeNil())
137138

138139
// check that plugin binaries exist
139140
plugins, err = utils.GetPluginBinaries()

0 commit comments

Comments
 (0)