Files

382 lines
19 KiB
Go

// Copyright (C) 2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package convert
import (
"fmt"
"runtime"
"github.com/luxfi/cli/v2/cmd"
"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 = "testSubnet"
)
const ewoqEVMAddress = "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"
func checkConvertOnlyOutput(output string, generateNodeID bool) {
gomega.Expect(output).Should(gomega.ContainSubstring("Converted blockchain successfully generated"))
gomega.Expect(output).Should(gomega.ContainSubstring("Have the Lux node(s) track the blockchain"))
gomega.Expect(output).Should(gomega.ContainSubstring("Call `lux contract initValidatorManager testSubnet`"))
gomega.Expect(output).Should(gomega.ContainSubstring("Ensure that the P2P port is exposed and 'public-ip' config value is set"))
gomega.Expect(output).Should(gomega.ContainSubstring("Subnet is successfully converted to sovereign L1"))
if generateNodeID {
gomega.Expect(output).Should(gomega.ContainSubstring("Create the corresponding Lux node(s) with the provided Node ID and BLS Info"))
} else {
gomega.Expect(output).ShouldNot(gomega.ContainSubstring("Create the corresponding Lux node(s) with the provided Node ID and BLS Info"))
}
}
var _ = ginkgo.Describe("[Blockchain Convert]", ginkgo.Ordered, func() {
blockchainCmdArgs := []string{subnetName}
_ = ginkgo.BeforeEach(func() {
testFlags := utils.TestFlags{
"latest": true,
"evm": true,
"evm-token": "TOK",
"sovereign": false,
"warp": false,
"skip-update-check": true,
"genesis": utils.SubnetEvmGenesisPoaPath,
}
_, err := utils.TestCommand(cmd.BlockchainCmd, "create", blockchainCmdArgs, nil, testFlags)
gomega.Expect(err).Should(gomega.BeNil())
globalFlags := utils.GlobalFlags{
"local": true,
"skip-update-check": true,
}
_, err = utils.TestCommand(cmd.BlockchainCmd, "deploy", blockchainCmdArgs, globalFlags, nil)
gomega.Expect(err).Should(gomega.BeNil())
})
ginkgo.AfterEach(func() {
commands.CleanNetwork()
// Cleanup test subnet config
commands.DeleteSubnetConfig(subnetName)
})
globalFlags := utils.GlobalFlags{
"skip-update-check": true,
"local": true,
"verify-input": false,
"validator-manager-owner": "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC",
"validator-manager-address": "0x0FEEDC0DE0000000000000000000000000000000",
"proof-of-authority": true,
"key": "ewoq",
}
ginkgo.It("HAPPY PATH: local convert default", func() {
testFlags := utils.TestFlags{}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(output).Should(gomega.ContainSubstring("Subnet is successfully converted to sovereign L1"))
gomega.Expect(err).Should(gomega.BeNil())
// verify that we have a local machine created that is now a bootstrap validator
localClusterUris, err := utils.GetLocalClusterUris()
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(len(localClusterUris)).Should(gomega.Equal(1))
})
ginkgo.It("HAPPY PATH: local convert with luxd path set", func() {
luxdPath := "tests/e2e/assets/mac/luxd"
if runtime.GOOS == "linux" {
luxdPath = "tests/e2e/assets/linux/luxd"
}
testFlags := utils.TestFlags{
"luxd-path": luxdPath,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(output).Should(gomega.ContainSubstring(fmt.Sprintf("Luxd path: %s", luxdPath)))
gomega.Expect(output).Should(gomega.ContainSubstring("Subnet is successfully converted to sovereign L1"))
gomega.Expect(err).Should(gomega.BeNil())
// verify that we have a local machine created that is now a bootstrap validator
localClusterUris, err := utils.GetLocalClusterUris()
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(len(localClusterUris)).Should(gomega.Equal(1))
})
ginkgo.It("HAPPY PATH: convert only", func() {
testFlags := utils.TestFlags{
"convert-only": true,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
checkConvertOnlyOutput(output, false)
gomega.Expect(err).Should(gomega.BeNil())
// verify that we have a local machine created that is now a bootstrap validator
localClusterUris, err := utils.GetLocalClusterUris()
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(len(localClusterUris)).Should(gomega.Equal(1))
})
ginkgo.It("HAPPY PATH: generate node id ends in convert only", func() {
testFlags := utils.TestFlags{
"generate-node-id": true,
"num-bootstrap-validators": 1,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
checkConvertOnlyOutput(output, true)
gomega.Expect(err).Should(gomega.BeNil())
sc, err := utils.GetSideCar(blockchainCmdArgs[0])
gomega.Expect(err).Should(gomega.BeNil())
numValidators := len(sc.Networks["Local Network"].BootstrapValidators)
gomega.Expect(numValidators).Should(gomega.BeEquivalentTo(1))
gomega.Expect(sc.Networks["Local Network"].BootstrapValidators[0].NodeID).ShouldNot(gomega.BeNil())
gomega.Expect(sc.Networks["Local Network"].BootstrapValidators[0].BLSProofOfPossession).ShouldNot(gomega.BeNil())
gomega.Expect(sc.Networks["Local Network"].BootstrapValidators[0].BLSPublicKey).ShouldNot(gomega.BeNil())
})
ginkgo.It("HAPPY PATH: local convert with bootstrap validator balance", func() {
testFlags := utils.TestFlags{
"balance": 0.2,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(output).Should(gomega.ContainSubstring("Subnet is successfully converted to sovereign L1"))
gomega.Expect(err).Should(gomega.BeNil())
sc, err := utils.GetSideCar(blockchainCmdArgs[0])
gomega.Expect(err).Should(gomega.BeNil())
testFlags = utils.TestFlags{
"local": true,
"validation-id": sc.Networks["Local Network"].BootstrapValidators[0].ValidationID,
}
output, err = utils.TestCommand(cmd.ValidatorCmd, "getBalance", nil, nil, testFlags)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(output).To(gomega.ContainSubstring("Validator Balance: 0.20000 LUX"))
})
ginkgo.It("HAPPY PATH: local convert with bootstrap filepath", func() {
testFlags := utils.TestFlags{
"bootstrap-filepath": utils.BootstrapValidatorPath2,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
checkConvertOnlyOutput(output, false)
gomega.Expect(err).Should(gomega.BeNil())
sc, err := utils.GetSideCar(blockchainCmdArgs[0])
gomega.Expect(err).Should(gomega.BeNil())
for i := 0; i < 2; i++ {
testFlags := utils.TestFlags{
"local": true,
"validation-id": sc.Networks["Local Network"].BootstrapValidators[i].ValidationID,
}
output, err = utils.TestCommand(cmd.ValidatorCmd, "getBalance", nil, nil, testFlags)
gomega.Expect(err).Should(gomega.BeNil())
if i == 0 {
sc.Networks["Local Network"].BootstrapValidators[i].NodeID = "NodeID-144PM69m93kSFyfTHMwULTmoGZSWzQ4C1"
sc.Networks["Local Network"].BootstrapValidators[i].Weight = 20
sc.Networks["Local Network"].BootstrapValidators[i].BLSPublicKey = "0x80b7851ce335cee149b7cfffbf6cf0bbca3c9b25026a24056e610976d095906e833a66d5ca5c56c23a3fe50e8785a81f"
sc.Networks["Local Network"].BootstrapValidators[i].BLSProofOfPossession = "0x89e1d6d47ff04ec0c78501a029865140e9ec12baba75a95bfc5710b3fecb8db4b6cecb5ccb1136e19f88db0539deb4420306dd60145024197b41cf89179790f20146fba398bc4d13e08540ea812207f736ca007275e4ebdb840065fdb38573de"
sc.Networks["Local Network"].BootstrapValidators[i].ChangeOwnerAddr = "P-custom1y5ku603lh583xs9v50p8kk0awcqzgeq0mezkqr"
// we set first validator to have 0.2 LUX balance in test_bootstrap_validator2.json
gomega.Expect(output).To(gomega.ContainSubstring("Validator Balance: 0.20000 LUX"))
} else {
sc.Networks["Local Network"].BootstrapValidators[i].NodeID = "NodeID-FtB74cdqNRrrsEpcyMHMvdpsRVodBupi3"
sc.Networks["Local Network"].BootstrapValidators[i].Weight = 30
sc.Networks["Local Network"].BootstrapValidators[i].BLSPublicKey = "0x8061a9d92920bff462c21318e77597ce322169eac4dce20aa842740b684d80a071be78dc56f789d3ef11f19314d871bd"
sc.Networks["Local Network"].BootstrapValidators[i].BLSProofOfPossession = "0x83da8a3f0324ee3f23bd09adcb7d3fcd1023246ca2ead75e9d55ff1397bb1063ebd9a3c67b4042f698ac445486d0102009a206163cb80c3c92a8029c0ce2bc95d8bb6cf4af8ff5882935ae92926ca0b856fe60c62f849ee463c079aa187240ec"
sc.Networks["Local Network"].BootstrapValidators[i].ChangeOwnerAddr = "P-custom1y5ku603lh583xs9v50p8kk0awcqzgeq0mezkqr"
// we set second validator to have 0.3 LUX balance in test_bootstrap_validator2.json
gomega.Expect(output).To(gomega.ContainSubstring("Validator Balance: 0.30000 LUX"))
}
}
})
ginkgo.It("HAPPY PATH: local convert with change owner address", func() {
testFlags := utils.TestFlags{
"change-owner-address": "P-custom1y5ku603lh583xs9v50p8kk0awcqzgeq0mezkqr",
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(output).Should(gomega.ContainSubstring("Subnet is successfully converted to sovereign L1"))
gomega.Expect(err).Should(gomega.BeNil())
})
ginkgo.It("HAPPY PATH: local convert set num bootstrap validators", func() {
testFlags := utils.TestFlags{
"num-bootstrap-validators": 2,
}
_, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.BeNil())
sc, err := utils.GetSideCar(blockchainCmdArgs[0])
gomega.Expect(err).Should(gomega.BeNil())
numValidators := len(sc.Networks["Local Network"].BootstrapValidators)
gomega.Expect(numValidators).Should(gomega.BeEquivalentTo(2))
localClusterUris, err := utils.GetLocalClusterUris()
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(len(localClusterUris)).Should(gomega.Equal(2))
})
ginkgo.It("ERROR PATH: invalid_version", func() {
testFlags := utils.TestFlags{
"luxd-version": "invalid_version",
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("invalid version string"))
})
ginkgo.It("ERROR PATH: invalid_luxd_path", func() {
luxdPath := "invalid_luxd_path"
testFlags := utils.TestFlags{
"luxd-path": luxdPath,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring(fmt.Sprintf("luxd binary %s does not exist", luxdPath)))
})
ginkgo.It("ERROR PATH: zero balance value", func() {
testFlags := utils.TestFlags{
"balance": 0,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("bootstrap validator balance must be greater than 0 LUX"))
})
ginkgo.It("ERROR PATH: negative balance value", func() {
testFlags := utils.TestFlags{
"balance": -1.0,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("bootstrap validator balance must be greater than 0 LUX"))
})
ginkgo.It("ERROR PATH: invalid bootstrap filepath", func() {
fileName := "nonexistent.json"
testFlags := utils.TestFlags{
"bootstrap-filepath": fileName,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("file path \"%s\" doesn't exist", fileName))
})
ginkgo.It("ERROR PATH: invalid change owner address format", func() {
testFlags := utils.TestFlags{
"change-owner-address": ewoqEVMAddress,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("failure parsing change owner address: no separator found in address"))
})
ginkgo.It("ERROR PATH: generate node id is not applicable if convert only is false", func() {
testFlags := utils.TestFlags{
"generate-node-id": true,
"convert-only": false,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("cannot set --convert-only=false if --generate-node-id=true"))
})
ginkgo.It("ERROR PATH: generate node id is not applicable if use local machine is true", func() {
testFlags := utils.TestFlags{
"generate-node-id": true,
"use-local-machine": true,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("cannot use local machine as bootstrap validator if --generate-node-id=true"))
})
ginkgo.It("ERROR PATH: bootstrap filepath is not applicable if convert only is false", func() {
testFlags := utils.TestFlags{
"bootstrap-filepath": utils.BootstrapValidatorPath,
"convert-only": false,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("cannot set --convert-only=false if --bootstrap-filepath is not empty"))
})
ginkgo.It("ERROR PATH: bootstrap filepath is not applicable if use local machine is true", func() {
testFlags := utils.TestFlags{
"bootstrap-filepath": utils.BootstrapValidatorPath,
"use-local-machine": true,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("cannot use local machine as bootstrap validator if --bootstrap-filepath is not empty"))
})
ginkgo.It("ERROR PATH: bootstrap endpoints is not applicable if convert only is false", func() {
testFlags := utils.TestFlags{
"bootstrap-endpoints": "127.0.0.1:9650",
"convert-only": false,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("cannot set --convert-only=false if --bootstrap-endpoints is not empty"))
})
ginkgo.It("ERROR PATH: bootstrap endpoints is not applicable if use local machine is true", func() {
testFlags := utils.TestFlags{
"bootstrap-endpoints": "127.0.0.1:9650",
"use-local-machine": true,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("cannot use local machine as bootstrap validator if --bootstrap-endpoints is not empty"))
})
ginkgo.It("ERROR PATH: bootstrap filepath cannot be set if generate node id is true", func() {
testFlags := utils.TestFlags{
"bootstrap-filepath": utils.BootstrapValidatorPath2,
"generate-node-id": true,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("cannot use --generate-node-id=true and a non-empty --bootstrap-filepath at the same time"))
})
ginkgo.It("ERROR PATH: bootstrap filepath cannot be set if num bootstrap validators is set", func() {
testFlags := utils.TestFlags{
"bootstrap-filepath": utils.BootstrapValidatorPath2,
"num-bootstrap-validators": 2,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("cannot use a non-empty --num-bootstrap-validators and a non-empty --bootstrap-filepath at the same time"))
})
ginkgo.It("ERROR PATH: bootstrap filepath cannot be set if balance is set", func() {
testFlags := utils.TestFlags{
"bootstrap-filepath": utils.BootstrapValidatorPath2,
"balance": 0.2,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("cannot use a non-empty --balance and a non-empty --bootstrap-filepath at the same time"))
})
ginkgo.It("ERROR PATH: bootstrap filepath cannot be set if bootstrap endpoints is set", func() {
testFlags := utils.TestFlags{
"bootstrap-filepath": utils.BootstrapValidatorPath2,
"bootstrap-endpoints": "127.0.0.1:9650",
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("cannot use a non-empty --bootstrap-endpoints and a non-empty --bootstrap-filepath at the same time"))
})
ginkgo.It("ERROR PATH: bootstrap endpoints is not applicable if generate node id is true", func() {
testFlags := utils.TestFlags{
"bootstrap-endpoints": utils.BootstrapValidatorPath2,
"generate-node-id": true,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("cannot use --generate-node-id=true and a non-empty --bootstrap-endpoints at the same time"))
})
ginkgo.It("ERROR PATH: bootstrap endpoints is not applicable if num bootstrap validators is set", func() {
testFlags := utils.TestFlags{
"bootstrap-endpoints": utils.BootstrapValidatorPath2,
"num-bootstrap-validators": 2,
}
output, err := utils.TestCommand(cmd.BlockchainCmd, "convert", blockchainCmdArgs, globalFlags, testFlags)
gomega.Expect(err).Should(gomega.HaveOccurred())
gomega.Expect(output).Should(gomega.ContainSubstring("cannot use a non-empty --num-bootstrap-validators and a non-empty --bootstrap-endpoints at the same time"))
})
})