Files
zeekay 8e45bcd029 refactor: Go-idiomatic package layout
Reorganize consensus packages following Go conventions and best practices:

Protocol Consolidation:
- Move prism/, photon/, wave/ → protocol/ directory
- Consolidate all protocol implementations under single namespace
- Follows standard library pattern (encoding/json, encoding/xml)

Package Naming:
- Rename validators/ → validator/ (singular, lowercase per Go convention)
- Aligns with stdlib patterns (net/http, database/sql)

Import Path Updates:
- Update all 241 Go files with new import paths
- github.com/luxfi/consensus/prism → protocol/prism
- github.com/luxfi/consensus/photon → protocol/photon
- github.com/luxfi/consensus/wave → protocol/wave
- github.com/luxfi/consensus/validators → validator

Benefits:
- Clear separation: core (contracts) vs protocol (algorithms) vs engine (runtime)
- Improved discoverability (all protocols under protocol/)
- Consistent with Go naming conventions
- Zero breaking changes to core APIs
- Easier to add new protocol implementations

Test Results:
- All 67+ tests passing across 21 packages
- 100% test coverage maintained
- No performance regression

Structure:
consensus/
├── core/           # Pure contracts (interfaces, zero deps)
├── protocol/       # Consensus algorithms & mechanics
│   ├── prism/      # Polling/quorum primitives
│   ├── photon/     # Unary consensus
│   ├── wave/       # N-ary consensus (FPC)
│   └── ...         # Other protocol phases
├── engine/         # Runtime glue (runs protocols)
└── validator/      # Validator management (singular)
2025-11-06 04:19:26 -08:00

73 lines
1.8 KiB
Go

// Package chaintest provides test utilities for chain testing
package chaintest
import (
"context"
"errors"
"testing"
"github.com/luxfi/consensus/engine/chain/block"
"github.com/luxfi/ids"
)
// VM is a test VM for chain testing
type VM struct {
T *testing.T
ParseBlockF func(context.Context, []byte) (block.Block, error)
}
// ParseBlock parses a block from bytes
func (vm *VM) ParseBlock(ctx context.Context, bytes []byte) (block.Block, error) {
if vm.ParseBlockF != nil {
return vm.ParseBlockF(ctx, bytes)
}
return &TestBlock{
bytes: bytes,
}, nil
}
// Initialize initializes the VM
func (vm *VM) Initialize(
ctx context.Context,
chainCtx interface{},
db interface{},
genesisBytes []byte,
upgradeBytes []byte,
configBytes []byte,
msgChan interface{},
fxs []interface{},
appSender interface{},
) error {
return nil
}
// BuildBlock builds a new block
func (vm *VM) BuildBlock(ctx context.Context) (block.Block, error) {
return nil, errors.New("BuildBlock not implemented")
}
// GetBlock gets a block by ID
func (vm *VM) GetBlock(ctx context.Context, id ids.ID) (block.Block, error) {
return nil, errors.New("GetBlock not implemented")
}
// GetBlockIDAtHeight gets the block ID at a given height
func (vm *VM) GetBlockIDAtHeight(ctx context.Context, height uint64) (ids.ID, error) {
return ids.Empty, errors.New("GetBlockIDAtHeight not implemented")
}
// LastAccepted returns the last accepted block ID
func (vm *VM) LastAccepted(ctx context.Context) (ids.ID, error) {
return Genesis.ID(), nil
}
// WaitForEvent waits for a blockchain event
func (vm *VM) WaitForEvent(ctx context.Context) (interface{}, error) {
return nil, errors.New("WaitForEvent not implemented")
}
// SetPreference sets the preferred block ID
func (vm *VM) SetPreference(ctx context.Context, id ids.ID) error {
return nil
}