Skip to content

Commit 9f6828a

Browse files
author
Tony Zhang
committed
adding more test cases per feedback
1 parent b786ffb commit 9f6828a

File tree

2 files changed

+214
-0
lines changed

2 files changed

+214
-0
lines changed

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

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
package network
55

66
import (
7+
"fmt"
8+
9+
"github.com/ava-labs/avalanche-cli/cmd"
10+
"github.com/ava-labs/avalanche-cli/pkg/constants"
711
"github.com/ava-labs/avalanche-cli/tests/e2e/commands"
12+
"github.com/ava-labs/avalanche-cli/tests/e2e/utils"
813
ginkgo "github.com/onsi/ginkgo/v2"
914
"github.com/onsi/gomega"
1015
)
@@ -20,9 +25,95 @@ var _ = ginkgo.Describe("[Local Network] Clean", ginkgo.Ordered, func() {
2025
gomega.Expect(out).Should(gomega.ContainSubstring("Process terminated"))
2126
})
2227

28+
ginkgo.It("can clean a deployed L1", func() {
29+
testSubnetName := "test-subnet-2"
30+
31+
// Deploy a local L1
32+
out, err := commands.DeployBlockchain(
33+
testSubnetName,
34+
utils.TestFlags{
35+
"local": true,
36+
"skip-icm-deploy": true,
37+
"skip-update-check": true,
38+
},
39+
)
40+
gomega.Expect(out).Should(gomega.ContainSubstring("L1 is successfully deployed on Local Network"))
41+
gomega.Expect(err).Should(gomega.BeNil())
42+
43+
// Clean the network
44+
out, err = commands.CleanNetwork()
45+
gomega.Expect(err).Should(gomega.BeNil())
46+
gomega.Expect(out).Should(gomega.ContainSubstring("Process terminated"))
47+
48+
// Check L1 status - should not be running
49+
out, err = utils.TestCommand(
50+
cmd.BlockchainCmd,
51+
"stats",
52+
[]string{
53+
testSubnetName,
54+
"--local",
55+
"--" + constants.SkipUpdateFlag,
56+
},
57+
utils.GlobalFlags{},
58+
utils.TestFlags{},
59+
)
60+
gomega.Expect(err).ShouldNot(gomega.BeNil())
61+
gomega.Expect(out).Should(gomega.ContainSubstring("no subnetID found for the provided blockchain name"))
62+
63+
commands.DeleteSubnetConfig(testSubnetName)
64+
})
65+
2366
ginkgo.It("should err out when no network is running", func() {
2467
out, err := commands.CleanNetwork()
2568
gomega.Expect(err).Should(gomega.BeNil())
2669
gomega.Expect(out).Should(gomega.ContainSubstring("No network is running"))
2770
})
71+
72+
ginkgo.It("should only clean default snapshot", func() {
73+
// Start the network
74+
out, err := commands.StartNetwork()
75+
gomega.Expect(err).Should(gomega.BeNil())
76+
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
77+
78+
// Stop the network with default snapshot
79+
err = commands.StopNetwork()
80+
gomega.Expect(err).Should(gomega.BeNil())
81+
82+
// check if default snapshot exists
83+
snapshotExists := utils.CheckSnapshotExists("default")
84+
gomega.Expect(snapshotExists).Should(gomega.BeTrue(),
85+
fmt.Sprintf("snapshot %s should exist", "default"))
86+
87+
// Start the network
88+
out, err = commands.StartNetwork()
89+
gomega.Expect(err).Should(gomega.BeNil())
90+
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
91+
92+
// Stop the network with custome snapshot
93+
testSnapshotName := "test-snapshot"
94+
err = commands.StopNetwork("--snapshot-name", testSnapshotName)
95+
gomega.Expect(err).Should(gomega.BeNil())
96+
97+
// check if custom snapshot exists
98+
snapshotExists = utils.CheckSnapshotExists(testSnapshotName)
99+
gomega.Expect(snapshotExists).Should(gomega.BeTrue(),
100+
fmt.Sprintf("snapshot %s should exist", testSnapshotName))
101+
102+
// Clean the network
103+
out, err = commands.CleanNetwork()
104+
gomega.Expect(err).Should(gomega.BeNil())
105+
gomega.Expect(out).Should(gomega.ContainSubstring("No network is running"))
106+
107+
// default snapshot should be cleaned up
108+
snapshotExists = utils.CheckSnapshotExists("default")
109+
gomega.Expect(snapshotExists).Should(gomega.BeFalse(),
110+
fmt.Sprintf("snapshot %s should not exist", "default"))
111+
112+
// custom snapshot should still exist
113+
snapshotExists = utils.CheckSnapshotExists(testSnapshotName)
114+
gomega.Expect(snapshotExists).Should(gomega.BeTrue(),
115+
fmt.Sprintf("snapshot %s should exist", testSnapshotName))
116+
117+
utils.DeleteSnapshot(testSnapshotName)
118+
})
28119
})

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

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
"fmt"
88
"strconv"
99

