Skip to content

Commit 2f2bf94

Browse files
author
Tony Zhang
committed
addressing comments
1 parent b34301d commit 2f2bf94

File tree

22 files changed

+95
-92
lines changed

22 files changed

+95
-92
lines changed

tests/e2e/commands/network.go

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/ava-labs/avalanche-cli/pkg/constants"
1111
"github.com/ava-labs/avalanche-cli/tests/e2e/utils"
12-
"github.com/onsi/gomega"
1312
)
1413

1514
/* #nosec G204 */
@@ -30,32 +29,14 @@ func CleanNetwork() (string, error) {
3029
return output, err
3130
}
3231

33-
func CleanNetworkHard() (string, error) {
34-
output, err := utils.TestCommand(
35-
NetworkCmd,
36-
"clean",
37-
[]string{
38-
"--hard",
39-
"--" + constants.SkipUpdateFlag,
40-
},
41-
utils.GlobalFlags{},
42-
utils.TestFlags{},
43-
)
44-
if err != nil {
45-
fmt.Println(output)
46-
utils.PrintStdErr(err)
47-
}
48-
return output, err
49-
}
50-
5132
/* #nosec G204 */
52-
func StartNetwork() string {
33+
func StartNetwork() (string, error) {
5334
return StartNetworkWithParams(map[string]string{
5435
"version": "",
5536
})
5637
}
5738

58-
func StartNetworkWithParams(paramMap map[string]string) string {
39+
func StartNetworkWithParams(paramMap map[string]string) (string, error) {
5940
cmdArgs := utils.GlobalFlags{}
6041

6142
for k, v := range paramMap {
@@ -87,8 +68,7 @@ func StartNetworkWithParams(paramMap map[string]string) string {
8768
fmt.Println(output)
8869
utils.PrintStdErr(err)
8970
}
90-
gomega.Expect(err).Should(gomega.BeNil())
91-
return output
71+
return output, err
9272
}
9373

9474
/* #nosec G204 */

tests/e2e/testcases/blockchain/configure/suite.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ var _ = ginkgo.Describe("[Blockchain Configure]", ginkgo.Ordered, func() {
246246
)
247247
gomega.Expect(err).Should(gomega.BeNil())
248248
// start
249-
out := commands.StartNetwork()
249+
out, err := commands.StartNetwork()
250+
gomega.Expect(err).Should(gomega.BeNil())
250251
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
251252
// check a new config is set after restart
252253
AssertBlockchainConfigIsSet(nodesInfo, blockchainID, newRPCTxFeeCap2, nil)
@@ -310,7 +311,8 @@ var _ = ginkgo.Describe("[Blockchain Configure]", ginkgo.Ordered, func() {
310311
)
311312
gomega.Expect(err).Should(gomega.BeNil())
312313
// start
313-
out := commands.StartNetwork()
314+
out, err := commands.StartNetwork()
315+
gomega.Expect(err).Should(gomega.BeNil())
314316
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
315317
// check a new config is set after restart
316318
AssertBlockchainConfigIsSet(nodesInfo, blockchainID, defaultRPCTxFeeCap, nodesRPCTxFeeCap)
@@ -362,7 +364,8 @@ var _ = ginkgo.Describe("[Blockchain Configure]", ginkgo.Ordered, func() {
362364
)
363365
gomega.Expect(err).Should(gomega.BeNil())
364366
// start
365-
out := commands.StartNetwork()
367+
out, err := commands.StartNetwork()
368+
gomega.Expect(err).Should(gomega.BeNil())
366369
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
367370
// check a new config is set after restart
368371
AssertSubnetConfigIsSet(nodesInfo, node2ID)
@@ -414,7 +417,8 @@ var _ = ginkgo.Describe("[Blockchain Configure]", ginkgo.Ordered, func() {
414417
)
415418
gomega.Expect(err).Should(gomega.BeNil())
416419
// start
417-
out := commands.StartNetwork()
420+
out, err := commands.StartNetwork()
421+
gomega.Expect(err).Should(gomega.BeNil())
418422
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
419423
// check a new config is set after restart
420424
AssertNodeConfigIsSet(nodesInfo, acpSupport2)

tests/e2e/testcases/icm/deploy/suite.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var evmClient evm.Client
3232
var _ = ginkgo.Describe("[ICM] deploy", func() {
3333
ginkgo.Context("with valid input", func() {
3434
ginkgo.BeforeEach(func() {
35-
commands.StartNetwork()
35+
_, _ = commands.StartNetwork()
3636

3737
var err error
3838
evmClient, err = evm.GetClient(cChainRPCUrl)
@@ -354,7 +354,7 @@ var _ = ginkgo.Describe("[ICM] deploy", func() {
354354
})
355355
ginkgo.Context("with invalid input", func() {
356356
ginkgo.BeforeEach(func() {
357-
commands.StartNetwork()
357+
_, _ = commands.StartNetwork()
358358
})
359359

360360
ginkgo.AfterEach(func() {

tests/e2e/testcases/icm/sendMsg/suite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var globalFlags = utils.GlobalFlags{
2525

2626
var _ = ginkgo.Describe("[ICM] sendMsg", func() {
2727
ginkgo.BeforeEach(func() {
28-
commands.StartNetwork()
28+
_, _ = commands.StartNetwork()
2929
})
3030

3131
ginkgo.AfterEach(func() {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ var _ = ginkgo.Describe("[Key] transfer", func() {
3131
_, err := commands.CreateKey(keyName)
3232
gomega.Expect(err).Should(gomega.BeNil())
3333

34-
commands.StartNetwork()
34+
_, err = commands.StartNetwork()
35+
gomega.Expect(err).Should(gomega.BeNil())
3536
})
3637

3738
ginkgo.AfterEach(func() {

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@
44
package network
55

66
import (
7-
"path"
8-
9-
"github.com/ava-labs/avalanche-cli/sdk/utils"
107
"github.com/ava-labs/avalanche-cli/tests/e2e/commands"
11-
testUtils "github.com/ava-labs/avalanche-cli/tests/e2e/utils"
128
ginkgo "github.com/onsi/ginkgo/v2"
139
"github.com/onsi/gomega"
1410
)
1511

1612
var _ = ginkgo.Describe("[Local Network] Clean", ginkgo.Ordered, func() {
1713
ginkgo.It("can clean a started network", func() {
18-
out := commands.StartNetwork()
14+
out, err := commands.StartNetwork()
15+
gomega.Expect(err).Should(gomega.BeNil())
1916
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
2017

21-
out, err := commands.CleanNetwork()
18+
out, err = commands.CleanNetwork()
2219
gomega.Expect(err).Should(gomega.BeNil())
2320
gomega.Expect(out).Should(gomega.ContainSubstring("Process terminated"))
2421
})
@@ -28,16 +25,4 @@ var _ = ginkgo.Describe("[Local Network] Clean", ginkgo.Ordered, func() {
2825
gomega.Expect(err).Should(gomega.BeNil())
2926
gomega.Expect(out).Should(gomega.ContainSubstring("No network is running"))
3027
})
31-
32-
ginkgo.It("hard clean should remove downloaded avalanchego and plugins", func() {
33-
out := commands.StartNetwork()
34-
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
35-
36-
_, err := commands.CleanNetworkHard()
37-
gomega.Expect(err).Should(gomega.BeNil())
38-
39-
// check if binaries are removed
40-
binDirExists := utils.DirExists(path.Join(testUtils.GetBaseDir(), "bin"))
41-
gomega.Expect(binDirExists).Should(gomega.BeFalse())
42-
})
4328
})

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"strconv"
99

10+
"github.com/ava-labs/avalanche-cli/pkg/constants"
1011
"github.com/ava-labs/avalanche-cli/tests/e2e/commands"
1112
ginkgo "github.com/onsi/ginkgo/v2"
1213
"github.com/onsi/gomega"
@@ -18,30 +19,29 @@ var _ = ginkgo.Describe("[Local Network] Start", ginkgo.Ordered, func() {
1819
})
1920

2021
ginkgo.It("can start network with default params", func() {
21-
out := commands.StartNetwork()
22+
out, err := commands.StartNetwork()
23+
gomega.Expect(err).Should(gomega.BeNil())
2224
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
2325

24-
// https://github.com/ava-labs/avalanchego/blob/master/tests/fixture/tmpnet/defaults.go#L27
25-
defaultNodeCount := 2
26-
2726
// check network status
28-
out, err := commands.GetNetworkStatus()
27+
out, err = commands.GetNetworkStatus()
2928
gomega.Expect(err).Should(gomega.BeNil())
3029
gomega.Expect(out).Should(gomega.ContainSubstring("Network is Up"))
31-
gomega.Expect(out).Should(gomega.ContainSubstring(fmt.Sprintf("Number of Nodes: %d", defaultNodeCount)))
30+
gomega.Expect(out).Should(gomega.ContainSubstring(fmt.Sprintf("Number of Nodes: %d", constants.LocalNetworkNumNodes)))
3231
gomega.Expect(out).Should(gomega.ContainSubstring("Network Healthy: true"))
3332
gomega.Expect(out).Should(gomega.ContainSubstring("Blockchains Healthy: true"))
3433
})
3534

3635
ginkgo.It("can start network with given number of nodes", func() {
3736
numOfNodes := uint(3)
38-
out := commands.StartNetworkWithParams(map[string]string{
37+
out, err := commands.StartNetworkWithParams(map[string]string{
3938
"number-of-nodes": strconv.FormatUint(uint64(numOfNodes), 10),
4039
})
40+
gomega.Expect(err).Should(gomega.BeNil())
4141
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
4242

4343
// check network status
44-
out, err := commands.GetNetworkStatus()
44+
out, err = commands.GetNetworkStatus()
4545
gomega.Expect(err).Should(gomega.BeNil())
4646
gomega.Expect(out).Should(gomega.ContainSubstring("Network is Up"))
4747
gomega.Expect(out).Should(gomega.ContainSubstring(fmt.Sprintf("Number of Nodes: %d", numOfNodes)))
@@ -50,13 +50,15 @@ var _ = ginkgo.Describe("[Local Network] Start", ginkgo.Ordered, func() {
5050
})
5151

5252
ginkgo.It("should not start network with already started network", func() {
53-
out := commands.StartNetwork()
53+
out, err := commands.StartNetwork()
54+
gomega.Expect(err).Should(gomega.BeNil())
5455
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
5556

56-
out = commands.StartNetwork()
57+
out, err = commands.StartNetwork()
58+
gomega.Expect(err).Should(gomega.BeNil())
5759
gomega.Expect(out).Should(gomega.ContainSubstring("Network has already been booted"))
5860

59-
out, err := commands.GetNetworkStatus()
61+
out, err = commands.GetNetworkStatus()
6062
gomega.Expect(err).Should(gomega.BeNil())
6163
gomega.Expect(out).Should(gomega.ContainSubstring("Network is Up"))
6264
})

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,35 @@ var _ = ginkgo.Describe("[Local Network] Status", ginkgo.Ordered, func() {
1717
})
1818

1919
ginkgo.It("can get status of started network", func() {
20-
out := commands.StartNetwork()
20+
out, err := commands.StartNetwork()
21+
gomega.Expect(err).Should(gomega.BeNil())
2122
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
2223

2324
// https://github.com/ava-labs/avalanchego/blob/master/tests/fixture/tmpnet/defaults.go#L27
2425
defaultNodeCount := 2
2526

2627
// check network status
27-
out, err := commands.GetNetworkStatus()
28+
out, err = commands.GetNetworkStatus()
2829
gomega.Expect(err).Should(gomega.BeNil())
2930
gomega.Expect(out).Should(gomega.ContainSubstring("Network is Up"))
3031
gomega.Expect(out).Should(gomega.ContainSubstring(fmt.Sprintf("Number of Nodes: %d", defaultNodeCount)))
3132
gomega.Expect(out).Should(gomega.ContainSubstring("Network Healthy: true"))
3233
gomega.Expect(out).Should(gomega.ContainSubstring("Blockchains Healthy: true"))
3334
})
3435

36+
ginkgo.It("fail to get status of failed-to-start network", func() {
37+
out, err := commands.StartNetworkWithParams(map[string]string{
38+
"version": "no-such-version",
39+
})
40+
gomega.Expect(err).ShouldNot(gomega.BeNil())
41+
gomega.Expect(out).Should(gomega.ContainSubstring("Error"))
42+
43+
// check network status
44+
out, err = commands.GetNetworkStatus()
45+
gomega.Expect(out).Should(gomega.ContainSubstring("network is not running"))
46+
gomega.Expect(err).ShouldNot(gomega.BeNil())
47+
})
48+
3549
ginkgo.It("can get status when no network is up", func() {
3650
out, err := commands.GetNetworkStatus()
3751
gomega.Expect(err).ShouldNot(gomega.BeNil())

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ var _ = ginkgo.Describe("[Local Network] Stop", ginkgo.Ordered, func() {
2020
})
2121

2222
ginkgo.It("can stop a started network", func() {
23-
out := commands.StartNetwork()
23+
out, err := commands.StartNetwork()
24+
gomega.Expect(err).Should(gomega.BeNil())
2425
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
2526

26-
err := commands.StopNetwork()
27+
err = commands.StopNetwork()
2728
gomega.Expect(err).Should(gomega.BeNil())
2829

2930
// check network status
@@ -40,10 +41,11 @@ var _ = ginkgo.Describe("[Local Network] Stop", ginkgo.Ordered, func() {
4041
})
4142

4243
ginkgo.It("can stop a started network with --dont-save", func() {
43-
out := commands.StartNetwork()
44+
out, err := commands.StartNetwork()
45+
gomega.Expect(err).Should(gomega.BeNil())
4446
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
4547

46-
err := commands.StopNetwork("--dont-save")
48+
err = commands.StopNetwork("--dont-save")
4749
gomega.Expect(err).Should(gomega.BeNil())
4850

4951
out, err = commands.GetNetworkStatus()
@@ -57,11 +59,12 @@ var _ = ginkgo.Describe("[Local Network] Stop", ginkgo.Ordered, func() {
5759
})
5860

5961
ginkgo.It("can stop a started network with --snapshot-name", func() {
60-
out := commands.StartNetwork()
62+
out, err := commands.StartNetwork()
63+
gomega.Expect(err).Should(gomega.BeNil())
6164
gomega.Expect(out).Should(gomega.ContainSubstring("Network ready to use"))
6265

6366
testSnapshotName := "test-snapshot"
64-
err := commands.StopNetwork("--snapshot-name", testSnapshotName)
67+
err = commands.StopNetwork("--snapshot-name", testSnapshotName)
6568
gomega.Expect(err).Should(gomega.BeNil())
6669

6770
out, err = commands.GetNetworkStatus()

tests/e2e/testcases/network/suite.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ var _ = ginkgo.Describe("[Network]", ginkgo.Ordered, func() {
5757

5858
err = commands.StopNetwork()
5959
gomega.Expect(err).Should(gomega.BeNil())
60-
commands.StartNetwork()
60+
_, err = commands.StartNetwork()
61+
gomega.Expect(err).Should(gomega.BeNil())
6162

6263
// Check greeter contract has right value
6364
scriptOutput, scriptErr, err = utils.RunHardhatScript(utils.GreeterCheck)
@@ -104,7 +105,8 @@ var _ = ginkgo.Describe("[Network]", ginkgo.Ordered, func() {
104105

105106
err = commands.StopNetwork()
106107
gomega.Expect(err).Should(gomega.BeNil())
107-
commands.StartNetwork()
108+
_, err = commands.StartNetwork()
109+
gomega.Expect(err).Should(gomega.BeNil())
108110

109111
// Check greeter contract has right value
110112
scriptOutput, scriptErr, err = utils.RunHardhatScript(utils.GreeterCheck)

0 commit comments

Comments
 (0)