-
Notifications
You must be signed in to change notification settings - Fork 22
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
Share length validation #478
Merged
MatheusFranco99
merged 9 commits into
ssvlabs:dev
from
MFrancoLink:share-length-validation
Aug 20, 2024
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ccfbcf0
Add share length validation in runner construction
MatheusFranco99 1336385
Align to error handling in runners constructions
MatheusFranco99 8df877e
Add validation to committee runner
MatheusFranco99 ab8d769
Add runner construction tests
MatheusFranco99 44e3d75
Refactor runner construction in testingutil to deal with creation errors
MatheusFranco99 f09a1d2
Generate JSON tests
MatheusFranco99 c2e465d
Fix lint issue
MatheusFranco99 e5f383d
Fix comments
MatheusFranco99 d5739e8
Merge branch 'dev' into share-length-validation
MatheusFranco99 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 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 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 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 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 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
Binary file not shown.
This file contains 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 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,29 @@ | ||
package runnerconstruction | ||
|
||
import ( | ||
"github.com/ssvlabs/ssv-spec/ssv/spectest/tests" | ||
"github.com/ssvlabs/ssv-spec/types" | ||
"github.com/ssvlabs/ssv-spec/types/testingutils" | ||
) | ||
|
||
func ManyShares() tests.SpecTest { | ||
|
||
ks := testingutils.KeySetMapForValidators(10) | ||
shares := testingutils.ShareMapFromKeySetMap(ks) | ||
|
||
// No errors since one share must be valid for all runners | ||
expectedErrors := map[types.RunnerRole]string{ | ||
types.RoleCommittee: "", | ||
types.RoleProposer: "must have one share", | ||
types.RoleAggregator: "must have one share", | ||
types.RoleSyncCommitteeContribution: "must have one share", | ||
types.RoleValidatorRegistration: "must have one share", | ||
types.RoleVoluntaryExit: "must have one share", | ||
} | ||
|
||
return &RunnerConstructionSpecTest{ | ||
Name: "many shares", | ||
Shares: shares, | ||
RoleError: expectedErrors, | ||
} | ||
} |
This file contains 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,28 @@ | ||
package runnerconstruction | ||
|
||
import ( | ||
"github.com/attestantio/go-eth2-client/spec/phase0" | ||
"github.com/ssvlabs/ssv-spec/ssv/spectest/tests" | ||
"github.com/ssvlabs/ssv-spec/types" | ||
) | ||
|
||
func NoShares() tests.SpecTest { | ||
|
||
shares := map[phase0.ValidatorIndex]*types.Share{} | ||
|
||
// No errors since one share must be valid for all runners | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updating, thanks! |
||
expectedErrors := map[types.RunnerRole]string{ | ||
types.RoleCommittee: "no shares", | ||
types.RoleProposer: "must have one share", | ||
types.RoleAggregator: "must have one share", | ||
types.RoleSyncCommitteeContribution: "must have one share", | ||
types.RoleValidatorRegistration: "must have one share", | ||
types.RoleVoluntaryExit: "must have one share", | ||
} | ||
|
||
return &RunnerConstructionSpecTest{ | ||
Name: "no shares", | ||
Shares: shares, | ||
RoleError: expectedErrors, | ||
} | ||
} |
This file contains 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,31 @@ | ||
package runnerconstruction | ||
|
||
import ( | ||
"github.com/attestantio/go-eth2-client/spec/phase0" | ||
"github.com/ssvlabs/ssv-spec/ssv/spectest/tests" | ||
"github.com/ssvlabs/ssv-spec/types" | ||
"github.com/ssvlabs/ssv-spec/types/testingutils" | ||
) | ||
|
||
func OneShare() tests.SpecTest { | ||
ks := testingutils.Testing4SharesSet() | ||
shares := testingutils.ShareMapFromKeySetMap(map[phase0.ValidatorIndex]*testingutils.TestKeySet{ | ||
testingutils.TestingValidatorIndex: ks, | ||
}) | ||
|
||
// No errors since one share must be valid for all runners | ||
expectedErrors := map[types.RunnerRole]string{ | ||
types.RoleCommittee: "", | ||
types.RoleProposer: "", | ||
types.RoleAggregator: "", | ||
types.RoleSyncCommitteeContribution: "", | ||
types.RoleValidatorRegistration: "", | ||
types.RoleVoluntaryExit: "", | ||
} | ||
|
||
return &RunnerConstructionSpecTest{ | ||
Name: "one share", | ||
Shares: shares, | ||
RoleError: expectedErrors, | ||
} | ||
} |
This file contains 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 runnerconstruction | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/attestantio/go-eth2-client/spec/phase0" | ||
"github.com/ssvlabs/ssv-spec/types" | ||
"github.com/ssvlabs/ssv-spec/types/testingutils" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type RunnerConstructionSpecTest struct { | ||
Name string | ||
Shares map[phase0.ValidatorIndex]*types.Share | ||
RoleError map[types.RunnerRole]string | ||
} | ||
|
||
func (test *RunnerConstructionSpecTest) TestName() string { | ||
return "RunnerConstruction " + test.Name | ||
} | ||
|
||
func (test *RunnerConstructionSpecTest) Run(t *testing.T) { | ||
|
||
if len(test.RoleError) == 0 { | ||
panic("no roles") | ||
} | ||
|
||
for role, expectedError := range test.RoleError { | ||
// Construct runner and get construction error | ||
_, err := testingutils.ConstructBaseRunnerWithShareMap(role, test.Shares) | ||
|
||
// Check error | ||
if len(expectedError) > 0 { | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), expectedError) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
} | ||
} | ||
|
||
func (test *RunnerConstructionSpecTest) GetPostState() (interface{}, error) { | ||
return nil, nil | ||
} |
This file contains 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 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 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 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment right for this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed not. Updating. Thanks for the catch!