This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
e2e_test.go
279 lines (247 loc) · 7.63 KB
/
e2e_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// e2e implements the e2e tests.
package e2e_test
import (
"context"
"flag"
"testing"
"time"
runner_client "github.com/ava-labs/avalanche-network-runner/client"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/subnet-cli/client"
"github.com/ava-labs/subnet-cli/internal/key"
"github.com/ava-labs/subnet-cli/pkg/color"
"github.com/ava-labs/subnet-cli/pkg/logutil"
ginkgo "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)
func TestE2e(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "subnet-cli e2e test suites")
}
var (
logLevel string
gRPCEp string
gRPCGatewayEp string
execPath string
)
func init() {
flag.StringVar(
&logLevel,
"log-level",
logutil.DefaultLogLevel,
"log level",
)
flag.StringVar(
&gRPCEp,
"grpc-endpoint",
"0.0.0.0:8080",
"gRPC server endpoint",
)
flag.StringVar(
&gRPCGatewayEp,
"grpc-gateway-endpoint",
"0.0.0.0:8081",
"gRPC gateway endpoint",
)
flag.StringVar(
&execPath,
"avalanchego-path",
"",
"avalanchego executable path",
)
}
var (
runnerClient runner_client.Client
cli client.Client
k key.Key
)
var _ = ginkgo.BeforeSuite(func() {
var err error
runnerClient, err = runner_client.New(runner_client.Config{
Endpoint: gRPCEp,
DialTimeout: 10 * time.Second,
}, logging.NoLog{})
gomega.Ω(err).Should(gomega.BeNil())
// TODO: pass subnet whitelisting
color.Outf("{{green}}starting:{{/}} %q\n", execPath)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
_, err = runnerClient.Start(ctx, execPath)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
ctx, cancel = context.WithTimeout(context.Background(), 2*time.Minute)
_, err = runnerClient.Health(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
color.Outf("{{green}}getting URIs{{/}}\n")
var uris []string
ctx, cancel = context.WithTimeout(context.Background(), 2*time.Minute)
uris, err = runnerClient.URIs(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
color.Outf("{{green}}creating subnet-cli client{{/}}\n")
cli, err = client.New(client.Config{
URI: uris[0],
PollInterval: time.Second,
})
gomega.Ω(err).Should(gomega.BeNil())
k, err = key.NewSoft(9999999, key.WithPrivateKeyEncoded(key.EwoqPrivateKey))
gomega.Ω(err).Should(gomega.BeNil())
})
var _ = ginkgo.AfterSuite(func() {
color.Outf("{{red}}shutting down cluster{{/}}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := runnerClient.Stop(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
color.Outf("{{red}}shutting down client{{/}}\n")
err = runnerClient.Close()
gomega.Ω(err).Should(gomega.BeNil())
})
var subnetID = ids.Empty
var _ = ginkgo.Describe("[CreateSubnet/CreateBlockchain]", func() {
ginkgo.It("can issue CreateSubnetTx", func() {
balance, err := cli.P().Balance(context.Background(), k)
gomega.Ω(err).Should(gomega.BeNil())
feeInfo, err := cli.Info().Client().GetTxFee(context.Background())
gomega.Ω(err).Should(gomega.BeNil())
subnetTxFee := uint64(feeInfo.CreateSubnetTxFee)
expectedBalance := balance - subnetTxFee
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
subnet1, _, err := cli.P().CreateSubnet(ctx, k, client.WithDryMode(true))
cancel()
gomega.Ω(err).Should(gomega.BeNil())
ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
subnet2, _, err := cli.P().CreateSubnet(ctx, k, client.WithDryMode(false))
cancel()
gomega.Ω(err).Should(gomega.BeNil())
ginkgo.By("returns an identical subnet ID with dry mode", func() {
gomega.Ω(subnet1).Should(gomega.Equal(subnet2))
})
subnetID = subnet1
ginkgo.By("returns a tx-fee deducted balance", func() {
curBal, err := cli.P().Balance(context.Background(), k)
gomega.Ω(err).Should(gomega.BeNil())
gomega.Ω(curBal).Should(gomega.Equal(expectedBalance))
})
})
ginkgo.It("can add subnet/validators", func() {
nodeID, _, err := cli.Info().Client().GetNodeID(context.Background())
gomega.Ω(err).Should(gomega.BeNil())
ginkgo.By("fails when subnet ID is empty", func() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
_, err = cli.P().AddSubnetValidator(
ctx,
k,
ids.Empty,
nodeID,
time.Now(),
time.Now(),
1000,
)
cancel()
gomega.Ω(err.Error()).Should(gomega.Equal(client.ErrEmptyID.Error()))
})
ginkgo.By("fails when node ID is empty", func() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
_, err = cli.P().AddSubnetValidator(
ctx,
k,
subnetID,
ids.EmptyNodeID,
time.Now(),
time.Now(),
1000,
)
cancel()
gomega.Ω(err.Error()).Should(gomega.Equal(client.ErrEmptyID.Error()))
})
ginkgo.By("fails to add an invalid subnet as a validator, when nodeID isn't validating the primary network", func() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
_, err = cli.P().AddSubnetValidator(
ctx,
k,
subnetID,
ids.GenerateTestNodeID(),
time.Now().Add(30*time.Second),
time.Now().Add(2*24*time.Hour),
1000,
)
cancel()
gomega.Ω(err.Error()).Should(gomega.Equal(client.ErrNotValidatingPrimaryNetwork.Error()))
})
ginkgo.By("fails when validate start/end times are invalid", func() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
_, err = cli.P().AddSubnetValidator(
ctx,
k,
subnetID,
nodeID,
time.Now(),
time.Now().Add(5*time.Second),
1000,
)
cancel()
// e.g., "failed to issue tx: couldn't issue tx: staking period is too short"
gomega.Ω(err.Error()).Should(gomega.ContainSubstring("staking period is too short"))
})
ginkgo.By("fails to add duplicate validator", func() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
_, err = cli.P().AddValidator(
ctx,
k,
nodeID,
time.Now().Add(30*time.Second),
time.Now().Add(5*24*time.Hour),
client.WithStakeAmount(2*units.KiloAvax),
// ref. "genesis/genesis_local.go".
client.WithRewardShares(30000), // 3%
)
cancel()
gomega.Ω(err.Error()).Should(gomega.Equal(client.ErrAlreadyValidator.Error()))
})
})
ginkgo.It("can issue CreateBlockchain", func() {
ginkgo.By("fails when subnet ID is empty", func() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
_, _, err := cli.P().CreateBlockchain(
ctx,
k,
ids.Empty,
"",
ids.Empty,
nil,
)
cancel()
gomega.Ω(err.Error()).Should(gomega.Equal(client.ErrEmptyID.Error()))
})
ginkgo.By("fails when vm ID is empty", func() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
_, _, err := cli.P().CreateBlockchain(
ctx,
k,
subnetID,
"",
ids.Empty,
nil,
)
cancel()
gomega.Ω(err.Error()).Should(gomega.Equal(client.ErrEmptyID.Error()))
})
ginkgo.Skip("TODO: once we have a testable spaces VM in public")
balance, err := cli.P().Balance(context.Background(), k)
gomega.Ω(err).Should(gomega.BeNil())
feeInfo, err := cli.Info().Client().GetTxFee(context.Background())
gomega.Ω(err).Should(gomega.BeNil())
blkChainFee := uint64(feeInfo.CreateBlockchainTxFee)
expectedBalance := balance - blkChainFee
ginkgo.By("returns a tx-fee deducted balance", func() {
curBal, err := cli.P().Balance(context.Background(), k)
gomega.Ω(err).Should(gomega.BeNil())
gomega.Ω(curBal).Should(gomega.Equal(expectedBalance))
})
})
})