Skip to content

Commit

Permalink
addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
holisticode committed Aug 4, 2022
1 parent c70bfd2 commit 0b3ccfb
Showing 1 changed file with 231 additions and 66 deletions.
297 changes: 231 additions & 66 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/message"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/prometheus/client_golang/prometheus"

ginkgo "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/prometheus/client_golang/prometheus"
)

func TestE2e(t *testing.T) {
Expand All @@ -39,13 +38,12 @@ func TestE2e(t *testing.T) {
}

var (
logLevel string
gRPCEp string
gRPCGatewayEp string
execPath1 string
execPath2 string
subnetEvmPath string
existingSubnetID string
logLevel string
gRPCEp string
gRPCGatewayEp string
execPath1 string
execPath2 string
subnetEvmPath string

newNodeName = "test-add-node"
customNodeConfigs = map[string]string{
Expand Down Expand Up @@ -124,70 +122,237 @@ var _ = ginkgo.AfterSuite(func() {
})

var _ = ginkgo.Describe("[Start/Remove/Restart/Add/Stop]", func() {
ginkgo.It("can start with blockchain", func() {
color.Outf("{{green}}sending 'start' with the valid binary path:{{/}} %q\n", execPath1)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
resp, err := cli.Start(ctx, execPath2,
client.WithBlockchainSpecs([]*rpcpb.BlockchainSpec{
{
VmName: "subnetevm",
Genesis: "tests/e2e/subnet-evm-genesis.json",
ginkgo.It("can create blockhains", func() {
existingSubnetID := ""
ginkgo.By("start with blockchain specs", func() {
color.Outf("{{green}}sending 'start' with the valid binary path:{{/}} %q\n", execPath1)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
resp, err := cli.Start(ctx, execPath2,
client.WithBlockchainSpecs([]*rpcpb.BlockchainSpec{
{
VmName: "subnetevm",
Genesis: "tests/e2e/subnet-evm-genesis.json",
},
}),
)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
color.Outf("{{green}}successfully started:{{/}} %+v\n", resp.ClusterInfo.NodeNames)
})

ginkgo.By("wait for network to be healthy", func() {
color.Outf("{{blue}}wait for health{{/}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.Health(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

ginkgo.By("get status", func() {
color.Outf("{{blue}}get status for existing subnet ID{{/}}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
subnetDeployed := false
LOOP:
for !subnetDeployed {
select {
case <-ctx.Done():
break LOOP
case <-time.After(5 * time.Second):
stat, err := cli.Status(ctx)
gomega.Ω(err).Should(gomega.BeNil())
if stat.ClusterInfo.CustomChainsHealthy {
subnetDeployed = true
existingSubnetID = stat.ClusterInfo.GetSubnets()[0]
gomega.Ω(existingSubnetID).Should(gomega.Not(gomega.BeNil()))
}
}
}
cancel()
gomega.Ω(subnetDeployed).Should(gomega.BeTrue())
})

time.Sleep(1 * time.Second)
ginkgo.By("can create a blockchain with a new subnet id", func() {
color.Outf("{{blue}}can create a blockchain in a new subnet{{/}}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.CreateBlockchains(ctx,
[]*rpcpb.BlockchainSpec{
{
VmName: "subnetevm",
Genesis: "tests/e2e/subnet-evm-genesis.json",
},
},
}),
)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
color.Outf("{{green}}successfully started:{{/}} %+v\n", resp.ClusterInfo.NodeNames)
)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

color.Outf("{{blue}}wait for health{{/}\n")
ctx, cancel = context.WithTimeout(context.Background(), 2*time.Minute)
_, err = cli.Health(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
ginkgo.By("wait for network to be healthy", func() {
color.Outf("{{blue}}wait for health{{/}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.Health(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

ginkgo.By("can create a blockchain with an existing subnet id", func() {
color.Outf("{{blue}}can create a blockchain in an existing subnet{{/}}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.CreateBlockchains(ctx,
[]*rpcpb.BlockchainSpec{
{
VmName: "subnetevm",
Genesis: "tests/e2e/subnet-evm-genesis.json",
SubnetId: &existingSubnetID,
},
},
)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

ginkgo.By("wait for network to be healthy", func() {
color.Outf("{{blue}}wait for health{{/}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.Health(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

color.Outf("{{blue}}get status for existing subnet ID{{/}}\n")
ctx, cancel = context.WithTimeout(context.Background(), 2*time.Minute)
subnetDeployed := false
LOOP:
for !subnetDeployed {
select {
case <-ctx.Done():
break LOOP
case <-time.After(5 * time.Second):
stat, err := cli.Status(ctx)
gomega.Ω(err).Should(gomega.BeNil())
if stat.ClusterInfo.CustomChainsHealthy {
subnetDeployed = true
existingSubnetID = stat.ClusterInfo.GetSubnets()[0]
gomega.Ω(existingSubnetID).Should(gomega.Not(gomega.BeNil()))
ginkgo.By("get status", func() {
color.Outf("{{blue}}get status for existing subnet ID{{/}}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
subnetDeployed := false
LOOP:
for !subnetDeployed {
select {
case <-ctx.Done():
break LOOP
case <-time.After(5 * time.Second):
stat, err := cli.Status(ctx)
gomega.Ω(err).Should(gomega.BeNil())
if stat.ClusterInfo.CustomChainsHealthy {
subnetDeployed = true
existingSubnetID = stat.ClusterInfo.GetSubnets()[0]
gomega.Ω(existingSubnetID).Should(gomega.Not(gomega.BeNil()))
}
}
}
}
cancel()
gomega.Ω(subnetDeployed).Should(gomega.BeTrue())
color.Outf("{{blue}}can create a blockchain in an existing subnet{{/}}\n")
ctx, cancel = context.WithTimeout(context.Background(), 2*time.Minute)
_, err = cli.CreateBlockchains(ctx,
[]*rpcpb.BlockchainSpec{
{
VmName: "subnetevm",
Genesis: "tests/e2e/subnet-evm-genesis.json",
SubnetId: &existingSubnetID,
cancel()
gomega.Ω(subnetDeployed).Should(gomega.BeTrue())
})

time.Sleep(1 * time.Second)
ginkgo.By("can save snapshot", func() {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.SaveSnapshot(ctx, "test")
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

ginkgo.By("can load snapshot", func() {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.LoadSnapshot(ctx, "test")
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

ginkgo.By("wait for network to be healthy", func() {
color.Outf("{{blue}}wait for health{{/}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.Health(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

ginkgo.By("get status", func() {
color.Outf("{{blue}}get status for existing subnet ID{{/}}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
subnetDeployed := false
LOOP:
for !subnetDeployed {
select {
case <-ctx.Done():
break LOOP
case <-time.After(5 * time.Second):
stat, err := cli.Status(ctx)
gomega.Ω(err).Should(gomega.BeNil())
if stat.ClusterInfo.CustomChainsHealthy {
subnetDeployed = true
existingSubnetID = stat.ClusterInfo.GetSubnets()[0]
gomega.Ω(existingSubnetID).Should(gomega.Not(gomega.BeNil()))
}
}
}
cancel()
gomega.Ω(subnetDeployed).Should(gomega.BeTrue())
})

// need to remove the snapshot otherwise it fails later in the 2nd part of snapshot tests
// (testing for no snapshots)
ginkgo.By("can remove snapshot", func() {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.RemoveSnapshot(ctx, "test")
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})
time.Sleep(1 * time.Second)
ginkgo.By("can create a blockchain with an existing subnet id", func() {
color.Outf("{{blue}}can create a blockchain in an existing subnet{{/}}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.CreateBlockchains(ctx,
[]*rpcpb.BlockchainSpec{
{
VmName: "subnetevm",
Genesis: "tests/e2e/subnet-evm-genesis.json",
SubnetId: &existingSubnetID,
},
},
},
)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
color.Outf("{{blue}}wait for health{{/}\n")
ctx, cancel = context.WithTimeout(context.Background(), 2*time.Minute)
_, err = cli.Health(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
ctx, cancel = context.WithTimeout(context.Background(), 2*time.Minute)
_, err = cli.Stop(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

ginkgo.By("wait for network to be healthy", func() {
color.Outf("{{blue}}wait for health{{/}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.Health(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})

ginkgo.By("get status", func() {
color.Outf("{{blue}}get status for existing subnet ID{{/}}\n")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
subnetDeployed := false
LOOP:
for !subnetDeployed {
select {
case <-ctx.Done():
break LOOP
case <-time.After(5 * time.Second):
stat, err := cli.Status(ctx)
gomega.Ω(err).Should(gomega.BeNil())
if stat.ClusterInfo.CustomChainsHealthy {
subnetDeployed = true
existingSubnetID = stat.ClusterInfo.GetSubnets()[0]
gomega.Ω(existingSubnetID).Should(gomega.Not(gomega.BeNil()))
}
}
}
cancel()
gomega.Ω(subnetDeployed).Should(gomega.BeTrue())
})

time.Sleep(1 * time.Second)
ginkgo.By("stop the network", func() {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
_, err := cli.Stop(ctx)
cancel()
gomega.Ω(err).Should(gomega.BeNil())
})
})

ginkgo.It("can start", func() {
ginkgo.By("start request with invalid exec path should fail", func() {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
Expand Down

0 comments on commit 0b3ccfb

Please sign in to comment.