Files
zeekayandHanzo Dev 62d5f28c22 A chain address is built in one place
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]>
2026-08-30 15:05:42 -07:00

234 lines
6.6 KiB
Go

// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package packageman
import (
"fmt"
"os"
"os/exec"
"path"
"github.com/luxfi/cli/pkg/chainvalidators"
"github.com/luxfi/cli/pkg/key"
"github.com/luxfi/cli/pkg/route"
"github.com/luxfi/cli/tests/e2e/commands"
"github.com/luxfi/cli/tests/e2e/utils"
"github.com/luxfi/constants"
"github.com/luxfi/ids"
luxlog "github.com/luxfi/log"
"github.com/luxfi/proto/p/txs"
blockchainSDK "github.com/luxfi/sdk/blockchain"
"github.com/luxfi/sdk/evm"
sdkinfo "github.com/luxfi/sdk/info"
"github.com/luxfi/sdk/models"
"github.com/luxfi/geth/common"
ginkgo "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)
const (
CLIBinary = "./bin/lux"
keyName = "treasury"
treasuryEVMAddress = "0x9011E888251AB053B7bD1cdB598Db4f9DEd94714"
treasuryPChainAddress = "P-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p"
ProxyContractAddress = "0xFEEDC0DE0000000000000000000000000000000"
)
var err error
func createSovEVMConfig() error {
// Check config does not already exist
_, err = utils.ChainConfigExists(utils.BlockchainName)
if err != nil {
return err
}
// Create config
cmd := exec.Command( //nolint:gosec // G204: Running our own CLI binary in tests
CLIBinary,
"blockchain",
"create",
utils.BlockchainName,
"--evm",
"--proof-of-authority",
"--validator-manager-owner",
treasuryEVMAddress,
"--proxy-contract-owner",
treasuryEVMAddress,
"--production-defaults",
"--evm-chain-id=99999",
"--evm-token=TOK",
"--"+constants.SkipUpdateFlag,
)
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(cmd.String())
utils.PrintStdErr(err)
}
fmt.Println(string(output))
return err
}
func createSovereignChain() (string, string, error) {
if err := createSovEVMConfig(); err != nil {
return "", "", err
}
// Deploy chain on sov local network with local machine as bootstrap validator
cmd := exec.Command( //nolint:gosec // G204: Running our own CLI binary in tests
CLIBinary,
"blockchain",
"deploy",
utils.BlockchainName,
"--local",
"--num-bootstrap-validators=1",
"--treasury",
"--convert-only",
"--change-owner-address",
treasuryPChainAddress,
"--"+constants.SkipUpdateFlag,
)
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(cmd.String())
utils.PrintStdErr(err)
}
fmt.Println(string(output))
chainID, err := utils.ParsePublicDeployOutput(string(output), utils.ChainIDParseType)
if err != nil {
return "", "", err
}
blockchainID, err := utils.ParsePublicDeployOutput(string(output), utils.BlockchainIDParseType)
if err != nil {
return "", "", err
}
return chainID, blockchainID, err
}
func destroyLocalNode() {
_, err := os.Stat(utils.TestLocalNodeName)
if os.IsNotExist(err) {
return
}
cmd := exec.Command( //nolint:gosec // G204: Running our own CLI binary in tests
CLIBinary,
"node",
"local",
"destroy",
utils.TestLocalNodeName,
"--"+constants.SkipUpdateFlag,
)
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(cmd.String())
fmt.Println(string(output))
utils.PrintStdErr(err)
}
}
func getBootstrapValidator(uri string) ([]*txs.ConvertNetworkToL1Validator, error) {
infoClient := sdkinfo.NewClient(uri)
ctx, cancel := utils.GetAPILargeContext()
defer cancel()
nodeID, proofOfPossession, err := infoClient.GetNodeID(ctx)
if err != nil {
return nil, err
}
publicKey := "0x" + proofOfPossession.PublicKey
pop := "0x" + proofOfPossession.ProofOfPossession
bootstrapValidator := models.ChainValidator{
NodeID: nodeID.String(),
Weight: constants.BootstrapValidatorWeight,
Balance: constants.BootstrapValidatorBalanceNanoLUX,
BLSPublicKey: publicKey,
BLSProofOfPossession: pop,
ChangeOwnerAddr: treasuryPChainAddress,
}
luxdBootstrapValidators, err := chainvalidators.ToL1Validators([]models.ChainValidator{bootstrapValidator})
if err != nil {
return nil, err
}
return luxdBootstrapValidators, nil
}
var _ = ginkgo.Describe("[Validator Manager POA Set Up]", ginkgo.Ordered, func() {
ginkgo.BeforeEach(func() {
// key
_ = utils.DeleteKey(keyName)
output, err := commands.CreateKeyFromPath(keyName, utils.LocalKeyPath)
if err != nil {
fmt.Println(output)
utils.PrintStdErr(err)
}
gomega.Expect(err).Should(gomega.BeNil())
// chain config
_ = utils.DeleteConfigs(utils.BlockchainName)
destroyLocalNode()
})
ginkgo.AfterEach(func() {
destroyLocalNode()
commands.DeleteChainConfig(utils.BlockchainName)
err := utils.DeleteKey(keyName)
gomega.Expect(err).Should(gomega.BeNil())
commands.CleanNetwork()
})
ginkgo.It("Set Up POA Validator Manager", func() {
chainIDStr, blockchainIDStr, err := createSovereignChain()
gomega.Expect(err).Should(gomega.BeNil())
uris, err := utils.GetLocalClusterUris()
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(len(uris)).Should(gomega.Equal(1))
_, err = commands.TrackLocalSovChain(utils.TestLocalNodeName, utils.BlockchainName)
gomega.Expect(err).Should(gomega.BeNil())
keyPath := path.Join(utils.GetBaseDir(), constants.KeyDir, fmt.Sprintf("chain_%s_airdrop", utils.BlockchainName)+constants.KeySuffix)
k, err := key.LoadSoft(models.NewLocalNetwork().ID(), keyPath)
gomega.Expect(err).Should(gomega.BeNil())
rpcURL := route.Chain(uris[0], blockchainIDStr) + "/rpc"
client, err := evm.GetClient(rpcURL)
gomega.Expect(err).Should(gomega.BeNil())
err = client.WaitForEVMBootstrapped(0)
gomega.Expect(err).Should(gomega.BeNil())
network := models.NewNetworkFromCluster(models.NewLocalNetwork(), utils.TestLocalNodeName)
chainID, err := ids.FromString(chainIDStr)
gomega.Expect(err).Should(gomega.BeNil())
blockchainID, err := ids.FromString(blockchainIDStr)
gomega.Expect(err).Should(gomega.BeNil())
luxdBootstrapValidators, err := getBootstrapValidator(uris[0])
gomega.Expect(err).Should(gomega.BeNil())
// Convert validators to interface slice for SDK
var validators []interface{}
for _, v := range luxdBootstrapValidators {
validators = append(validators, v)
}
ownerAddress := common.HexToAddress(treasuryEVMAddress)
netSDK := blockchainSDK.Net{
ChainID: chainID,
BlockchainID: blockchainID,
OwnerAddress: &ownerAddress,
RPC: rpcURL,
BootstrapValidators: validators,
}
_, cancel := utils.GetSignatureAggregatorContext()
defer cancel()
err = netSDK.InitializeProofOfAuthority(
luxlog.NoLog{},
network.SDKNetwork(),
k.PrivKeyHex(),
luxlog.NoLog{},
ProxyContractAddress,
true,
"",
)
gomega.Expect(err).Should(gomega.BeNil())
})
})