-
Notifications
You must be signed in to change notification settings - Fork 112
feat(testnet): add configurable testnet validator powers #708
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 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
69eb7ee
add configurable validator power
almk-dev 8a16d94
Merge branch 'main' into abdul/testnet-validator-power-flag
almk-dev aba0d17
add changelog
almk-dev 486e26d
update flag string
almk-dev 335f2f2
update comments
almk-dev 7bd64a1
remove string parsing from validation function and update tests
almk-dev 3924699
Merge branch 'main' into abdul/testnet-validator-power-flag
vladjdk 23b3695
Merge branch 'main' into abdul/testnet-validator-power-flag
aljo242 81d0608
Merge branch 'main' into abdul/testnet-validator-power-flag
almk-dev d68bd5c
Merge branch 'main' into abdul/testnet-validator-power-flag
aljo242 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
Some comments aren't visible on the classic Files Changed page.
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,100 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestParseValidatorPowers(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| powersStr string | ||
| numValidators int | ||
| want []int64 | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "empty string - use defaults", | ||
| powersStr: "", | ||
| numValidators: 4, | ||
| want: []int64{100, 100, 100, 100}, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "exact number of powers", | ||
| powersStr: "100,200,150,300", | ||
| numValidators: 4, | ||
| want: []int64{100, 200, 150, 300}, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "fewer powers than validators", | ||
| powersStr: "100,200", | ||
| numValidators: 5, | ||
| want: []int64{100, 200, 200, 200, 200}, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "single power for all validators", | ||
| powersStr: "500", | ||
| numValidators: 3, | ||
| want: []int64{500, 500, 500}, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "more powers than validators", | ||
| powersStr: "100,200,300,400", | ||
| numValidators: 2, | ||
| want: []int64{100, 200}, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "invalid power - not a number", | ||
| powersStr: "100,abc,300", | ||
| numValidators: 3, | ||
| want: nil, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "invalid power - negative", | ||
| powersStr: "100,-200,300", | ||
| numValidators: 3, | ||
| want: nil, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "invalid power - zero", | ||
| powersStr: "100,0,300", | ||
| numValidators: 3, | ||
| want: nil, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "with spaces", | ||
| powersStr: "100, 200, 300", | ||
| numValidators: 3, | ||
| want: []int64{100, 200, 300}, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "trailing comma", | ||
| powersStr: "100,200,300,", | ||
| numValidators: 3, | ||
| want: []int64{100, 200, 300}, | ||
| wantErr: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got, err := parseValidatorPowers(tt.powersStr, tt.numValidators) | ||
| if tt.wantErr { | ||
| require.Error(t, err) | ||
| } else { | ||
| require.NoError(t, err) | ||
| require.Equal(t, tt.want, got) | ||
| } | ||
| }) | ||
| } | ||
| } |
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.