-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spec - Share length validation (#478)
* Add share length validation in runner construction * Align to error handling in runners constructions * Add validation to committee runner * Add runner construction tests * Refactor runner construction in testingutil to deal with creation errors * Generate JSON tests * Fix lint issue * Fix comments
- Loading branch information
1 parent
642d9d2
commit 02beeb9
Showing
15 changed files
with
314 additions
and
88 deletions.
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
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,28 @@ | ||
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) | ||
|
||
expectedErrors := map[types.RunnerRole]string{ | ||
types.RoleCommittee: "", // No errors since it can handle multiple 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: "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,27 @@ | ||
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{} | ||
|
||
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.