Files
zeekayandGitHub 2d67d98b01 env: drop LUX_ prefix from env vars (noise) (#38)
Renames LUX_-prefixed env vars to canonical, non-noisy forms:

- LUX_MNEMONIC      -> MNEMONIC      (deploy script + LLM doc)
- LUX_PRIVATE_KEY   -> PRIVATE_KEY   (deploy script + LLM doc)
- LUX_INSECURE_TLS  -> INSECURE_TLS
- LUX_NODE_ENDPOINT -> NODE_ENDPOINT
- LUX_NETWORK_TYPE  -> NETWORK_TYPE  (backend gRPC server selector)
- LUX_RPC_URL       -> RPC_URL
- LUX_NODE_ROOT     -> NODE_ROOT
- LUX_CHART_PATH    -> CHART_PATH
- LUX_CHAINS_FILE   -> CHAINS_FILE
- LUX_KMS_ROOT_KEY  -> KMS_ROOT_KEY
- LUX_WC_PROJECT_ID -> WC_PROJECT_ID (WalletConnect)
- LUX_BLS_KEY       -> BLS_KEY       (was already supported via getEnv())
- LUX_KEY_INDEX     -> KEY_INDEX     (was already supported via getEnv())

pkg/key/backend_env.go: removed the LUX_-prefix-stripping getEnv()
helper (now reads env vars by exact name) and dropped the broken
"MNEMONIC / MNEMONIC" / "PRIVATE_KEY / PRIVATE_KEY" doc comments
which were a previous incomplete rename.

NOT renamed (defined in upstream luxfi/constants — separate concern):
- LUX_NODE_PATH      (constants.EnvNodePath)
- LUX_NETRUNNER_PATH (constants.EnvNetrunnerPath)
- LUX_EVM_PATH       (constants.EnvEVMPath)
- LUX_PLUGINS_DIR    (constants.EnvPluginsDir)

Doc comments referencing those env vars (cmd/root.go,
cmd/networkcmd/start.go, cmd/nodecmd/link.go) describe the
constants-defined names accurately and are left alone.

NOT renamed (script-local variables, not env vars):
- LUX_ZONE in scripts/update-cloudflare-dns.sh (Cloudflare DNS zone ID)
- LUX_BIN_DIR in scripts/install.sh (~/.lux/bin path constant)

BREAKING: external callers/operators must update env var names. Per
CLAUDE.md no-backwards-compatibility rule, the old forms are removed.
2026-05-15 16:35:26 -07:00

184 lines
4.1 KiB
Go

// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package nodecmd
import (
"testing"
"time"
)
func TestResolveNamespace(t *testing.T) {
tests := []struct {
name string
mainnet bool
testnet bool
devnet bool
namespace string
want string
wantErr bool
}{
{
name: "mainnet flag",
mainnet: true,
want: "lux-mainnet",
},
{
name: "testnet flag",
testnet: true,
want: "lux-testnet",
},
{
name: "devnet flag",
devnet: true,
want: "lux-devnet",
},
{
name: "explicit namespace overrides",
mainnet: true,
namespace: "custom-ns",
want: "custom-ns",
},
{
name: "no flags = error",
wantErr: true,
},
{
name: "multiple network flags = error",
mainnet: true,
testnet: true,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Set package-level vars
flagMainnet = tt.mainnet
flagTestnet = tt.testnet
flagDevnet = tt.devnet
flagNamespace = tt.namespace
// Reset after test
defer func() {
flagMainnet = false
flagTestnet = false
flagDevnet = false
flagNamespace = ""
}()
got, err := resolveNamespace()
if (err != nil) != tt.wantErr {
t.Errorf("resolveNamespace() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("resolveNamespace() = %q, want %q", got, tt.want)
}
})
}
}
func TestResolveNetwork(t *testing.T) {
tests := []struct {
name string
mainnet bool
testnet bool
devnet bool
namespace string
want string
wantErr bool
}{
{name: "mainnet flag", mainnet: true, want: "mainnet"},
{name: "testnet flag", testnet: true, want: "testnet"},
{name: "devnet flag", devnet: true, want: "devnet"},
{name: "namespace lux-mainnet", namespace: "lux-mainnet", want: "mainnet"},
{name: "namespace lux-testnet", namespace: "lux-testnet", want: "testnet"},
{name: "namespace lux-devnet", namespace: "lux-devnet", want: "devnet"},
{name: "custom namespace = error", namespace: "custom-ns", wantErr: true},
{name: "no flags = error", wantErr: true},
{name: "multiple flags = error", mainnet: true, testnet: true, wantErr: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
flagMainnet = tt.mainnet
flagTestnet = tt.testnet
flagDevnet = tt.devnet
flagNamespace = tt.namespace
defer func() {
flagMainnet = false
flagTestnet = false
flagDevnet = false
flagNamespace = ""
}()
got, err := resolveNetwork()
if (err != nil) != tt.wantErr {
t.Errorf("resolveNetwork() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("resolveNetwork() = %q, want %q", got, tt.want)
}
})
}
}
func TestDefaultChartPath(t *testing.T) {
// Without env var, should return ~/work/lux/devops/charts/lux
t.Setenv("CHART_PATH", "")
p := defaultChartPath()
if p == "" {
t.Error("defaultChartPath() returned empty string")
}
// With env var, should return the env value
t.Setenv("CHART_PATH", "/custom/chart")
p = defaultChartPath()
if p != "/custom/chart" {
t.Errorf("defaultChartPath() = %q, want /custom/chart", p)
}
}
func TestNetworkFlag(t *testing.T) {
tests := []struct {
namespace string
want string
}{
{"lux-mainnet", "mainnet"},
{"lux-testnet", "testnet"},
{"lux-devnet", "devnet"},
{"custom", "namespace custom"},
}
for _, tt := range tests {
got := networkFlag(tt.namespace)
if got != tt.want {
t.Errorf("networkFlag(%q) = %q, want %q", tt.namespace, got, tt.want)
}
}
}
func TestFormatDuration(t *testing.T) {
tests := []struct {
name string
secs int
want string
}{
{"seconds", 45, "45s"},
{"minutes", 300, "5m"},
{"hours", 7200, "2h"},
{"days", 172800, "2d"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := formatDuration(time.Duration(tt.secs) * time.Second)
if got != tt.want {
t.Errorf("formatDuration(%ds) = %q, want %q", tt.secs, got, tt.want)
}
})
}
}