-
Notifications
You must be signed in to change notification settings - Fork 886
[ConfigManager] Register Sections 1/4 #3974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1da0d72
config: the first four sections enter the registry
bdchatham f7dc6bb
config: say why a field excluded from configuration declares no key
bdchatham 12fe6c0
config: name the untagged field, and say each thing once
bdchatham 517f240
config: the wasm query limit is one statement, and it is the one a no…
bdchatham 905df20
refactor(config): name the conditions a field tag has to pass
bdchatham 4e382a0
Merge branch 'main' into plt-775-sections-1
bdchatham 20b7691
Merge branch 'main' into plt-775-sections-1
masih d0e2143
fix(config): the generated gas limit is one statement, not two
bdchatham c419c21
Merge remote-tracking branch 'origin/plt-775-sections-1' into plt-775…
bdchatham 103600a
fix(config): leave the generated protobuf files as they were
bdchatham 50948c0
Merge branch 'main' into plt-775-sections-1
bdchatham dd0e683
docs(config): state the gas limit's two facts once each
bdchatham 9fbc3ef
Merge remote-tracking branch 'origin/plt-775-sections-1' into plt-775…
bdchatham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package admin | ||
|
|
||
| import ( | ||
| "github.com/sei-protocol/sei-chain/config/registry" | ||
| ) | ||
|
|
||
| // SectionName is this section's name in the configuration key space. | ||
| const SectionName = "admin_server" | ||
|
|
||
| // Registration puts this section in the configuration registry. | ||
| // | ||
| // The keys derive from the mapstructure tags, and the reader resolves the same strings through the | ||
| // constants beside it, so a rename moves one occurrence and the test holds the two together. | ||
| func init() { | ||
| registry.RegisterSection(SectionName, &Config{}, defaults) | ||
| } | ||
|
|
||
| // defaults is what the seid init command writes for a node of this kind. | ||
| func defaults(registry.Mode) any { return DefaultConfig } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package admin | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "sort" | ||
| "testing" | ||
|
|
||
| "github.com/sei-protocol/sei-chain/config/registry" | ||
| ) | ||
|
|
||
| // TestTheDeclaredKeysAreTheKeysThisReaderResolves holds the declaration against the reader. | ||
| // | ||
| // The tags derive the keys and the constants below are what the reader passes to Get, so this compares | ||
| // two statements that are edited for different reasons rather than one written out twice. | ||
| func TestTheDeclaredKeysAreTheKeysThisReaderResolves(t *testing.T) { | ||
| for _, defect := range registry.Defects() { | ||
| if defect.Section == SectionName { | ||
| t.Fatalf("%s was refused: %v", SectionName, defect.Err) | ||
| } | ||
| } | ||
| section, ok := registry.Lookup(SectionName) | ||
| if !ok { | ||
| t.Fatalf("%s is not registered, so nothing resolves its keys", SectionName) | ||
| } | ||
|
|
||
| want := []string{flagAdminAddress, flagAdminEnabled} | ||
| sort.Strings(want) | ||
| if got := section.Keys; !reflect.DeepEqual(got, want) { | ||
| t.Errorf("declared keys are %v, want %v", got, want) | ||
| } | ||
| } | ||
|
|
||
| // TestTheDefaultsAreWhatTheNodeAlreadyRuns keeps the section from restating the values by hand. | ||
| func TestTheDefaultsAreWhatTheNodeAlreadyRuns(t *testing.T) { | ||
| for _, mode := range registry.Modes() { | ||
| got, ok := defaults(mode).(Config) | ||
| if !ok { | ||
| t.Fatalf("mode %q: defaults returned %T, want Config", mode, defaults(mode)) | ||
| } | ||
| if got != DefaultConfig { | ||
| t.Errorf("mode %q resolves to %+v, want the package default %+v", mode, got, DefaultConfig) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/sei-protocol/sei-chain/config/registry" | ||
| ) | ||
|
|
||
| // TestEverySectionThisBinaryDeclaresIsUsable is the check no single section can make. | ||
| // | ||
| // A section registers during its own package's initialisation, and a registration the registry cannot use | ||
| // is recorded rather than panicked, so a section that failed to register is absent rather than loud. Two | ||
| // of the refusals depend on what else has registered: two sections declaring one key, and two keys that | ||
| // collapse onto one environment variable. Neither is visible from inside either section, and the section | ||
| // that loses is dropped whole, with every key it declared. | ||
| // | ||
| // This package links every section a node's configuration reaches, so asking here is asking about the set | ||
| // a node actually gets. Nothing is enumerated, so a section added later is covered without this file | ||
| // changing. | ||
| func TestEverySectionThisBinaryDeclaresIsUsable(t *testing.T) { | ||
| for _, defect := range registry.Defects() { | ||
| t.Errorf("%s was refused, so none of its keys is declared: %v", defect.Section, defect.Err) | ||
| } | ||
| if len(registry.Sections()) == 0 { | ||
| t.Fatal("no section registered, so the checks above hold for an empty set. This package links " + | ||
| "the packages that register, and one of those imports has gone") | ||
| } | ||
| } | ||
|
|
||
| // TestEveryDeclaredKeyResolvesForEveryMode covers the half of a registration a section's own test cannot. | ||
| // | ||
| // Registering validates the struct a section declares against. Whether its defaults can state one value | ||
| // for every key it declared is checked when something resolves them, and until now nothing did outside the | ||
| // registry's own tests. A default that arrives short is refused rather than filled, so the failure is an | ||
| // error here instead of a key resolving to a zero nobody chose. | ||
| func TestEveryDeclaredKeyResolvesForEveryMode(t *testing.T) { | ||
| for _, mode := range registry.Modes() { | ||
| resolved, err := registry.Resolve(mode, registry.Sources{}) | ||
| if err != nil { | ||
| t.Errorf("mode %q does not resolve: %v", mode, err) | ||
| continue | ||
| } | ||
| for _, section := range registry.Sections() { | ||
| for _, key := range section.Keys { | ||
| if _, ok := resolved.Values[key]; !ok { | ||
| t.Errorf("mode %q: %s declares %s and it did not resolve", mode, section.Name, key) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.