10+
"github.com/ava-labs/avalanche-cli/cmd"
1011
"github.com/ava-labs/avalanche-cli/pkg/constants"
1112
"github.com/ava-labs/avalanche-cli/tests/e2e/commands"
13+
"github.com/ava-labs/avalanche-cli/tests/e2e/utils"
1214
ginkgo "github.com/onsi/ginkgo/v2"
1315
"github.com/onsi/gomega"
1416
)
@@ -62,4 +64,125 @@ var _ = ginkgo.Describe("[Local Network] Start", ginkgo.Ordered, func() {
6264
gomega.Expect(err).Should(gomega.BeNil())
6365
gomega.Expect(out).Should(gomega.ContainSubstring("Network is Up"))
6466
})
67+
68+
ginkgo.It("can start stopped network with preserved state - default snapshot", func() {
69+
// start network with given number of nodes
70+
numOfNodes := uint(5)
71+
out, err := commands.StartNetworkWithParams(map[string]interface{}{
72+
"num-nodes": strconv.FormatUint(uint64(numOfNodes), 10),
73+
})
74+
gomega.Expect(err).Should(gomega.BeNil())
75+
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
76+
77+
// check network status - number of nodes
78+
out, err = commands.GetNetworkStatus()
79+
gomega.Expect(err).Should(gomega.BeNil())
80+
gomega.Expect(out).Should(gomega.ContainSubstring("Network is Up"))
81+
gomega.Expect(out).Should(gomega.ContainSubstring(fmt.Sprintf("Number of Nodes: %d", numOfNodes)))
82+
83+
// stop the network
84+
err = commands.StopNetwork()
85+
gomega.Expect(err).Should(gomega.BeNil())
86+
87+
// now start the network again with no arguments
88+
out, err = commands.StartNetwork()
89+
gomega.Expect(err).Should(gomega.BeNil())
90+
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
91+
92+
// check network status - number of nodes should be preserved
93+
out, err = commands.GetNetworkStatus()
94+
gomega.Expect(err).Should(gomega.BeNil())
95+
gomega.Expect(out).Should(gomega.ContainSubstring("Network is Up"))
96+
gomega.Expect(out).Should(gomega.ContainSubstring(fmt.Sprintf("Number of Nodes: %d", numOfNodes)))
97+
})
98+
99+
ginkgo.It("can start properly with given snapshot - custom snapshot", func() {
100+
// start network with given number of nodes
101+
numOfNodes := uint(5)
102+
out, err := commands.StartNetworkWithParams(map[string]interface{}{
103+
"num-nodes": strconv.FormatUint(uint64(numOfNodes), 10),
104+
})
105+
gomega.Expect(err).Should(gomega.BeNil())
106+
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
107+
108+
// stop with snapshot name
109+
testSnapshotName := "test-snapshot"
110+
err = commands.StopNetwork("--snapshot-name", testSnapshotName)
111+
gomega.Expect(err).Should(gomega.BeNil())
112+
113+
// check snapshot exists
114+
snapshotExists := utils.CheckSnapshotExists(testSnapshotName)
115+
gomega.Expect(snapshotExists).Should(gomega.BeTrue(),
116+
fmt.Sprintf("snapshot %s should exist", testSnapshotName))
117+
118+
// start the network with snapshot name
119+
out, err = commands.StartNetworkWithParams(map[string]interface{}{
120+
"snapshot-name": testSnapshotName,
121+
})
122+
gomega.Expect(err).Should(gomega.BeNil())
123+
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
124+
125+
// check network status - number of nodes should be preserved
126+
out, err = commands.GetNetworkStatus()
127+
gomega.Expect(err).Should(gomega.BeNil())
128+
gomega.Expect(out).Should(gomega.ContainSubstring("Network is Up"))
129+
gomega.Expect(out).Should(gomega.ContainSubstring(fmt.Sprintf("Number of Nodes: %d", numOfNodes)))
130+
131+
utils.DeleteSnapshot(testSnapshotName)
132+
})
133+
134+
ginkgo.It("can start a deployed but stopped L1", func() {
135+
testSubnetName := "test-subnet-1"
136+
commands.CreateEtnaSubnetEvmConfig(testSubnetName, utils.EwoqEVMAddress, commands.PoA)
137+
138+
// Deploy a local L1
139+
out, err := commands.DeployBlockchain(
140+
testSubnetName,
141+
utils.TestFlags{
142+
"local": true,
143+
"skip-icm-deploy": true,
144+
"skip-update-check": true,
145+
},
146+
)
147+
gomega.Expect(out).Should(gomega.ContainSubstring("L1 is successfully deployed on Local Network"))
148+
gomega.Expect(err).Should(gomega.BeNil())
149+
150+
// stop the network
151+
err = commands.StopNetwork()
152+
gomega.Expect(err).Should(gomega.BeNil())
153+
154+
// now restart the network
155+
out, err = commands.StartNetwork()
156+
gomega.Expect(err).Should(gomega.BeNil())
157+
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
158+
159+
// check L1 status - should be back and running
160+
out, err = utils.TestCommand(
161+
cmd.BlockchainCmd,
162+
"stats",
163+
[]string{
164+
testSubnetName,
165+
"--local",
166+
"--" + constants.SkipUpdateFlag,
167+
},
168+
utils.GlobalFlags{},
169+
utils.TestFlags{},
170+
)
171+
gomega.Expect(err).Should(gomega.BeNil())
172+
gomega.Expect(out).Should(gomega.ContainSubstring("already validating the subnet"))
173+
174+
commands.DeleteSubnetConfig(testSubnetName)
175+
})
176+
177+
ginkgo.It("can start with given avalanchego version", func() {
178+
// subnet config
179+
_ = utils.DeleteConfigs(utils.BlockchainName)
180+
_, avagoVersion := commands.CreateSubnetEvmConfigSOV(utils.BlockchainName, utils.SubnetEvmGenesisPath)
181+
182+
// local network
183+
_, err := commands.StartNetworkWithParams(map[string]interface{}{
184+
"avalanchego-version": avagoVersion,
185+
})
186+
gomega.Expect(err).Should(gomega.BeNil())
187+
})
65188
})

0 commit comments

Comments
 (0)