Skip to content

Commit 68c727a

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

File tree

2 files changed

+217
-0
lines changed

2 files changed

+217
-0
lines changed

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

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

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

Lines changed: 125 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,127 @@ 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 := "testSubnet1"
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+
testSubnetName := "testSubnet3"
179+
// subnet config
180+
_, avagoVersion := commands.CreateSubnetEvmConfigSOV(testSubnetName, 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+
188+
_ = utils.DeleteConfigs(testSubnetName)
189+
})
65190
})

0 commit comments

Comments
 (0)