|
1 | 1 | package seiconfig |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "os" |
5 | 6 | "path/filepath" |
6 | 7 | "strings" |
7 | 8 | "testing" |
8 | 9 | "time" |
| 10 | + |
| 11 | + "github.com/BurntSushi/toml" |
9 | 12 | ) |
10 | 13 |
|
11 | 14 | const testRPCAddr = "tcp://0.0.0.0:26657" |
@@ -445,6 +448,85 @@ func TestApplyOverrides_Bool(t *testing.T) { |
445 | 448 | } |
446 | 449 | } |
447 | 450 |
|
| 451 | +// TestWriteModeEnableAuto_Tristate covers the three states a reserve node |
| 452 | +// depends on: absent so the binary's default applies, explicitly false to pin |
| 453 | +// the node to its own write mode, and explicitly true. |
| 454 | +func TestWriteModeEnableAuto_Tristate(t *testing.T) { |
| 455 | + encode := func(t *testing.T, cfg *SeiConfig) string { |
| 456 | + t.Helper() |
| 457 | + var buf bytes.Buffer |
| 458 | + if err := toml.NewEncoder(&buf).Encode(cfg.toLegacyApp()); err != nil { |
| 459 | + t.Fatalf("encoding app.toml: %v", err) |
| 460 | + } |
| 461 | + return buf.String() |
| 462 | + } |
| 463 | + |
| 464 | + t.Run("unset omits the key", func(t *testing.T) { |
| 465 | + cfg := Default() |
| 466 | + if cfg.Storage.StateCommit.WriteModeEnableAuto != nil { |
| 467 | + t.Fatal("default should leave WriteModeEnableAuto unset") |
| 468 | + } |
| 469 | + if got := encode(t, cfg); strings.Contains(got, "sc-write-mode-enable-auto") { |
| 470 | + t.Error("unset value must not render the key, so the binary keeps its own default") |
| 471 | + } |
| 472 | + }) |
| 473 | + |
| 474 | + t.Run("override to false renders false", func(t *testing.T) { |
| 475 | + cfg := Default() |
| 476 | + if err := ApplyOverrides(cfg, map[string]string{ |
| 477 | + "storage.state_commit.write_mode_enable_auto": "false", |
| 478 | + }); err != nil { |
| 479 | + t.Fatalf("ApplyOverrides: %v", err) |
| 480 | + } |
| 481 | + got := cfg.Storage.StateCommit.WriteModeEnableAuto |
| 482 | + if got == nil || *got { |
| 483 | + t.Fatalf("WriteModeEnableAuto: got %v, want pointer to false", got) |
| 484 | + } |
| 485 | + if out := encode(t, cfg); !strings.Contains(out, "sc-write-mode-enable-auto = false") { |
| 486 | + t.Error("an explicit false must render; omitempty on a pointer drops only nil") |
| 487 | + } |
| 488 | + }) |
| 489 | + |
| 490 | + t.Run("override to true renders true", func(t *testing.T) { |
| 491 | + cfg := Default() |
| 492 | + if err := ApplyOverrides(cfg, map[string]string{ |
| 493 | + "storage.state_commit.write_mode_enable_auto": "true", |
| 494 | + }); err != nil { |
| 495 | + t.Fatalf("ApplyOverrides: %v", err) |
| 496 | + } |
| 497 | + got := cfg.Storage.StateCommit.WriteModeEnableAuto |
| 498 | + if got == nil || !*got { |
| 499 | + t.Fatalf("WriteModeEnableAuto: got %v, want pointer to true", got) |
| 500 | + } |
| 501 | + if out := encode(t, cfg); !strings.Contains(out, "sc-write-mode-enable-auto = true") { |
| 502 | + t.Error("an explicit true must render") |
| 503 | + } |
| 504 | + }) |
| 505 | +} |
| 506 | + |
| 507 | +// TestWriteModeEnableAuto_RoundTrip checks that reading back a rendered |
| 508 | +// app.toml preserves the pin, so a re-render does not silently unpin the node. |
| 509 | +func TestWriteModeEnableAuto_RoundTrip(t *testing.T) { |
| 510 | + for _, want := range []*bool{nil, boolPtr(false), boolPtr(true)} { |
| 511 | + cfg := Default() |
| 512 | + cfg.Storage.StateCommit.WriteModeEnableAuto = want |
| 513 | + |
| 514 | + back := fromLegacy(cfg.toLegacyTendermint(), cfg.toLegacyApp()) |
| 515 | + got := back.Storage.StateCommit.WriteModeEnableAuto |
| 516 | + |
| 517 | + switch { |
| 518 | + case want == nil && got != nil: |
| 519 | + t.Errorf("unset round-tripped to %v", *got) |
| 520 | + case want != nil && got == nil: |
| 521 | + t.Errorf("%v round-tripped to unset", *want) |
| 522 | + case want != nil && got != nil && *want != *got: |
| 523 | + t.Errorf("round-trip: got %v, want %v", *got, *want) |
| 524 | + } |
| 525 | + } |
| 526 | +} |
| 527 | + |
| 528 | +func boolPtr(b bool) *bool { return &b } |
| 529 | + |
448 | 530 | func TestApplyOverrides_Uint(t *testing.T) { |
449 | 531 | cfg := Default() |
450 | 532 | if err := ApplyOverrides(cfg, map[string]string{ |
|
0 commit comments