mirror of
https://github.com/luxfi/bft.git
synced 2026-10-30 17:01:54 +00:00
Reapplies the fork's whole delta on top of the merge, as one reviewable diff rather than 43 conflict resolutions. Nothing here changes consensus behaviour. - module github.com/luxfi/bft, Go 1.26.4; root package simplex -> bft, which would otherwise collide with the simplex/ subpackage under this module name. - go.uber.org/zap -> github.com/luxfi/log, so common.Logger takes ...log.Field. zap.Error maps to log.Err: log.Error is luxfi/log's package-level logging function, not a field constructor, and the compiler is the only thing that catches that. Needs luxfi/log v1.6.1 for the Stringers constructor. - avalanchego/ -> host/. The package holds NodeID, VMBlock, Bitmask and size limits — the host node's types, vendored to avoid importing a whole node — so it is named for what it holds. Renaming it luxd/ would have swapped one brand for another and said just as little. - testutil/logger.go reimplemented without zapcore. Upstream layers a keyword-filtering Core, a debug-swallowing Encoder and a Tee because that is zap's extension model; luxfi/log has no such seam, so every policy is applied in one emit. That also fixes two defects the layering caused: SilenceExceptKeywords rebuilt the logger and discarded an installed Intercept hook, and the two sinks read different env vars (LOG_LEVEL vs log_level) so they disagreed about suppressing debug. Hooks run outside the lock, so a hook that logs fails the test instead of deadlocking it. Fatal panics rather than exiting, because exiting takes the suite down with no attribution. - simplex/monitor_test.go keeps a local logger: testutil imports simplex, so an internal test cannot import testutil back without closing a cycle. - README keeps the name Simplex throughout — it is the protocol's own name and the subject of reference [1]. Only the deployment target changed. The HyperSDK sentence still says Avalanche because that sentence is true. - Drops the fork's Makefile: it duplicated unit-tests.sh and fuzz.sh, and ran the suite with -timeout 30s when simplex alone needs over 100s. Co-authored-by: Hanzo Dev <[email protected]>
103 lines
2.9 KiB
Go
103 lines
2.9 KiB
Go
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package random_network
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/luxfi/bft/testutil"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestFileLogging(t *testing.T) {
|
|
// Create temp directory for test logs
|
|
tempDir := t.TempDir()
|
|
|
|
// Create config with file logging enabled
|
|
config := DefaultFuzzConfig()
|
|
config.LogDirectory = tempDir
|
|
|
|
// Create network logger
|
|
networkLogger := CreateNetworkLogger(t, config)
|
|
networkLogger.Info("Test network log message")
|
|
|
|
// Create node logger
|
|
nodeID := testutil.GenerateNodeID(t)
|
|
nodeLogger := CreateNodeLogger(t, config, nodeID)
|
|
nodeLogger.Info("Test node log message")
|
|
|
|
// Verify main.log was created and contains the message
|
|
mainLogPath := filepath.Join(tempDir, "main.log")
|
|
require.FileExists(t, mainLogPath)
|
|
|
|
mainLogContent, err := os.ReadFile(mainLogPath)
|
|
require.NoError(t, err)
|
|
require.Contains(t, string(mainLogContent), "Test network log message")
|
|
|
|
// Verify node log was created with hex filename
|
|
nodeLogPattern := filepath.Join(tempDir, "*.log")
|
|
matches, err := filepath.Glob(nodeLogPattern)
|
|
require.NoError(t, err)
|
|
require.GreaterOrEqual(t, len(matches), 2) // Should have main.log and at least one node log
|
|
|
|
// Find the node log file (not main.log)
|
|
var nodeLogPath string
|
|
for _, match := range matches {
|
|
if filepath.Base(match) != "main.log" {
|
|
nodeLogPath = match
|
|
break
|
|
}
|
|
}
|
|
require.NotEmpty(t, nodeLogPath)
|
|
|
|
nodeLogContent, err := os.ReadFile(nodeLogPath)
|
|
require.NoError(t, err)
|
|
require.Contains(t, string(nodeLogContent), "Test node log message")
|
|
}
|
|
|
|
func TestLogDirectoryClearing(t *testing.T) {
|
|
// Create temp directory for test logs
|
|
tempDir := t.TempDir()
|
|
|
|
// Create an old log file
|
|
oldLogPath := filepath.Join(tempDir, "old.log")
|
|
err := os.WriteFile(oldLogPath, []byte("old log content"), 0644)
|
|
require.NoError(t, err)
|
|
require.FileExists(t, oldLogPath)
|
|
|
|
// Create config with file logging enabled
|
|
config := DefaultFuzzConfig()
|
|
config.LogDirectory = tempDir
|
|
|
|
// Create network logger - this should clear the directory
|
|
networkLogger := CreateNetworkLogger(t, config)
|
|
networkLogger.Info("New log message")
|
|
|
|
// Verify old log was removed
|
|
require.NoFileExists(t, oldLogPath)
|
|
|
|
// Verify new main.log was created
|
|
mainLogPath := filepath.Join(tempDir, "main.log")
|
|
require.FileExists(t, mainLogPath)
|
|
}
|
|
|
|
func TestConsoleOnlyLogging(t *testing.T) {
|
|
// Create config with file logging disabled (empty directory)
|
|
config := DefaultFuzzConfig()
|
|
config.LogDirectory = ""
|
|
|
|
// Create network logger - should not panic
|
|
networkLogger := CreateNetworkLogger(t, config)
|
|
networkLogger.Info("Console only network log")
|
|
|
|
// Create node logger - should not panic
|
|
nodeID := testutil.GenerateNodeID(t)
|
|
nodeLogger := CreateNodeLogger(t, config, nodeID)
|
|
nodeLogger.Info("Console only node log")
|
|
|
|
// No files should be created (test passes if no panic)
|
|
}
|