Files
node/x/blockdb/helpers_test.go
zeekay 7cf87b230b node-unified is the node
The module already called itself github.com/luxfi/node while containing no node
in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and
the Go column of the matrix measured a VM plugin. A repo that fetches the thing
it claims to be has not replaced it, so the Go sources move in — 1515 files,
the daemon and everything under it — and the build reaches outside this module
for nothing.

Rust and C++ sit beside it unchanged and are still measured against it by the
differential. That is the point of one repo: the reference implementation and
the two ports are the same checkout, so parity is a thing you can run rather
than a thing you assert.

Verified: builds, and the closure carries no lux-private — checked at build time
rather than believed. The daemon starts twelve chains on a local network
(P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
2026-09-07 16:15:25 -07:00

73 lines
1.9 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package blockdb
import (
"crypto/rand"
"fmt"
"math/big"
"testing"
"github.com/stretchr/testify/require"
"github.com/luxfi/log"
)
func newTestDatabase(t *testing.T, opts DatabaseConfig) (*Database, func()) {
t.Helper()
dir := t.TempDir()
config := opts
if config.IndexDir == "" {
config = config.WithIndexDir(dir)
}
if config.DataDir == "" {
config = config.WithDataDir(dir)
}
db, err := New(config, log.NoLog{})
require.NoError(t, err, "failed to create database")
cleanup := func() {
db.Close()
}
return db, cleanup
}
// randomBlock generates a random block of size 1KB-50KB.
func randomBlock(t *testing.T) []byte {
size, err := rand.Int(rand.Reader, big.NewInt(50*1024-1024+1))
require.NoError(t, err, "failed to generate random size")
blockSize := int(size.Int64()) + 1024 // 1KB to 50KB
b := make([]byte, blockSize)
_, err = rand.Read(b)
require.NoError(t, err, "failed to fill random block")
return b
}
// fixedSizeBlock generates a block of the specified fixed size with height information.
func fixedSizeBlock(t *testing.T, size int, height uint64) []byte {
require.Positive(t, size, "block size must be positive")
b := make([]byte, size)
// Fill the beginning with height information for better testability
heightStr := fmt.Sprintf("block-height-%d-", height)
if len(heightStr) <= size {
copy(b, heightStr)
}
return b
}
func checkDatabaseState(t *testing.T, db *Database, maxHeight uint64, maxContiguousHeight uint64) {
heights := db.blockHeights.Load()
if heights != nil {
require.Equal(t, maxHeight, heights.maxBlockHeight, "maxBlockHeight mismatch")
} else {
require.Equal(t, uint64(unsetHeight), maxHeight, "maxBlockHeight mismatch")
}
}
// Helper function to create a pointer to uint64
func uint64Ptr(v uint64) *uint64 {
return &v
}