|
| 1 | +package planner |
| 2 | + |
| 3 | +import ( |
| 4 | + "slices" |
| 5 | + "testing" |
| 6 | + |
| 7 | + seiconfig "github.com/sei-protocol/sei-config" |
| 8 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 9 | + |
| 10 | + seiv1alpha1 "github.com/sei-protocol/sei-k8s-controller/api/v1alpha1" |
| 11 | +) |
| 12 | + |
| 13 | +func TestArchivePlanner_BlockSyncProgression(t *testing.T) { |
| 14 | + node := &seiv1alpha1.SeiNode{ |
| 15 | + ObjectMeta: metav1.ObjectMeta{Name: "archive-0", Namespace: "pacific-1"}, |
| 16 | + Spec: seiv1alpha1.SeiNodeSpec{ |
| 17 | + ChainID: "pacific-1", |
| 18 | + Image: "seid:v6.4.1", |
| 19 | + Archive: &seiv1alpha1.ArchiveSpec{}, |
| 20 | + }, |
| 21 | + } |
| 22 | + |
| 23 | + p := &archiveNodePlanner{} |
| 24 | + plan, err := p.BuildPlan(node) |
| 25 | + if err != nil { |
| 26 | + t.Fatalf("BuildPlan: %v", err) |
| 27 | + } |
| 28 | + |
| 29 | + types := make([]string, 0, len(plan.Tasks)) |
| 30 | + for _, task := range plan.Tasks { |
| 31 | + types = append(types, task.Type) |
| 32 | + } |
| 33 | + |
| 34 | + // Archive nodes use the genesis (block sync) progression: no snapshot-restore, no state-sync |
| 35 | + if slices.Contains(types, TaskSnapshotRestore) { |
| 36 | + t.Error("archive plan should not contain snapshot-restore") |
| 37 | + } |
| 38 | + if slices.Contains(types, TaskConfigureStateSync) { |
| 39 | + t.Error("archive plan should not contain configure-state-sync") |
| 40 | + } |
| 41 | + |
| 42 | + // Must contain the base genesis progression |
| 43 | + for _, expected := range []string{TaskConfigureGenesis, TaskConfigApply, TaskConfigValidate, TaskMarkReady} { |
| 44 | + if !slices.Contains(types, expected) { |
| 45 | + t.Errorf("archive plan missing expected task %s, got %v", expected, types) |
| 46 | + } |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func TestArchivePlanner_WithPeers(t *testing.T) { |
| 51 | + node := &seiv1alpha1.SeiNode{ |
| 52 | + ObjectMeta: metav1.ObjectMeta{Name: "archive-0", Namespace: "pacific-1"}, |
| 53 | + Spec: seiv1alpha1.SeiNodeSpec{ |
| 54 | + ChainID: "pacific-1", |
| 55 | + Image: "seid:v6.4.1", |
| 56 | + Archive: &seiv1alpha1.ArchiveSpec{}, |
| 57 | + Peers: []seiv1alpha1.PeerSource{ |
| 58 | + {Static: &seiv1alpha1.StaticPeerSource{Addresses: []string{"peer1@host:26656"}}}, |
| 59 | + }, |
| 60 | + }, |
| 61 | + } |
| 62 | + |
| 63 | + p := &archiveNodePlanner{} |
| 64 | + plan, err := p.BuildPlan(node) |
| 65 | + if err != nil { |
| 66 | + t.Fatalf("BuildPlan: %v", err) |
| 67 | + } |
| 68 | + |
| 69 | + types := make([]string, 0, len(plan.Tasks)) |
| 70 | + for _, task := range plan.Tasks { |
| 71 | + types = append(types, task.Type) |
| 72 | + } |
| 73 | + |
| 74 | + if !slices.Contains(types, TaskDiscoverPeers) { |
| 75 | + t.Errorf("archive plan with peers should contain discover-peers, got %v", types) |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +func TestArchivePlanner_SnapshotGenerationOverrides(t *testing.T) { |
| 80 | + node := &seiv1alpha1.SeiNode{ |
| 81 | + ObjectMeta: metav1.ObjectMeta{Name: "archive-0", Namespace: "pacific-1"}, |
| 82 | + Spec: seiv1alpha1.SeiNodeSpec{ |
| 83 | + ChainID: "pacific-1", |
| 84 | + Image: "seid:v6.4.1", |
| 85 | + Archive: &seiv1alpha1.ArchiveSpec{ |
| 86 | + SnapshotGeneration: &seiv1alpha1.SnapshotGenerationConfig{ |
| 87 | + KeepRecent: 5, |
| 88 | + }, |
| 89 | + }, |
| 90 | + }, |
| 91 | + } |
| 92 | + |
| 93 | + p := &archiveNodePlanner{} |
| 94 | + overrides := p.controllerOverrides(node) |
| 95 | + |
| 96 | + if overrides == nil { |
| 97 | + t.Fatal("expected overrides for snapshotGeneration, got nil") |
| 98 | + } |
| 99 | + if got := overrides[seiconfig.KeySnapshotKeepRecent]; got != "5" { |
| 100 | + t.Errorf("snapshot-keep-recent = %q, want %q", got, "5") |
| 101 | + } |
| 102 | + if _, ok := overrides[seiconfig.KeySnapshotInterval]; !ok { |
| 103 | + t.Error("expected snapshot-interval override to be set") |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +func TestArchivePlanner_NoSnapshotGenerationOverrides(t *testing.T) { |
| 108 | + node := &seiv1alpha1.SeiNode{ |
| 109 | + ObjectMeta: metav1.ObjectMeta{Name: "archive-0", Namespace: "pacific-1"}, |
| 110 | + Spec: seiv1alpha1.SeiNodeSpec{ |
| 111 | + ChainID: "pacific-1", |
| 112 | + Image: "seid:v6.4.1", |
| 113 | + Archive: &seiv1alpha1.ArchiveSpec{}, |
| 114 | + }, |
| 115 | + } |
| 116 | + |
| 117 | + p := &archiveNodePlanner{} |
| 118 | + overrides := p.controllerOverrides(node) |
| 119 | + |
| 120 | + if overrides != nil { |
| 121 | + t.Errorf("expected nil overrides without snapshotGeneration, got %v", overrides) |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +func TestArchivePlanner_Mode(t *testing.T) { |
| 126 | + p := &archiveNodePlanner{} |
| 127 | + if got := p.Mode(); got != string(seiconfig.ModeArchive) { |
| 128 | + t.Errorf("Mode() = %q, want %q", got, seiconfig.ModeArchive) |
| 129 | + } |
| 130 | +} |
0 commit comments