Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sukantoraymond committed Oct 1, 2024
1 parent 11c9346 commit b5faf60
Show file tree
Hide file tree
Showing 11 changed files with 1,487 additions and 80 deletions.
74 changes: 69 additions & 5 deletions tests/e2e/commands/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
)

/* #nosec G204 */
func CreateSubnetEvmConfig(subnetName string, genesisPath string) (string, string) {
func CreateSubnetEvmConfigNonSOV(subnetName string, genesisPath string) (string, string) {
mapper := utils.NewVersionMapper()
mapping, err := utils.GetVersionMapping(mapper)
gomega.Expect(err).Should(gomega.BeNil())
Expand All @@ -32,6 +32,15 @@ func CreateSubnetEvmConfig(subnetName string, genesisPath string) (string, strin
return mapping[utils.LatestEVM2AvagoKey], mapping[utils.LatestAvago2EVMKey]
}

func CreateSubnetEvmConfigSOV(subnetName string, genesisPath string) (string, string) {
mapper := utils.NewVersionMapper()
mapping, err := utils.GetVersionMapping(mapper)
gomega.Expect(err).Should(gomega.BeNil())
// let's use a SubnetEVM version which has a guaranteed compatible avago
CreateSubnetEvmConfigWithVersionSOV(subnetName, genesisPath, mapping[utils.LatestEVM2AvagoKey])
return mapping[utils.LatestEVM2AvagoKey], mapping[utils.LatestAvago2EVMKey]
}

/* #nosec G204 */
func CreateSubnetEvmConfigWithVersionNonSOV(subnetName string, genesisPath string, version string) {
// Check config does not already exist
Expand Down Expand Up @@ -279,10 +288,14 @@ func DeleteSubnetConfig(subnetName string) {

// Returns the deploy output
/* #nosec G204 */
func DeploySubnetLocally(subnetName string) string {
func DeploySubnetLocallyNonSOV(subnetName string) string {
return DeploySubnetLocallyWithArgsNonSOV(subnetName, "", "")
}

func DeploySubnetLocallySOV(subnetName string) string {
return DeploySubnetLocallyWithArgsSOV(subnetName, "", "")
}

/* #nosec G204 */
func DeploySubnetLocallyExpectError(subnetName string) {
mapper := utils.NewVersionMapper()
Expand All @@ -294,20 +307,32 @@ func DeploySubnetLocallyExpectError(subnetName string) {

// Returns the deploy output
/* #nosec G204 */
func DeploySubnetLocallyWithViperConf(subnetName string, confPath string) string {
func DeploySubnetLocallyWithViperConfNonSOV(subnetName string, confPath string) string {
mapper := utils.NewVersionMapper()
mapping, err := utils.GetVersionMapping(mapper)
gomega.Expect(err).Should(gomega.BeNil())

return DeploySubnetLocallyWithArgsNonSOV(subnetName, mapping[utils.OnlyAvagoKey], confPath)
}

func DeploySubnetLocallyWithViperConfSOV(subnetName string, confPath string) string {
mapper := utils.NewVersionMapper()
mapping, err := utils.GetVersionMapping(mapper)
gomega.Expect(err).Should(gomega.BeNil())

return DeploySubnetLocallyWithArgsSOV(subnetName, mapping[utils.OnlyAvagoKey], confPath)
}

// Returns the deploy output
/* #nosec G204 */
func DeploySubnetLocallyWithVersion(subnetName string, version string) string {
func DeploySubnetLocallyWithVersionNonSOV(subnetName string, version string) string {
return DeploySubnetLocallyWithArgsNonSOV(subnetName, version, "")
}

func DeploySubnetLocallyWithVersionSOV(subnetName string, version string) string {
return DeploySubnetLocallyWithArgsSOV(subnetName, version, "")
}

// Returns the deploy output
/* #nosec G204 */
func DeploySubnetLocallyWithArgsNonSOV(subnetName string, version string, confPath string) string {
Expand Down Expand Up @@ -610,7 +635,46 @@ func SimulateMainnetDeploySOV(

// simulates multisig mainnet deploy execution path on a local network
/* #nosec G204 */
func SimulateMultisigMainnetDeploy(
func SimulateMultisigMainnetDeployNonSOV(
subnetName string,
subnetControlAddrs []string,
chainCreationAuthAddrs []string,
txPath string,
errorIsExpected bool,
) string {
// Check config exists
exists, err := utils.SubnetConfigExists(subnetName)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(exists).Should(gomega.BeTrue())

// enable simulation of public network execution paths on a local network
err = os.Setenv(constants.SimulatePublicNetwork, "true")
gomega.Expect(err).Should(gomega.BeNil())

// Multisig deploy for local subnet with possible tx file generation
return utils.ExecCommand(
CLIBinary,
[]string{
SubnetCmd,
"deploy",
"--mainnet",
"--control-keys",
strings.Join(subnetControlAddrs, ","),
"--subnet-auth-keys",
strings.Join(chainCreationAuthAddrs, ","),
"--output-tx-path",
txPath,
"--mainnet-chain-id",
fmt.Sprint(subnetEVMMainnetChainID),
subnetName,
"--" + constants.SkipUpdateFlag,
},
true,
errorIsExpected,
)
}

func SimulateMultisigMainnetDeploySOV(
subnetName string,
subnetControlAddrs []string,
chainCreationAuthAddrs []string,
Expand Down
15 changes: 13 additions & 2 deletions tests/e2e/testcases/errhandling/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,23 @@ var _ = ginkgo.Describe("[Error handling]", func() {
// delete custom vm
utils.DeleteCustomBinary(subnetName)
})
ginkgo.It("subnet-evm has error but booted", func() {
ginkgo.It("subnet-evm has error but booted non SOV", func() {
// tip: if you really want to run this, reduce the RequestTimeout
ginkgo.Skip("run this manually only, times out")
// this will boot the subnet with a bad genesis:
// the root gas limit is smaller than the fee config gas limit, should fail
commands.CreateSubnetEvmConfig(subnetName, utils.SubnetEvmGenesisBadPath)
commands.CreateSubnetEvmConfigNonSOV(subnetName, utils.SubnetEvmGenesisBadPath)
out, err := commands.DeploySubnetLocallyWithArgsAndOutputNonSOV(subnetName, "", "")
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(out).Should(gomega.ContainSubstring("does not match gas limit"))
fmt.Println(string(out))
})
ginkgo.It("subnet-evm has error but booted SOV", func() {
// tip: if you really want to run this, reduce the RequestTimeout
ginkgo.Skip("run this manually only, times out")
// this will boot the subnet with a bad genesis:
// the root gas limit is smaller than the fee config gas limit, should fail
commands.CreateSubnetEvmConfigSOV(subnetName, utils.SubnetEvmGenesisBadPath)
out, err := commands.DeploySubnetLocallyWithArgsAndOutputNonSOV(subnetName, "", "")
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(out).Should(gomega.ContainSubstring("does not match gas limit"))
Expand Down
95 changes: 89 additions & 6 deletions tests/e2e/testcases/network/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ var _ = ginkgo.Describe("[Network]", ginkgo.Ordered, func() {
gomega.Expect(err).Should(gomega.BeNil())
})

ginkgo.It("can stop and restart a deployed subnet", func() {
commands.CreateSubnetEvmConfig(subnetName, utils.SubnetEvmGenesisPath)
deployOutput := commands.DeploySubnetLocally(subnetName)
ginkgo.It("can stop and restart a deployed subnet non SOV", func() {
commands.CreateSubnetEvmConfigNonSOV(subnetName, utils.SubnetEvmGenesisPath)
deployOutput := commands.DeploySubnetLocallyNonSOV(subnetName)
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
Expand Down Expand Up @@ -79,9 +79,92 @@ var _ = ginkgo.Describe("[Network]", ginkgo.Ordered, func() {
commands.DeleteSubnetConfig(subnetName)
})

ginkgo.It("clean hard deletes plugin binaries", func() {
commands.CreateSubnetEvmConfig(subnetName, utils.SubnetEvmGenesisPath)
deployOutput := commands.DeploySubnetLocally(subnetName)
ginkgo.It("can stop and restart a deployed subnet SOV", func() {
commands.CreateSubnetEvmConfigSOV(subnetName, utils.SubnetEvmGenesisPath)
deployOutput := commands.DeploySubnetLocallyNonSOV(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())

// Deploy greeter contract
scriptOutput, scriptErr, err := utils.RunHardhatScript(utils.GreeterScript)
if scriptErr != "" {
fmt.Println(scriptOutput)
fmt.Println(scriptErr)
}
gomega.Expect(err).Should(gomega.BeNil())
err = utils.ParseGreeterAddress(scriptOutput)
gomega.Expect(err).Should(gomega.BeNil())

// Check greeter script before stopping
scriptOutput, scriptErr, err = utils.RunHardhatScript(utils.GreeterCheck)
if scriptErr != "" {
fmt.Println(scriptOutput)
fmt.Println(scriptErr)
}
gomega.Expect(err).Should(gomega.BeNil())

commands.StopNetwork()
restartOutput := commands.StartNetwork()
rpcs, err = utils.ParseRPCsFromOutput(restartOutput)
if err != nil {
fmt.Println(restartOutput)
}
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())

// Check greeter contract has right value
scriptOutput, scriptErr, err = utils.RunHardhatScript(utils.GreeterCheck)
if scriptErr != "" {
fmt.Println(scriptOutput)
fmt.Println(scriptErr)
}
gomega.Expect(err).Should(gomega.BeNil())

commands.DeleteSubnetConfig(subnetName)
})

ginkgo.It("clean hard deletes plugin binaries non SOV", func() {
commands.CreateSubnetEvmConfigNonSOV(subnetName, utils.SubnetEvmGenesisPath)
deployOutput := commands.DeploySubnetLocallyNonSOV(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))

// check that plugin binaries exist
plugins, err := utils.GetPluginBinaries()
// should have only subnet-evm binary
gomega.Expect(len(plugins)).Should(gomega.Equal(1))
gomega.Expect(err).Should(gomega.BeNil())

commands.CleanNetwork()

// check that plugin binaries exist
plugins, err = utils.GetPluginBinaries()
// should be empty
gomega.Expect(len(plugins)).Should(gomega.Equal(0))
gomega.Expect(err).Should(gomega.BeNil())

commands.DeleteSubnetConfig(subnetName)
})

ginkgo.It("clean hard deletes plugin binaries SOV", func() {
commands.CreateSubnetEvmConfigSOV(subnetName, utils.SubnetEvmGenesisPath)
deployOutput := commands.DeploySubnetLocallyNonSOV(subnetName)
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/testcases/packageman/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var _ = ginkgo.Describe("[Package Management]", ginkgo.Ordered, func() {
gomega.Expect(utils.CheckAvalancheGoExists(binaryToVersion[utils.SoloAvagoKey])).Should(gomega.BeFalse())

commands.CreateSubnetEvmConfigWithVersionNonSOV(subnetName, utils.SubnetEvmGenesisPath, binaryToVersion[utils.SoloSubnetEVMKey1])
deployOutput := commands.DeploySubnetLocallyWithVersion(subnetName, binaryToVersion[utils.SoloAvagoKey])
deployOutput := commands.DeploySubnetLocallyWithVersionNonSOV(subnetName, binaryToVersion[utils.SoloAvagoKey])
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
Expand Down Expand Up @@ -76,15 +76,15 @@ var _ = ginkgo.Describe("[Package Management]", ginkgo.Ordered, func() {
commands.CreateSubnetEvmConfigWithVersionNonSOV(subnetName, utils.SubnetEvmGenesisPath, binaryToVersion[utils.SoloSubnetEVMKey1])
commands.CreateSubnetEvmConfigWithVersionNonSOV(secondSubnetName, utils.SubnetEvmGenesis2Path, binaryToVersion[utils.SoloSubnetEVMKey2])

deployOutput := commands.DeploySubnetLocally(subnetName)
deployOutput := commands.DeploySubnetLocallyNonSOV(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.DeploySubnetLocally(secondSubnetName)
deployOutput = commands.DeploySubnetLocallyNonSOV(secondSubnetName)
rpcs2, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
Expand Down Expand Up @@ -118,7 +118,7 @@ var _ = ginkgo.Describe("[Package Management]", ginkgo.Ordered, func() {
gomega.Expect(utils.CheckAvalancheGoExists(binaryToVersion[utils.MultiAvago2Key])).Should(gomega.BeFalse())

commands.CreateSubnetEvmConfigWithVersionNonSOV(subnetName, utils.SubnetEvmGenesisPath, binaryToVersion[utils.MultiAvagoSubnetEVMKey])
deployOutput := commands.DeploySubnetLocallyWithVersion(subnetName, binaryToVersion[utils.MultiAvago1Key])
deployOutput := commands.DeploySubnetLocallyWithVersionNonSOV(subnetName, binaryToVersion[utils.MultiAvago1Key])
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
Expand Down Expand Up @@ -149,7 +149,7 @@ var _ = ginkgo.Describe("[Package Management]", ginkgo.Ordered, func() {

commands.CleanNetwork()

deployOutput = commands.DeploySubnetLocallyWithVersion(subnetName, binaryToVersion[utils.MultiAvago2Key])
deployOutput = commands.DeploySubnetLocallyWithVersionNonSOV(subnetName, binaryToVersion[utils.MultiAvago2Key])
rpcs, err = utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
fmt.Println(deployOutput)
Expand Down
Loading

0 comments on commit b5faf60

Please sign in to comment.