Files

249 lines
7.8 KiB
Go

// Copyright (C) 2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package subnet
import (
"fmt"
"github.com/luxfi/cli/v2/tests/e2e/commands"
"github.com/luxfi/cli/v2/tests/e2e/utils"
ginkgo "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)
const (
subnetName = "e2eSubnetTest"
secondSubnetName = "e2eSecondSubnetTest"
confPath = "tests/e2e/assets/test_lux-cli.json"
)
var (
mapping map[string]string
err error
)
var _ = ginkgo.Describe("[Local Subnet SOV]", ginkgo.Ordered, func() {
_ = ginkgo.BeforeAll(func() {
mapper := utils.NewVersionMapper()
mapping, err = utils.GetVersionMapping(mapper)
gomega.Expect(err).Should(gomega.BeNil())
})
ginkgo.AfterEach(func() {
commands.CleanNetwork()
err := utils.DeleteConfigs(subnetName)
if err != nil {
fmt.Println("Clean network error:", err)
}
gomega.Expect(err).Should(gomega.BeNil())
err = utils.DeleteConfigs(secondSubnetName)
if err != nil {
fmt.Println("Delete config error:", err)
}
gomega.Expect(err).Should(gomega.BeNil())
// delete custom vm
utils.DeleteCustomBinary(subnetName)
utils.DeleteCustomBinary(secondSubnetName)
})
ginkgo.It("can deploy a custom vm subnet to local SOV", func() {
customVMPath, err := utils.DownloadCustomVMBin(mapping[utils.SoloSubnetEVMKey1])
gomega.Expect(err).Should(gomega.BeNil())
commands.CreateCustomVMConfigSOV(subnetName, utils.SubnetEvmGenesisPoaPath, customVMPath)
deployOutput := commands.DeploySubnetLocallyWithVersionSOV(subnetName, mapping[utils.SoloLuxdKey])
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
}
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(rpcs).Should(gomega.HaveLen(1))
rpc := rpcs[0]
err = utils.SetHardhatRPC(rpc)
gomega.Expect(err).Should(gomega.BeNil())
err = utils.RunHardhatTests(utils.BaseTest)
gomega.Expect(err).Should(gomega.BeNil())
commands.DeleteSubnetConfig(subnetName)
})
ginkgo.It("can deploy a SubnetEvm subnet to local SOV", func() {
commands.CreateSubnetEvmConfigSOV(subnetName, utils.SubnetEvmGenesisPoaPath)
deployOutput := commands.DeploySubnetLocallySOV(subnetName)
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
}
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(rpcs).Should(gomega.HaveLen(1))
rpc := rpcs[0]
err = utils.SetHardhatRPC(rpc)
gomega.Expect(err).Should(gomega.BeNil())
err = utils.RunHardhatTests(utils.BaseTest)
gomega.Expect(err).Should(gomega.BeNil())
commands.DeleteSubnetConfig(subnetName)
})
ginkgo.It("can load viper config and setup node properties for local deploy SOV", func() {
commands.CreateSubnetEvmConfigSOV(subnetName, utils.SubnetEvmGenesisPoaPath)
deployOutput := commands.DeploySubnetLocallyWithViperConfSOV(subnetName, confPath)
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
}
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(rpcs).Should(gomega.HaveLen(1))
rpc := rpcs[0]
gomega.Expect(rpc).Should(gomega.HavePrefix("http://127.0.0.1:"))
commands.DeleteSubnetConfig(subnetName)
})
ginkgo.It("can't deploy the same subnet twice to local SOV", func() {
commands.CreateSubnetEvmConfigSOV(subnetName, utils.SubnetEvmGenesisPoaPath)
deployOutput := commands.DeploySubnetLocallySOV(subnetName)
fmt.Println(deployOutput)
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
}
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(rpcs).Should(gomega.HaveLen(1))
out, err := commands.DeploySubnetLocallyWithArgsAndOutputSOV(subnetName, "", "")
gomega.Expect(err).Should(gomega.HaveOccurred())
deployOutput = string(out)
rpcs, err = utils.ParseRPCsFromOutput(deployOutput)
if err == nil {
fmt.Println(deployOutput)
}
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(rpcs).Should(gomega.HaveLen(0))
gomega.Expect(deployOutput).Should(gomega.ContainSubstring("has already been deployed"))
})
ginkgo.It("can deploy multiple subnets to local SOV", func() {
commands.CreateSubnetEvmConfigSOV(subnetName, utils.SubnetEvmGenesisPoaPath)
commands.CreateSubnetEvmConfigSOV(secondSubnetName, utils.SubnetEvmGenesis2Path)
deployOutput := commands.DeploySubnetLocallySOV(subnetName)
rpcs1, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
}
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(rpcs1).Should(gomega.HaveLen(1))
deployOutput = commands.DeploySubnetLocallySOV(secondSubnetName)
rpcs2, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
}
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(rpcs2).Should(gomega.HaveLen(1))
err = utils.SetHardhatRPC(rpcs1[0])
gomega.Expect(err).Should(gomega.BeNil())
err = utils.RunHardhatTests(utils.BaseTest)
gomega.Expect(err).Should(gomega.BeNil())
err = utils.SetHardhatRPC(rpcs2[0])
gomega.Expect(err).Should(gomega.BeNil())
err = utils.RunHardhatTests(utils.BaseTest)
gomega.Expect(err).Should(gomega.BeNil())
commands.DeleteSubnetConfig(subnetName)
commands.DeleteSubnetConfig(secondSubnetName)
})
ginkgo.It("can list a subnet's validators SOV", func() {
nodeIDs := []string{
"NodeID-MFrZFVCXPv5iCn6M9K6XduxGTYp891xXZ",
"NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg",
}
commands.CreateSubnetEvmConfigSOV(subnetName, utils.SubnetEvmGenesisPoaPath)
deployOutput := commands.DeploySubnetLocallySOV(subnetName)
_, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
}
gomega.Expect(err).Should(gomega.BeNil())
output, err := commands.ListValidators(subnetName, "local")
gomega.Expect(err).Should(gomega.BeNil())
for _, nodeID := range nodeIDs {
gomega.Expect(output).Should(gomega.ContainSubstring(nodeID))
}
commands.DeleteSubnetConfig(subnetName)
})
})
var _ = ginkgo.Describe("[Subnet Compatibility]", func() {
ginkgo.AfterEach(func() {
commands.CleanNetwork()
if err := utils.DeleteConfigs(subnetName); err != nil {
fmt.Println("Clean network error:", err)
gomega.Expect(err).Should(gomega.BeNil())
}
if err := utils.DeleteConfigs(secondSubnetName); err != nil {
fmt.Println("Delete config error:", err)
gomega.Expect(err).Should(gomega.BeNil())
}
})
ginkgo.It("can deploy a subnet-evm with old version SOV", func() {
subnetEVMVersion := mapping[utils.SoloSubnetEVMKey1]
commands.CreateSubnetEvmConfigWithVersionSOV(subnetName, utils.SubnetEvmGenesisPoaPath, subnetEVMVersion)
deployOutput := commands.DeploySubnetLocallySOV(subnetName)
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
}
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(rpcs).Should(gomega.HaveLen(1))
rpc := rpcs[0]
err = utils.SetHardhatRPC(rpc)
gomega.Expect(err).Should(gomega.BeNil())
err = utils.RunHardhatTests(utils.BaseTest)
gomega.Expect(err).Should(gomega.BeNil())
commands.DeleteSubnetConfig(subnetName)
})
ginkgo.It("can't deploy conflicting vm versions SOV", func() {
subnetEVMVersion1 := mapping[utils.SoloSubnetEVMKey1]
subnetEVMVersion2 := "v0.6.12"
commands.CreateSubnetEvmConfigWithVersionSOV(subnetName, utils.SubnetEvmGenesisPoaPath, subnetEVMVersion1)
commands.CreateSubnetEvmConfigWithVersionSOV(secondSubnetName, utils.SubnetEvmGenesis2Path, subnetEVMVersion2)
deployOutput := commands.DeploySubnetLocallySOV(subnetName)
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
}
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(rpcs).Should(gomega.HaveLen(1))
commands.DeploySubnetLocallyExpectErrorSOV(secondSubnetName)
commands.DeleteSubnetConfig(subnetName)
commands.DeleteSubnetConfig(secondSubnetName)
})
})