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]>
90 lines
2.3 KiB
Go
90 lines
2.3 KiB
Go
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package wal_test
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/luxfi/bft/common"
|
|
"github.com/luxfi/bft/testutil"
|
|
"github.com/luxfi/bft/wal"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type mockTruncateableWAL struct {
|
|
t *testing.T
|
|
*testutil.TestWAL
|
|
}
|
|
|
|
func (m *mockTruncateableWAL) Truncate(uint64) error {
|
|
m.TestWAL = testutil.NewTestWAL(m.t)
|
|
return nil
|
|
}
|
|
|
|
func TestLastRecord(t *testing.T) {
|
|
dir, err := os.MkdirTemp(os.TempDir(), t.Name())
|
|
require.NoError(t, err)
|
|
|
|
lastRecordFilePath := filepath.Join(dir, "last-record")
|
|
|
|
testWAL, err := wal.NewLastRecordStoringWAL(lastRecordFilePath,
|
|
&mockTruncateableWAL{
|
|
t: t,
|
|
TestWAL: testutil.NewTestWAL(t),
|
|
},
|
|
common.NotarizationRecordType,
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
entry1 := []byte{0, byte(common.NotarizationRecordType), 1, 2, 3, 4, 5}
|
|
entry2 := []byte{0, byte(common.EmptyNotarizationRecordType), 6, 7, 8, 9, 10}
|
|
entry3 := []byte{0, byte(common.NotarizationRecordType), 11, 12, 13, 14, 15}
|
|
|
|
require.NoError(t, testWAL.Append(entry1))
|
|
require.NoError(t, testWAL.Append(entry2))
|
|
|
|
lastRecord := testWAL.LastRecord()
|
|
require.Equal(t, entry1, lastRecord)
|
|
|
|
require.NoError(t, testWAL.Append(entry3))
|
|
|
|
lastRecord = testWAL.LastRecord()
|
|
require.Equal(t, entry3, lastRecord)
|
|
|
|
entries, err := testWAL.ReadAll()
|
|
require.NoError(t, err)
|
|
require.Equal(t, [][]byte{entry1, entry2, entry3}, entries)
|
|
|
|
require.NoError(t, testWAL.Truncate(0))
|
|
|
|
// Re-create the WAL, it should contain entry3 when probed for its last record.
|
|
|
|
testWAL, err = wal.NewLastRecordStoringWAL(lastRecordFilePath,
|
|
&mockTruncateableWAL{
|
|
t: t,
|
|
TestWAL: testutil.NewTestWAL(t),
|
|
},
|
|
common.NotarizationRecordType,
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
entries, err = testWAL.ReadAll()
|
|
require.NoError(t, err)
|
|
require.Empty(t, entries)
|
|
require.Equal(t, entry3, testWAL.LastRecord())
|
|
|
|
// Next, write a notarization record and make sure that:
|
|
// - Its last record is no longer entry3.
|
|
// - The last record file path is removed.
|
|
|
|
entry4 := []byte{0, byte(common.NotarizationRecordType), 16, 17, 18, 19, 20}
|
|
require.NoError(t, testWAL.Append(entry4))
|
|
require.Equal(t, entry4, testWAL.LastRecord())
|
|
|
|
_, err = os.Stat(lastRecordFilePath)
|
|
require.True(t, os.IsNotExist(err))
|
|
}
|