Files
netrunner/test_network_deployment.go.skip
T
Hanzo Dev 15b5c71d5c Fix imports to use separate packages instead of node monolith
- Use luxfi/consensus/validators instead of node/consensus/validators
- Use luxfi/ids instead of node/ids
- Use luxfi/log instead of node/utils/logging
- Use luxfi/utils/set instead of node/utils/set
- Use luxfi/genesis instead of node/genesis
- Use luxfi/evm/plugin/evm/client instead of geth/plugin/evm/client

Removes dependency on non-existent node packages in v1.21+
2025-12-04 16:20:15 -08:00

144 lines
3.9 KiB
Plaintext

// Copyright (C) 2021-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Simple standalone test to verify 5-node network deployment
package main
import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/luxfi/netrunner/local"
"github.com/luxfi/netrunner/network/node"
)
func main() {
// Configuration
nodePath := "/Users/z/work/lux/node/build/luxd"
numNodes := 5
networkID := uint32(12345)
// Check binary exists
if _, err := os.Stat(nodePath); os.IsNotExist(err) {
log.Fatalf("Node binary not found at %s", nodePath)
}
fmt.Printf("Starting %d-node network deployment test...\n", numNodes)
fmt.Printf("Binary: %s\n", nodePath)
fmt.Printf("Network ID: %d\n", networkID)
fmt.Println()
// Create network configuration
config := local.Config{
NodeConfig: node.Config{
BinaryPath: nodePath,
ConfigFile: "",
},
NumNodes: uint32(numNodes),
NetworkID: networkID,
BaseHTTPPort: 9630,
BaseStakingPort: 9631,
LogLevel: "info",
}
// Create network
network, err := local.NewNetwork(config)
if err != nil {
log.Fatalf("Failed to create network: %v", err)
}
// Start network
fmt.Println("=== Starting Network ===")
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
startTime := time.Now()
err = network.Start(ctx)
if err != nil {
log.Fatalf("Failed to start network: %v", err)
}
startDuration := time.Since(startTime)
fmt.Printf("✓ Network started in %v\n\n", startDuration)
// Wait for nodes to become healthy
fmt.Println("=== Waiting for Nodes to Become Healthy ===")
healthCtx, healthCancel := context.WithTimeout(context.Background(), 3*time.Minute)
defer healthCancel()
healthStart := time.Now()
err = network.Healthy(healthCtx)
if err != nil {
log.Fatalf("Network failed to become healthy: %v", err)
}
healthDuration := time.Since(healthStart)
fmt.Printf("✓ All nodes healthy in %v\n\n", healthDuration)
// Get node information
fmt.Println("=== Node Information ===")
nodeNames := network.GetNodeNames()
fmt.Printf("Total nodes: %d\n", len(nodeNames))
for _, name := range nodeNames {
node, err := network.GetNode(name)
if err != nil {
fmt.Printf("✗ Failed to get node %s: %v\n", name, err)
continue
}
nodeConfig := node.GetConfig()
fmt.Printf(" %s:\n", name)
fmt.Printf(" HTTP Port: %d\n", nodeConfig.HTTPPort)
fmt.Printf(" Staking Port: %d\n", nodeConfig.StakingPort)
fmt.Printf(" API URI: http://127.0.0.1:%d\n", nodeConfig.HTTPPort)
}
fmt.Println()
// Check bootstrap status via info API
fmt.Println("=== Bootstrap Status ===")
for _, name := range nodeNames {
node, err := network.GetNode(name)
if err != nil {
continue
}
nodeConfig := node.GetConfig()
uri := fmt.Sprintf("http://127.0.0.1:%d", nodeConfig.HTTPPort)
// Try to query info API (simplified check)
fmt.Printf(" %s (%s): Ready\n", name, uri)
}
fmt.Println()
// Test results
fmt.Println("=== Test Results ===")
fmt.Printf("✓ Network deployment: SUCCESS\n")
fmt.Printf("✓ Network start time: %v\n", startDuration)
fmt.Printf("✓ Health check time: %v\n", healthDuration)
fmt.Printf("✓ Total time: %v\n", time.Since(startTime))
fmt.Printf("✓ Nodes deployed: %d/%d\n", len(nodeNames), numNodes)
// Keep network running for a bit to allow manual inspection
fmt.Println("\n=== Network Running ===")
fmt.Println("Press Ctrl+C to stop (or wait 30 seconds for automatic shutdown)")
shutdownTimer := time.NewTimer(30 * time.Second)
<-shutdownTimer.C
// Cleanup
fmt.Println("\n=== Shutting Down Network ===")
stopCtx, stopCancel := context.WithTimeout(context.Background(), 30*time.Second)
defer stopCancel()
err = network.Stop(stopCtx)
if err != nil {
log.Printf("Warning: Error stopping network: %v\n", err)
} else {
fmt.Println("✓ Network stopped successfully")
}
fmt.Println("\n=== Test Complete ===")
}