mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
200 lines
3.7 KiB
Go
200 lines
3.7 KiB
Go
// Copyright (C) 2022, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
|
|
"github.com/luxfi/cli/v2/pkg/constants"
|
|
"github.com/luxfi/cli/v2/tests/e2e/utils"
|
|
"github.com/onsi/gomega"
|
|
)
|
|
|
|
/* #nosec G204 */
|
|
func ImportUpgradeBytes(subnetName, filepath string) (string, error) {
|
|
cmd := exec.Command(
|
|
CLIBinary,
|
|
SubnetCmd,
|
|
UpgradeCmd,
|
|
"import",
|
|
subnetName,
|
|
"--upgrade-filepath",
|
|
filepath,
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
fmt.Println(cmd.String())
|
|
fmt.Println(string(output))
|
|
utils.PrintStdErr(err)
|
|
}
|
|
return string(output), err
|
|
}
|
|
|
|
/* #nosec G204 */
|
|
func UpgradeVMConfig(subnetName string, targetVersion string) (string, error) {
|
|
cmd := exec.Command(
|
|
CLIBinary,
|
|
SubnetCmd,
|
|
UpgradeCmd,
|
|
"vm",
|
|
subnetName,
|
|
"--config",
|
|
"--version",
|
|
targetVersion,
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
fmt.Println(cmd.String())
|
|
fmt.Println(string(output))
|
|
utils.PrintStdErr(err)
|
|
}
|
|
return string(output), err
|
|
}
|
|
|
|
/* #nosec G204 */
|
|
func UpgradeCustomVM(subnetName string, binaryPath string) (string, error) {
|
|
cmd := exec.Command(
|
|
CLIBinary,
|
|
SubnetCmd,
|
|
UpgradeCmd,
|
|
"vm",
|
|
subnetName,
|
|
"--config",
|
|
"--binary",
|
|
binaryPath,
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
|
|
output, err := cmd.Output()
|
|
if err != nil {
|
|
fmt.Println(cmd.String())
|
|
fmt.Println(string(output))
|
|
utils.PrintStdErr(err)
|
|
}
|
|
return string(output), err
|
|
}
|
|
|
|
/* #nosec G204 */
|
|
func UpgradeVMPublic(subnetName string, targetVersion string, pluginDir string) (string, error) {
|
|
cmd := exec.Command(
|
|
CLIBinary,
|
|
SubnetCmd,
|
|
UpgradeCmd,
|
|
"vm",
|
|
subnetName,
|
|
"--testnet",
|
|
"--version",
|
|
targetVersion,
|
|
"--plugin-dir",
|
|
pluginDir,
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
fmt.Println(cmd.String())
|
|
fmt.Println(string(output))
|
|
utils.PrintStdErr(err)
|
|
}
|
|
return string(output), err
|
|
}
|
|
|
|
/* #nosec G204 */
|
|
func UpgradeVMLocal(subnetName string, targetVersion string) string {
|
|
cmd := exec.Command(
|
|
CLIBinary,
|
|
SubnetCmd,
|
|
UpgradeCmd,
|
|
"vm",
|
|
subnetName,
|
|
"--local",
|
|
"--version",
|
|
targetVersion,
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
fmt.Println(cmd.String())
|
|
fmt.Println(string(output))
|
|
utils.PrintStdErr(err)
|
|
}
|
|
|
|
gomega.Expect(err).Should(gomega.BeNil())
|
|
return string(output)
|
|
}
|
|
|
|
/* #nosec G204 */
|
|
func UpgradeCustomVMLocal(subnetName string, binaryPath string) string {
|
|
cmd := exec.Command(
|
|
CLIBinary,
|
|
SubnetCmd,
|
|
UpgradeCmd,
|
|
"vm",
|
|
subnetName,
|
|
"--local",
|
|
"--binary",
|
|
binaryPath,
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
|
|
output, err := cmd.Output()
|
|
if err != nil {
|
|
fmt.Println(cmd.String())
|
|
fmt.Println(string(output))
|
|
utils.PrintStdErr(err)
|
|
}
|
|
gomega.Expect(err).Should(gomega.BeNil())
|
|
return string(output)
|
|
}
|
|
|
|
/* #nosec G204 */
|
|
func ApplyUpgradeLocal(subnetName string) (string, error) {
|
|
cmd := exec.Command(
|
|
CLIBinary,
|
|
SubnetCmd,
|
|
UpgradeCmd,
|
|
"apply",
|
|
subnetName,
|
|
"--local",
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
fmt.Println(cmd.String())
|
|
fmt.Println(string(output))
|
|
utils.PrintStdErr(err)
|
|
}
|
|
return string(output), err
|
|
}
|
|
|
|
/* #nosec G204 */
|
|
func ApplyUpgradeToPublicNode(subnetName, luxChainConfDir string) (string, error) {
|
|
cmd := exec.Command(
|
|
CLIBinary,
|
|
SubnetCmd,
|
|
UpgradeCmd,
|
|
"apply",
|
|
subnetName,
|
|
"--testnet",
|
|
"--node-chain-config-dir",
|
|
luxChainConfDir,
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
fmt.Println(cmd.String())
|
|
fmt.Println(string(output))
|
|
utils.PrintStdErr(err)
|
|
}
|
|
return string(output), err
|
|
}
|