Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
sukantoraymond committed Sep 30, 2024
1 parent a05a1b6 commit d489e48
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 31 deletions.
251 changes: 240 additions & 11 deletions tests/e2e/commands/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,52 @@ func CreateSubnetEvmConfig(subnetName string, genesisPath string) (string, strin
mapping, err := utils.GetVersionMapping(mapper)
gomega.Expect(err).Should(gomega.BeNil())
// let's use a SubnetEVM version which has a guaranteed compatible avago
CreateSubnetEvmConfigWithVersion(subnetName, genesisPath, mapping[utils.LatestEVM2AvagoKey])
CreateSubnetEvmConfigWithVersionNonSOV(subnetName, genesisPath, mapping[utils.LatestEVM2AvagoKey])
return mapping[utils.LatestEVM2AvagoKey], mapping[utils.LatestAvago2EVMKey]
}

/* #nosec G204 */
func CreateSubnetEvmConfigWithVersion(subnetName string, genesisPath string, version string) {
func CreateSubnetEvmConfigWithVersionNonSOV(subnetName string, genesisPath string, version string) {
// Check config does not already exist
exists, err := utils.SubnetConfigExists(subnetName)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(exists).Should(gomega.BeFalse())

// Create config
cmdArgs := []string{
SubnetCmd,
"create",
"--genesis",
genesisPath,
"--evm",
subnetName,
"--" + constants.SkipUpdateFlag,
"--teleporter=false",
"--not-sov",
"--evm-token",
"TOK",
}
if version == "" {
cmdArgs = append(cmdArgs, "--latest")
} else {
cmdArgs = append(cmdArgs, "--vm-version", version)
}
cmd := exec.Command(CLIBinary, cmdArgs...)
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(cmd.String())
fmt.Println(string(output))
utils.PrintStdErr(err)
}
gomega.Expect(err).Should(gomega.BeNil())

// Config should now exist
exists, err = utils.SubnetConfigExists(subnetName)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(exists).Should(gomega.BeTrue())
}

