mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
The node moved every chain route from /v1/bc/<alias> to /v1/chain/<alias> and deleted the old prefix, so every chain call answered 404. The address was spelled out at 112 sites across 34 files and constants.ChainAliasPrefix was used at none of them, which is why nothing failed to compile when the segment moved. route.Chain(uri, alias) composes it now, and route.Alias reads one back, replacing three hand-rolled parsers — one of which took the alias by position in the split path and only worked because the new segment happens to leave the component count unchanged. TestChainAddressBuiltOnlyHere walks every .go file in the module and fails on a chain address in a string literal, so the segment cannot drift back; prose is free to name a route. TestGuardCatchesEachShape plants each forbidden shape and requires the guard to find it. The endpoint box and the eleven-chain table were the same list written twice; there is one list, rendered once, measured rather than hand-padded. The generated CLI reference and the faucet manifest compose through the same function. Co-authored-by: Hanzo Dev <[email protected]>
357 lines
8.2 KiB
Go
357 lines
8.2 KiB
Go
// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/luxfi/cli/pkg/route"
|
|
"github.com/luxfi/cli/tests/e2e/utils"
|
|
"github.com/luxfi/constants"
|
|
"github.com/onsi/gomega"
|
|
)
|
|
|
|
type ChainManagementType uint
|
|
|
|
const (
|
|
Unknown ChainManagementType = iota
|
|
PoA
|
|
PoS
|
|
)
|
|
|
|
const (
|
|
PoSString = "proof-of-stake"
|
|
PoAString = "proof-of-authority"
|
|
)
|
|
|
|
func CreateSovEVMConfig(
|
|
chainName string,
|
|
ewoqEVMAddress string,
|
|
chainManagementType ChainManagementType,
|
|
) (string, string) {
|
|
// Check config does not already exist
|
|
exists, err := utils.ChainConfigExists(chainName)
|
|
gomega.Expect(err).Should(gomega.BeNil())
|
|
gomega.Expect(exists).Should(gomega.BeFalse())
|
|
|
|
rewardBasisPoints := ""
|
|
chainManagementStr := PoAString
|
|
if chainManagementType == PoS {
|
|
rewardBasisPoints = "--reward-basis-points=1000000000"
|
|
chainManagementStr = PoSString
|
|
}
|
|
// Create config
|
|
cmd := exec.Command( //nolint:gosec // G204: Running our own CLI binary in tests
|
|
CLIBinary,
|
|
"blockchain",
|
|
"create",
|
|
chainName,
|
|
"--evm",
|
|
fmt.Sprintf("--%s", chainManagementStr),
|
|
"--validator-manager-owner",
|
|
ewoqEVMAddress,
|
|
"--proxy-contract-owner",
|
|
ewoqEVMAddress,
|
|
"--test-defaults",
|
|
"--evm-chain-id=99999",
|
|
"--evm-token=TOK",
|
|
"--warp=false",
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
if rewardBasisPoints != "" {
|
|
cmd.Args = append(cmd.Args, rewardBasisPoints)
|
|
}
|
|
fmt.Println(cmd)
|
|
output, err := cmd.CombinedOutput()
|
|
fmt.Println(string(output))
|
|
if err != nil {
|
|
fmt.Println(cmd.String())
|
|
utils.PrintStdErr(err)
|
|
}
|
|
gomega.Expect(err).Should(gomega.BeNil())
|
|
|
|
// Config should now exist
|
|
exists, err = utils.ChainConfigExists(chainName)
|
|
gomega.Expect(err).Should(gomega.BeNil())
|
|
gomega.Expect(exists).Should(gomega.BeTrue())
|
|
|
|
// return binary versions for this conf
|
|
mapper := utils.NewVersionMapper()
|
|
mapping, err := utils.GetVersionMapping(mapper)
|
|
gomega.Expect(err).Should(gomega.BeNil())
|
|
return mapping[utils.LatestEVM2LuxdKey], mapping[utils.LatestLuxd2EVMKey]
|
|
}
|
|
|
|
func CreateLocalSovNode(
|
|
luxdVersion string,
|
|
clusterName string,
|
|
numNodes int,
|
|
) (string, error) {
|
|
cmd := exec.Command( //nolint:gosec // G204: Running our own CLI binary in tests
|
|
CLIBinary,
|
|
"node",
|
|
"local",
|
|
"start",
|
|
clusterName,
|
|
"--local",
|
|
"--num-nodes",
|
|
fmt.Sprintf("%d", numNodes),
|
|
"--custom-luxd-version",
|
|
luxdVersion,
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
fmt.Println(cmd)
|
|
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), err
|
|
}
|
|
|
|
func DestroyLocalNode(
|
|
clusterName string,
|
|
) (string, error) {
|
|
cmd := exec.Command( //nolint:gosec // G204: Running our own CLI binary in tests
|
|
CLIBinary,
|
|
"node",
|
|
"local",
|
|
"destroy",
|
|
clusterName,
|
|
"--"+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), err
|
|
}
|
|
|
|
func DeploySovBlockchain(
|
|
chainName string,
|
|
clusterName string,
|
|
bootstrapEndpoints []string,
|
|
ewoqPChainAddress string,
|
|
convertOnly bool,
|
|
) (string, error) {
|
|
convertOnlyFlag := ""
|
|
if convertOnly {
|
|
convertOnlyFlag = "--convert-only"
|
|
}
|
|
bootstrapEndpointsFlag := ""
|
|
if len(bootstrapEndpoints) > 0 {
|
|
bootstrapEndpointsFlag = "--bootstrap-endpoints=" + strings.Join(bootstrapEndpoints, ",")
|
|
}
|
|
// Check config exists
|
|
exists, err := utils.ChainConfigExists(chainName)
|
|
gomega.Expect(err).Should(gomega.BeNil())
|
|
gomega.Expect(exists).Should(gomega.BeTrue())
|
|
|
|
// Deploy chain on sov local network with local machine as bootstrap validator
|
|
args := []string{
|
|
"blockchain",
|
|
"deploy",
|
|
chainName,
|
|
"--ewoq",
|
|
"--change-owner-address",
|
|
ewoqPChainAddress,
|
|
"--" + constants.SkipUpdateFlag,
|
|
}
|
|
if clusterName != "" {
|
|
args = append(args, "--cluster", clusterName)
|
|
} else {
|
|
args = append(args, "--local")
|
|
}
|
|
if convertOnlyFlag != "" {
|
|
args = append(args, convertOnlyFlag)
|
|
}
|
|
if bootstrapEndpointsFlag != "" {
|
|
args = append(args, bootstrapEndpointsFlag)
|
|
}
|
|
cmd := exec.Command(CLIBinary, args...) //nolint:gosec // G204: Running our own CLI binary in tests
|
|
fmt.Println(cmd)
|
|
output, err := cmd.CombinedOutput()
|
|
fmt.Println(string(output))
|
|
if err != nil {
|
|
fmt.Println(cmd.String())
|
|
utils.PrintStdErr(err)
|
|
}
|
|
gomega.Expect(err).Should(gomega.BeNil())
|
|
return string(output), err
|
|
}
|
|
|
|
func TrackLocalSovChain(
|
|
clusterName string,
|
|
chainName string,
|
|
) (string, error) {
|
|
cmd := exec.Command( //nolint:gosec // G204: Running our own CLI binary in tests
|
|
CLIBinary,
|
|
"node",
|
|
"local",
|
|
"track",
|
|
clusterName,
|
|
chainName,
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
fmt.Println(cmd)
|
|
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), err
|
|
}
|
|
|
|
func InitValidatorManager(
|
|
chainName string,
|
|
clusterName string,
|
|
endpoint string,
|
|
blockchainID string,
|
|
) (string, error) {
|
|
cmd := exec.Command( //nolint:gosec // G204: Running our own CLI binary in tests
|
|
CLIBinary,
|
|
"contract",
|
|
"initValidatorManager",
|
|
chainName,
|
|
"--cluster",
|
|
clusterName,
|
|
"--endpoint",
|
|
endpoint,
|
|
"--rpc",
|
|
route.Chain(endpoint, blockchainID)+"/rpc",
|
|
"--genesis-key",
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
fmt.Println(cmd)
|
|
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), err
|
|
}
|
|
|
|
func AddSovChainValidatorToCluster(
|
|
clusterName string,
|
|
chainName string,
|
|
nodeEndpoint string,
|
|
ewoqPChainAddress string,
|
|
balance int,
|
|
createLocalValidator bool,
|
|
) (string, error) {
|
|
cmd := exec.Command( //nolint:gosec // G204: Running our own CLI binary in tests
|
|
CLIBinary,
|
|
"blockchain",
|
|
"addValidator",
|
|
chainName,
|
|
"--ewoq",
|
|
"--balance",
|
|
strconv.Itoa(balance),
|
|
"--remaining-balance-owner",
|
|
ewoqPChainAddress,
|
|
"--disable-owner",
|
|
ewoqPChainAddress,
|
|
"--delegation-fee",
|
|
"100",
|
|
"--rewards-recipient",
|
|
utils.TreasuryEVMAddress,
|
|
"--staking-period",
|
|
"100s",
|
|
"--weight",
|
|
strconv.Itoa(constants.DefaultStakeWeight),
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
if clusterName != "" {
|
|
cmd.Args = append(cmd.Args, "--cluster", clusterName)
|
|
} else {
|
|
cmd.Args = append(cmd.Args, "--local")
|
|
}
|
|
if nodeEndpoint != "" {
|
|
cmd.Args = append(cmd.Args, "--node-endpoint", nodeEndpoint)
|
|
}
|
|
if createLocalValidator {
|
|
cmd.Args = append(cmd.Args, "--create-local-validator")
|
|
}
|
|
fmt.Println(cmd)
|
|
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), err
|
|
}
|
|
|
|
func RemoveSovChainValidatorFromCluster(
|
|
clusterName string,
|
|
chainName string,
|
|
nodeEndpoint string,
|
|
keyName string,
|
|
uptimeSec uint64,
|
|
) (string, error) {
|
|
cmd := exec.Command( //nolint:gosec // G204: Running our own CLI binary in tests
|
|
CLIBinary,
|
|
"blockchain",
|
|
"removeValidator",
|
|
chainName,
|
|
"--cluster",
|
|
clusterName,
|
|
"--node-endpoint",
|
|
nodeEndpoint,
|
|
"--key",
|
|
keyName,
|
|
"--uptime",
|
|
strconv.Itoa(int(uptimeSec)), //nolint:gosec // G115: uptimeSec is bounded by test duration
|
|
"--force",
|
|
"--"+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), err
|
|
}
|
|
|
|
func GetLocalClusterStatus(
|
|
clusterName string,
|
|
blockchainName string,
|
|
) (string, error) {
|
|
cmd := exec.Command( //nolint:gosec // G204: Running our own CLI binary in tests
|
|
CLIBinary,
|
|
"node",
|
|
"local",
|
|
"status",
|
|
clusterName,
|
|
"--"+constants.SkipUpdateFlag,
|
|
)
|
|
if blockchainName != "" {
|
|
cmd.Args = append(cmd.Args, "--blockchain", blockchainName)
|
|
}
|
|
fmt.Println(cmd)
|
|
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), err
|
|
}
|