mirror of
https://github.com/luxfi/consensus.git
synced 2026-09-24 00:26:58 +00:00
- Add epoch.go for epoch-based consensus timing - Add quantum_block.go for quantum-resistant block structures - Add grouped_threshold.go for grouped threshold voting - Add quasar.go as main protocol entry point - Add dual_threshold_test.go for dual threshold testing - Update core.go with improved consensus logic - Remove deprecated hybrid.go - Fix engine.Start bool parameter in tests
119 lines
2.2 KiB
Go
119 lines
2.2 KiB
Go
package chain
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/luxfi/ids"
|
|
)
|
|
|
|
func TestNew(t *testing.T) {
|
|
engine := New()
|
|
if engine == nil {
|
|
t.Fatal("New() returned nil")
|
|
}
|
|
|
|
if engine.IsBootstrapped() {
|
|
t.Error("Engine should not be bootstrapped initially")
|
|
}
|
|
}
|
|
|
|
func TestStart(t *testing.T) {
|
|
engine := New()
|
|
ctx := context.Background()
|
|
|
|
err := engine.Start(ctx, true)
|
|
if err != nil {
|
|
t.Fatalf("Start failed: %v", err)
|
|
}
|
|
|
|
if !engine.IsBootstrapped() {
|
|
t.Error("Engine should be bootstrapped after Start")
|
|
}
|
|
}
|
|
|
|
func TestStop(t *testing.T) {
|
|
engine := New()
|
|
ctx := context.Background()
|
|
|
|
_ = engine.Start(ctx, true)
|
|
|
|
err := engine.Stop(ctx)
|
|
if err != nil {
|
|
t.Fatalf("Stop failed: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestHealthCheck(t *testing.T) {
|
|
engine := New()
|
|
ctx := context.Background()
|
|
|
|
health, err := engine.HealthCheck(ctx)
|
|
if err != nil {
|
|
t.Fatalf("HealthCheck failed: %v", err)
|
|
}
|
|
|
|
if health == nil {
|
|
t.Error("HealthCheck returned nil")
|
|
}
|
|
|
|
// Check it returns a map with consensus stats
|
|
if m, ok := health.(map[string]interface{}); ok {
|
|
// Real consensus returns detailed stats
|
|
if _, exists := m["total_blocks"]; !exists {
|
|
t.Error("HealthCheck should include total_blocks stat")
|
|
}
|
|
if _, exists := m["bootstrapped"]; !exists {
|
|
t.Error("HealthCheck should include bootstrapped stat")
|
|
}
|
|
} else {
|
|
t.Error("HealthCheck should return a map[string]interface{}")
|
|
}
|
|
}
|
|
|
|
func TestGetBlock(t *testing.T) {
|
|
engine := New()
|
|
ctx := context.Background()
|
|
|
|
// GetBlock should return nil (no-op for now)
|
|
// Using empty IDs for test
|
|
nodeID := ids.EmptyNodeID
|
|
blockID := ids.Empty
|
|
|
|
err := engine.GetBlock(ctx, nodeID, 1, blockID)
|
|
if err != nil {
|
|
t.Errorf("GetBlock should not error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestChainWorkflow(t *testing.T) {
|
|
engine := New()
|
|
ctx := context.Background()
|
|
|
|
// Start engine
|
|
err := engine.Start(ctx, true)
|
|
if err != nil {
|
|
t.Fatalf("Start failed: %v", err)
|
|
}
|
|
|
|
// Check bootstrapped
|
|
if !engine.IsBootstrapped() {
|
|
t.Error("Should be bootstrapped")
|
|
}
|
|
|
|
// Health check
|
|
health, err := engine.HealthCheck(ctx)
|
|
if err != nil {
|
|
t.Fatalf("HealthCheck failed: %v", err)
|
|
}
|
|
if health == nil {
|
|
t.Error("Health should not be nil")
|
|
}
|
|
|
|
// Stop engine
|
|
err = engine.Stop(ctx)
|
|
if err != nil {
|
|
t.Fatalf("Stop failed: %v", err)
|
|
}
|
|
}
|