func CreateSubnetEvmConfigWithVersionSOV(subnetName string, genesisPath string, version string) {
// Check config does not already exist
exists, err := utils.SubnetConfigExists(subnetName)
gomega.Expect(err).Should(gomega.BeNil())
Expand Down Expand Up @@ -112,7 +152,58 @@ func ConfigurePerNodeChainConfig(subnetName string, perNodeChainConfigPath strin
}

/* #nosec G204 */
func CreateCustomVMConfig(subnetName string, genesisPath string, vmPath string) {
func CreateCustomVMConfigNonSOV(subnetName string, genesisPath string, vmPath string) {
// Check config does not already exist
exists, err := utils.SubnetConfigExists(subnetName)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(exists).Should(gomega.BeFalse())
// Check vm binary does not already exist
exists, err = utils.SubnetCustomVMExists(subnetName)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(exists).Should(gomega.BeFalse())

// Create config
cmd := exec.Command(
CLIBinary,
SubnetCmd,
"create",
"--genesis",
genesisPath,
"--not-sov",
"--custom",
subnetName,
"--custom-vm-path",
vmPath,
"--"+constants.SkipUpdateFlag,
"--teleporter=false",
"--evm-token",
"TOK",
)
output, err := cmd.CombinedOutput()
if err != nil {
var (
exitErr *exec.ExitError
stderr string
)
if errors.As(err, &exitErr) {
stderr = string(exitErr.Stderr)
}
fmt.Println(string(output))
utils.PrintStdErr(err)
fmt.Println(stderr)
gomega.Expect(err).Should(gomega.BeNil())
}

// Config should now exist
exists, err = utils.SubnetConfigExists(subnetName)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(exists).Should(gomega.BeTrue())
exists, err = utils.SubnetCustomVMExists(subnetName)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(exists).Should(gomega.BeTrue())
}

func CreateCustomVMConfigSOV(subnetName string, genesisPath string, vmPath string) {
// Check config does not already exist
exists, err := utils.SubnetConfigExists(subnetName)
gomega.Expect(err).Should(gomega.BeNil())
Expand Down Expand Up @@ -191,7 +282,7 @@ func DeleteSubnetConfig(subnetName string) {
// Returns the deploy output
/* #nosec G204 */
func DeploySubnetLocally(subnetName string) string {
return DeploySubnetLocallyWithArgs(subnetName, "", "")
return DeploySubnetLocallyWithArgsNonSOV(subnetName, "", "")
}

/* #nosec G204 */
Expand All @@ -210,18 +301,56 @@ func DeploySubnetLocallyWithViperConf(subnetName string, confPath string) string
mapping, err := utils.GetVersionMapping(mapper)
gomega.Expect(err).Should(gomega.BeNil())

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

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

// Returns the deploy output
/* #nosec G204 */
func DeploySubnetLocallyWithArgs(subnetName string, version string, confPath string) string {
func DeploySubnetLocallyWithArgsNonSOV(subnetName string, version string, confPath string) string {
// Check config exists
exists, err := utils.SubnetConfigExists(subnetName)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(exists).Should(gomega.BeTrue())

// Deploy subnet locally
cmdArgs := []string{SubnetCmd, "deploy", "--local", subnetName, "--" + constants.SkipUpdateFlag}
if version != "" {
cmdArgs = append(cmdArgs, "--avalanchego-version", version)
}
if confPath != "" {
cmdArgs = append(cmdArgs, "--config", confPath)
}
// in case we want to use specific avago for local tests
debugAvalanchegoPath := os.Getenv(constants.E2EDebugAvalanchegoPath)
if debugAvalanchegoPath != "" {
cmdArgs = append(cmdArgs, "--avalanchego-path", debugAvalanchegoPath)
}
cmd := exec.Command(CLIBinary, cmdArgs...)
output, err := cmd.CombinedOutput()
if err != nil {
var (
exitErr *exec.ExitError
stderr string
)
if errors.As(err, &exitErr) {
stderr = string(exitErr.Stderr)
}
fmt.Println(string(output))
utils.PrintStdErr(err)
fmt.Println(stderr)
}
gomega.Expect(err).Should(gomega.BeNil())

return string(output)
}

func DeploySubnetLocallyWithArgsSOV(subnetName string, version string, confPath string) string {
// Check config exists
exists, err := utils.SubnetConfigExists(subnetName)
gomega.Expect(err).Should(gomega.BeNil())
Expand Down Expand Up @@ -259,7 +388,30 @@ func DeploySubnetLocallyWithArgs(subnetName string, version string, confPath str
return string(output)
}

func DeploySubnetLocallyWithArgsAndOutput(subnetName string, version string, confPath string) ([]byte, error) {
func DeploySubnetLocallyWithArgsAndOutputNonSOV(subnetName string, version string, confPath string) ([]byte, error) {
// Check config exists
exists, err := utils.SubnetConfigExists(subnetName)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(exists).Should(gomega.BeTrue())

// Deploy subnet locally
cmdArgs := []string{SubnetCmd, "deploy", "--local", subnetName, "--" + constants.SkipUpdateFlag}
if version != "" {
cmdArgs = append(cmdArgs, "--avalanchego-version", version)
}
if confPath != "" {
cmdArgs = append(cmdArgs, "--config", confPath)
}
// in case we want to use specific avago for local tests
debugAvalanchegoPath := os.Getenv(constants.E2EDebugAvalanchegoPath)
if debugAvalanchegoPath != "" {
cmdArgs = append(cmdArgs, "--avalanchego-path", debugAvalanchegoPath)
}
cmd := exec.Command(CLIBinary, cmdArgs...)
return cmd.CombinedOutput()
}

func DeploySubnetLocallyWithArgsAndOutputSOV(subnetName string, version string, confPath string) ([]byte, error) {
// Check config exists
exists, err := utils.SubnetConfigExists(subnetName)
gomega.Expect(err).Should(gomega.BeNil())
Expand All @@ -284,7 +436,7 @@ func DeploySubnetLocallyWithArgsAndOutput(subnetName string, version string, con

/* #nosec G204 */
func DeploySubnetLocallyWithArgsExpectError(subnetName string, version string, confPath string) {
_, err := DeploySubnetLocallyWithArgsAndOutput(subnetName, version, confPath)
_, err := DeploySubnetLocallyWithArgsAndOutputNonSOV(subnetName, version, confPath)
gomega.Expect(err).Should(gomega.HaveOccurred())
}

Expand Down Expand Up @@ -337,7 +489,45 @@ func SimulateFujiDeploy(

// simulates mainnet deploy execution path on a local network
/* #nosec G204 */
func SimulateMainnetDeploy(
func SimulateMainnetDeployNonSOV(
subnetName string,
mainnetChainID int,
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())

if mainnetChainID == 0 {
mainnetChainID = subnetEVMMainnetChainID
}

// Deploy subnet locally
return utils.ExecCommand(
CLIBinary,
[]string{
SubnetCmd,
"deploy",
"--mainnet",
"--threshold",
"1",
"--same-control-key",
"--mainnet-chain-id",
fmt.Sprint(mainnetChainID),
subnetName,
"--" + constants.SkipUpdateFlag,
},
true,
errorIsExpected,
)
}

func SimulateMainnetDeploySOV(
subnetName string,
mainnetChainID int,
errorIsExpected bool,
Expand Down Expand Up @@ -378,7 +568,46 @@ func SimulateMainnetDeploy(

// 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
2 changes: 1 addition & 1 deletion tests/e2e/testcases/errhandling/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var _ = ginkgo.Describe("[Error handling]", func() {
// 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)
out, err := commands.DeploySubnetLocallyWithArgsAndOutput(subnetName, "", "")
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))
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/testcases/packageman/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = ginkgo.Describe("[Package Management]", ginkgo.Ordered, func() {
gomega.Expect(utils.CheckSubnetEVMExists(binaryToVersion[utils.SoloSubnetEVMKey1])).Should(gomega.BeFalse())
gomega.Expect(utils.CheckAvalancheGoExists(binaryToVersion[utils.SoloAvagoKey])).Should(gomega.BeFalse())

commands.CreateSubnetEvmConfigWithVersion(subnetName, utils.SubnetEvmGenesisPath, binaryToVersion[utils.SoloSubnetEVMKey1])
commands.CreateSubnetEvmConfigWithVersionNonSOV(subnetName, utils.SubnetEvmGenesisPath, binaryToVersion[utils.SoloSubnetEVMKey1])
deployOutput := commands.DeploySubnetLocallyWithVersion(subnetName, binaryToVersion[utils.SoloAvagoKey])
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
Expand Down Expand Up @@ -73,8 +73,8 @@ var _ = ginkgo.Describe("[Package Management]", ginkgo.Ordered, func() {
gomega.Expect(utils.CheckSubnetEVMExists(binaryToVersion[utils.SoloSubnetEVMKey1])).Should(gomega.BeFalse())
gomega.Expect(utils.CheckSubnetEVMExists(binaryToVersion[utils.SoloSubnetEVMKey2])).Should(gomega.BeFalse())

commands.CreateSubnetEvmConfigWithVersion(subnetName, utils.SubnetEvmGenesisPath, binaryToVersion[utils.SoloSubnetEVMKey1])
commands.CreateSubnetEvmConfigWithVersion(secondSubnetName, utils.SubnetEvmGenesis2Path, binaryToVersion[utils.SoloSubnetEVMKey2])
commands.CreateSubnetEvmConfigWithVersionNonSOV(subnetName, utils.SubnetEvmGenesisPath, binaryToVersion[utils.SoloSubnetEVMKey1])
commands.CreateSubnetEvmConfigWithVersionNonSOV(secondSubnetName, utils.SubnetEvmGenesis2Path, binaryToVersion[utils.SoloSubnetEVMKey2])

deployOutput := commands.DeploySubnetLocally(subnetName)
rpcs1, err := utils.ParseRPCsFromOutput(deployOutput)
Expand Down Expand Up @@ -117,7 +117,7 @@ var _ = ginkgo.Describe("[Package Management]", ginkgo.Ordered, func() {
gomega.Expect(utils.CheckAvalancheGoExists(binaryToVersion[utils.MultiAvago1Key])).Should(gomega.BeFalse())
gomega.Expect(utils.CheckAvalancheGoExists(binaryToVersion[utils.MultiAvago2Key])).Should(gomega.BeFalse())

commands.CreateSubnetEvmConfigWithVersion(subnetName, utils.SubnetEvmGenesisPath, binaryToVersion[utils.MultiAvagoSubnetEVMKey])
commands.CreateSubnetEvmConfigWithVersionNonSOV(subnetName, utils.SubnetEvmGenesisPath, binaryToVersion[utils.MultiAvagoSubnetEVMKey])
deployOutput := commands.DeploySubnetLocallyWithVersion(subnetName, binaryToVersion[utils.MultiAvago1Key])
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/testcases/subnet/local/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var _ = ginkgo.Describe("[Local Subnet]", ginkgo.Ordered, func() {
ginkgo.It("can deploy a custom vm subnet to local", func() {
customVMPath, err := utils.DownloadCustomVMBin(mapping[utils.SoloSubnetEVMKey1])
gomega.Expect(err).Should(gomega.BeNil())
commands.CreateCustomVMConfig(subnetName, utils.SubnetEvmGenesisPath, customVMPath)
commands.CreateCustomVMConfigNonSOV(subnetName, utils.SubnetEvmGenesisPath, customVMPath)
deployOutput := commands.DeploySubnetLocallyWithVersion(subnetName, mapping[utils.SoloAvagoKey])
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
Expand Down Expand Up @@ -126,7 +126,7 @@ var _ = ginkgo.Describe("[Local Subnet]", ginkgo.Ordered, func() {
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(rpcs).Should(gomega.HaveLen(1))

out, err := commands.DeploySubnetLocallyWithArgsAndOutput(subnetName, "", "")
out, err := commands.DeploySubnetLocallyWithArgsAndOutputNonSOV(subnetName, "", "")
gomega.Expect(err).Should(gomega.HaveOccurred())
deployOutput = string(out)
rpcs, err = utils.ParseRPCsFromOutput(deployOutput)
Expand Down Expand Up @@ -323,7 +323,7 @@ var _ = ginkgo.Describe("[Subnet Compatibility]", func() {
ginkgo.It("can deploy a subnet-evm with old version", func() {
subnetEVMVersion := "v0.6.6"

commands.CreateSubnetEvmConfigWithVersion(subnetName, utils.SubnetEvmGenesisPath, subnetEVMVersion)
commands.CreateSubnetEvmConfigWithVersionNonSOV(subnetName, utils.SubnetEvmGenesisPath, subnetEVMVersion)
deployOutput := commands.DeploySubnetLocally(subnetName)
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
if err != nil {
Expand All @@ -347,8 +347,8 @@ var _ = ginkgo.Describe("[Subnet Compatibility]", func() {
subnetEVMVersion1 := "v0.6.6"
subnetEVMVersion2 := "v0.6.2"

commands.CreateSubnetEvmConfigWithVersion(subnetName, utils.SubnetEvmGenesisPath, subnetEVMVersion1)
commands.CreateSubnetEvmConfigWithVersion(secondSubnetName, utils.SubnetEvmGenesis2Path, subnetEVMVersion2)
commands.CreateSubnetEvmConfigWithVersionNonSOV(subnetName, utils.SubnetEvmGenesisPath, subnetEVMVersion1)
commands.CreateSubnetEvmConfigWithVersionNonSOV(secondSubnetName, utils.SubnetEvmGenesis2Path, subnetEVMVersion2)

deployOutput := commands.DeploySubnetLocally(subnetName)
rpcs, err := utils.ParseRPCsFromOutput(deployOutput)
Expand Down
Loading

0 comments on commit d489e48

Please sign in to comment.