mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
Final lux sweep. Five small touches: cmd/networkcmd/start_local.go "subnet creation" → "chain creation" (comment) cmd/explorecmd/explore.go "or subnet name" → "or chain name" (flag help) pkg/plugins/luxdConfig_test.go test fixture: testSubNet → testChain, subNetId000 → chainId000 pkg/mpc/deploy.go AWSSubnet → AWSNet (Go field + json tag) The AWS field rename is Go-side only. AWS itself still calls the resource a subnet on the wire; our config field carries the canonical name without taking a dependency on AWS API verbiage. Build clean.
154 lines
4.2 KiB
Go
154 lines
4.2 KiB
Go
// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package plugins
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/luxfi/cli/internal/testutils"
|
|
"github.com/luxfi/cli/pkg/ux"
|
|
"github.com/luxfi/constants"
|
|
"github.com/luxfi/sdk/models"
|
|
|
|
luxlog "github.com/luxfi/log"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
const (
|
|
chainName1 = "TEST_chain"
|
|
chainName2 = "TEST_copied_chain"
|
|
|
|
chainID = "testChain"
|
|
networkID = uint32(67443)
|
|
)
|
|
|
|
// testing backward compatibility
|
|
func TestEditConfigFileWithOldPattern(t *testing.T) {
|
|
ux.NewUserLog(luxlog.NewNoOpLogger(), io.Discard)
|
|
|
|
require := require.New(t)
|
|
|
|
ap := testutils.SetupTestInTempDir(t)
|
|
|
|
genesisBytes := []byte("genesis")
|
|
err := ap.WriteGenesisFile(chainName1, genesisBytes)
|
|
require.NoError(err)
|
|
|
|
configFile := constants.NodeFileName
|
|
|
|
// Create ConfigFile
|
|
tmpDir := os.TempDir()
|
|
configPath := filepath.Join(tmpDir, configFile)
|
|
defer func() { _ = os.Remove(configPath) }()
|
|
|
|
// testing backward compatibility
|
|
configBytes := []byte("{\"whitelisted-chains\": \"chainId000\"}")
|
|
err = os.MkdirAll(filepath.Dir(configPath), constants.DefaultPerms755)
|
|
require.NoError(err)
|
|
err = os.WriteFile(configPath, configBytes, 0o600)
|
|
require.NoError(err)
|
|
|
|
err = EditConfigFile(ap, chainID, models.NetworkFromNetworkID(networkID), configPath, true, "")
|
|
require.NoError(err)
|
|
|
|
fileBytes, err := os.ReadFile(configPath) //nolint:gosec // G304: Test utility
|
|
require.NoError(err)
|
|
|
|
var luxConfig map[string]interface{}
|
|
err = json.Unmarshal(fileBytes, &luxConfig)
|
|
require.NoError(err)
|
|
|
|
require.Equal("chainId000,testChain", luxConfig["track-chains"])
|
|
|
|
// ensure that the old setting has been deleted
|
|
require.Equal(nil, luxConfig["whitelisted-chains"])
|
|
}
|
|
|
|
// testing backward compatibility
|
|
func TestEditConfigFileWithNewPattern(t *testing.T) {
|
|
ux.NewUserLog(luxlog.NewNoOpLogger(), io.Discard)
|
|
|
|
require := require.New(t)
|
|
|
|
ap := testutils.SetupTestInTempDir(t)
|
|
|
|
genesisBytes := []byte("genesis")
|
|
err := ap.WriteGenesisFile(chainName1, genesisBytes)
|
|
require.NoError(err)
|
|
|
|
configFile := constants.NodeFileName
|
|
|
|
// Create ConfigFile
|
|
tmpDir := os.TempDir()
|
|
configPath := filepath.Join(tmpDir, configFile)
|
|
defer func() { _ = os.Remove(configPath) }()
|
|
|
|
// testing backward compatibility
|
|
configBytes := []byte("{\"track-chains\": \"chainId000\"}")
|
|
err = os.MkdirAll(filepath.Dir(configPath), constants.DefaultPerms755)
|
|
require.NoError(err)
|
|
err = os.WriteFile(configPath, configBytes, 0o600)
|
|
require.NoError(err)
|
|
|
|
err = EditConfigFile(ap, chainID, models.NetworkFromNetworkID(networkID), configPath, true, "")
|
|
require.NoError(err)
|
|
|
|
fileBytes, err := os.ReadFile(configPath) //nolint:gosec // G304: Test utility
|
|
require.NoError(err)
|
|
|
|
var luxConfig map[string]interface{}
|
|
err = json.Unmarshal(fileBytes, &luxConfig)
|
|
require.NoError(err)
|
|
|
|
require.Equal("chainId000,testChain", luxConfig["track-chains"])
|
|
|
|
// ensure that the old setting wont be applied at all
|
|
require.Equal(nil, luxConfig["whitelisted-chains"])
|
|
}
|
|
|
|
func TestEditConfigFileWithNoSettings(t *testing.T) {
|
|
ux.NewUserLog(luxlog.NewNoOpLogger(), io.Discard)
|
|
|
|
require := require.New(t)
|
|
|
|
ap := testutils.SetupTestInTempDir(t)
|
|
|
|
genesisBytes := []byte("genesis")
|
|
err := ap.WriteGenesisFile(chainName1, genesisBytes)
|
|
require.NoError(err)
|
|
|
|
configFile := constants.NodeFileName
|
|
|
|
// Create ConfigFile
|
|
tmpDir := os.TempDir()
|
|
configPath := filepath.Join(tmpDir, configFile)
|
|
defer func() { _ = os.Remove(configPath) }()
|
|
|
|
// testing when no setting for tracked chains exists
|
|
configBytes := []byte("{\"networkId\": \"5\"}")
|
|
err = os.MkdirAll(filepath.Dir(configPath), constants.DefaultPerms755)
|
|
require.NoError(err)
|
|
err = os.WriteFile(configPath, configBytes, 0o600)
|
|
require.NoError(err)
|
|
|
|
err = EditConfigFile(ap, chainID, models.NetworkFromNetworkID(networkID), configPath, true, "")
|
|
require.NoError(err)
|
|
|
|
fileBytes, err := os.ReadFile(configPath) //nolint:gosec // G304: Test utility
|
|
require.NoError(err)
|
|
|
|
var luxConfig map[string]interface{}
|
|
err = json.Unmarshal(fileBytes, &luxConfig)
|
|
require.NoError(err)
|
|
|
|
require.Equal("testChain", luxConfig["track-chains"])
|
|
|
|
// ensure that the old setting wont be applied at all
|
|
require.Equal(nil, luxConfig["whitelisted-chains"])
|
|
}
|