-
Notifications
You must be signed in to change notification settings - Fork 24
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
Type test: share #337
Type test: share #337
Changes from 5 commits
958a013
77ddba9
bb321da
c5cbcd3
f39a4ae
0cf502c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
package share | ||
|
||
import ( | ||
"github.com/bloxapp/ssv-spec/types" | ||
"github.com/bloxapp/ssv-spec/types/testingutils" | ||
"github.com/herumi/bls-eth-go-binary/bls" | ||
) | ||
|
||
// HasQuorum tests msg with unique 2f+1 signers | ||
func HasQuorum() *SpecTest { | ||
panic("implement") | ||
func HasQuorum() *ShareTest { | ||
ks := testingutils.Testing4SharesSet() | ||
share := testingutils.TestingShare(ks) | ||
|
||
msg := testingutils.TestingCommitMultiSignerMessage([]*bls.SecretKey{ks.Shares[1], ks.Shares[2], ks.Shares[3]}, []types.OperatorID{1, 2, 3}) | ||
|
||
return &ShareTest{ | ||
Name: "has quorum", | ||
Share: *share, | ||
Message: *msg, | ||
ExpectedHasPartialQuorum: true, | ||
ExpectedHasQuorum: true, | ||
ExpectedFullCommittee: false, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
package share | ||
|
||
import ( | ||
"github.com/bloxapp/ssv-spec/types" | ||
"github.com/bloxapp/ssv-spec/types/testingutils" | ||
"github.com/herumi/bls-eth-go-binary/bls" | ||
) | ||
|
||
// HasQuorum3f1 tests msg with unique 3f+1 signers | ||
func HasQuorum3f1() *SpecTest { | ||
panic("implement") | ||
func HasQuorum3f1() *ShareTest { | ||
ks := testingutils.Testing4SharesSet() | ||
share := testingutils.TestingShare(ks) | ||
|
||
msg := testingutils.TestingCommitMultiSignerMessage([]*bls.SecretKey{ks.Shares[1], ks.Shares[2], ks.Shares[3], ks.Shares[4]}, []types.OperatorID{1, 2, 3, 4}) | ||
|
||
return &ShareTest{ | ||
Name: "has quorum 3f1", | ||
Share: *share, | ||
Message: *msg, | ||
ExpectedHasPartialQuorum: true, | ||
ExpectedHasQuorum: true, | ||
ExpectedFullCommittee: true, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,22 @@ | ||
package share | ||
|
||
import ( | ||
"github.com/bloxapp/ssv-spec/types/testingutils" | ||
) | ||
|
||
// NoPartialQuorum tests msg with < unique f+1 signers | ||
func NoPartialQuorum() *SpecTest { | ||
panic("implement") | ||
func NoPartialQuorum() *ShareTest { | ||
ks := testingutils.Testing4SharesSet() | ||
share := testingutils.TestingShare(ks) | ||
|
||
msg := testingutils.TestingCommitMessage(ks.Shares[1], 1) | ||
|
||
return &ShareTest{ | ||
Name: "no partial quorum", | ||
Share: *share, | ||
Message: *msg, | ||
ExpectedHasPartialQuorum: false, | ||
ExpectedHasQuorum: false, | ||
ExpectedFullCommittee: false, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,34 @@ | ||
package share | ||
|
||
import ( | ||
"github.com/bloxapp/ssv-spec/qbft" | ||
"github.com/bloxapp/ssv-spec/types" | ||
"github.com/bloxapp/ssv-spec/types/testingutils" | ||
) | ||
|
||
// NoPartialQuorumDuplicate tests msg with < unique f+1 signers (but f+1 signers including duplicates) | ||
func NoPartialQuorumDuplicate() *SpecTest { | ||
panic("implement") | ||
func NoPartialQuorumDuplicate() *ShareTest { | ||
ks := testingutils.Testing4SharesSet() | ||
share := testingutils.TestingShare(ks) | ||
|
||
msg := &qbft.SignedMessage{ | ||
Message: qbft.Message{ | ||
MsgType: qbft.CommitMsgType, | ||
Height: qbft.FirstHeight, | ||
Round: qbft.FirstRound, | ||
Identifier: testingutils.TestingIdentifier, | ||
Root: testingutils.TestingQBFTRootData, | ||
}, | ||
Signers: []types.OperatorID{1, 1}, | ||
} | ||
|
||
return &ShareTest{ | ||
Name: "no partial quorum duplicate", | ||
Share: *share, | ||
Message: *msg, | ||
ExpectedHasPartialQuorum: false, | ||
ExpectedHasQuorum: false, | ||
ExpectedFullCommittee: false, | ||
ExpectedError: "non unique signer", | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,34 @@ | ||
package share | ||
|
||
import ( | ||
"github.com/bloxapp/ssv-spec/qbft" | ||
"github.com/bloxapp/ssv-spec/types" | ||
"github.com/bloxapp/ssv-spec/types/testingutils" | ||
) | ||
|
||
// NoQuorumDuplicate tests msg with < unique 2f+1 signers (but 2f+1 signers including duplicates) | ||
func NoQuorumDuplicate() *SpecTest { | ||
panic("implement") | ||
func NoQuorumDuplicate() *ShareTest { | ||
ks := testingutils.Testing4SharesSet() | ||
share := testingutils.TestingShare(ks) | ||
|
||
msg := &qbft.SignedMessage{ | ||
Message: qbft.Message{ | ||
MsgType: qbft.CommitMsgType, | ||
Height: qbft.FirstHeight, | ||
Round: qbft.FirstRound, | ||
Identifier: testingutils.TestingIdentifier, | ||
Root: testingutils.TestingQBFTRootData, | ||
}, | ||
Signers: []types.OperatorID{1, 1, 2}, | ||
} | ||
|
||
return &ShareTest{ | ||
Name: "no quorum duplicate", | ||
Share: *share, | ||
Message: *msg, | ||
ExpectedHasPartialQuorum: true, | ||
ExpectedHasQuorum: false, | ||
ExpectedFullCommittee: false, | ||
ExpectedError: "non unique signer", | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package share | ||
|
||
import ( | ||
"github.com/bloxapp/ssv-spec/types" | ||
"github.com/bloxapp/ssv-spec/types/testingutils" | ||
"github.com/herumi/bls-eth-go-binary/bls" | ||
) | ||
|
||
// HasPartialQuorumButNoQuorum tests msg with unique f+1 signers | ||
func HasPartialQuorumButNoQuorum() *ShareTest { | ||
ks := testingutils.Testing4SharesSet() | ||
share := testingutils.TestingShare(ks) | ||
|
||
msg := testingutils.TestingCommitMultiSignerMessage([]*bls.SecretKey{ks.Shares[1], ks.Shares[2]}, []types.OperatorID{1, 2}) | ||
|
||
return &ShareTest{ | ||
Name: "has partial quorum but no quorum", | ||
Share: *share, | ||
Message: *msg, | ||
ExpectedHasPartialQuorum: true, | ||
ExpectedHasQuorum: false, | ||
ExpectedFullCommittee: false, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,34 @@ | ||
package share | ||
|
||
import ( | ||
"github.com/bloxapp/ssv-spec/qbft" | ||
"github.com/bloxapp/ssv-spec/types" | ||
"github.com/bloxapp/ssv-spec/types/testingutils" | ||
) | ||
|
||
// PartialQuorumWithDuplicate tests msg with unique f+1 signers (but also including duplicates) | ||
func PartialQuorumWithDuplicate() *SpecTest { | ||
panic("implement") | ||
func PartialQuorumWithDuplicate() *ShareTest { | ||
ks := testingutils.Testing4SharesSet() | ||
share := testingutils.TestingShare(ks) | ||
|
||
msg := &qbft.SignedMessage{ | ||
Message: qbft.Message{ | ||
MsgType: qbft.CommitMsgType, | ||
Height: qbft.FirstHeight, | ||
Round: qbft.FirstRound, | ||
Identifier: testingutils.TestingIdentifier, | ||
Root: testingutils.TestingQBFTRootData, | ||
}, | ||
Signers: []types.OperatorID{1, 1, 2}, | ||
} | ||
|
||
return &ShareTest{ | ||
Name: "partial quorum with duplicate", | ||
Share: *share, | ||
Message: *msg, | ||
ExpectedHasPartialQuorum: true, | ||
ExpectedHasQuorum: false, | ||
ExpectedFullCommittee: false, | ||
ExpectedError: "non unique signer", | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,34 @@ | ||
package share | ||
|
||
import ( | ||
"github.com/bloxapp/ssv-spec/qbft" | ||
"github.com/bloxapp/ssv-spec/types" | ||
"github.com/bloxapp/ssv-spec/types/testingutils" | ||
) | ||
|
||
// QuorumWithDuplicate tests msg with unique 2f+1 signers (but also including duplicates) | ||
func QuorumWithDuplicate() *SpecTest { | ||
panic("implement") | ||
func QuorumWithDuplicate() *ShareTest { | ||
ks := testingutils.Testing4SharesSet() | ||
share := testingutils.TestingShare(ks) | ||
|
||
msg := &qbft.SignedMessage{ | ||
Message: qbft.Message{ | ||
MsgType: qbft.CommitMsgType, | ||
Height: qbft.FirstHeight, | ||
Round: qbft.FirstRound, | ||
Identifier: testingutils.TestingIdentifier, | ||
Root: testingutils.TestingQBFTRootData, | ||
}, | ||
Signers: []types.OperatorID{1, 1, 2, 3}, | ||
} | ||
|
||
return &ShareTest{ | ||
Name: "quorum with duplicate", | ||
Share: *share, | ||
Message: *msg, | ||
ExpectedHasPartialQuorum: true, | ||
ExpectedHasQuorum: true, | ||
ExpectedFullCommittee: false, | ||
ExpectedError: "non unique signer", | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,17 +2,53 @@ package share | |||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||||||||||
"testing" | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
"github.com/bloxapp/ssv-spec/types" | ||||||||||||||||||||||||||||||||||||||
"github.com/stretchr/testify/require" | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
"github.com/bloxapp/ssv-spec/qbft" | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
type SpecTest struct { | ||||||||||||||||||||||||||||||||||||||
Name string | ||||||||||||||||||||||||||||||||||||||
Data []byte | ||||||||||||||||||||||||||||||||||||||
type ShareTest struct { | ||||||||||||||||||||||||||||||||||||||
Name string | ||||||||||||||||||||||||||||||||||||||
Share types.Share | ||||||||||||||||||||||||||||||||||||||
Message qbft.SignedMessage | ||||||||||||||||||||||||||||||||||||||
ExpectedHasPartialQuorum bool | ||||||||||||||||||||||||||||||||||||||
ExpectedHasQuorum bool | ||||||||||||||||||||||||||||||||||||||
ExpectedFullCommittee bool | ||||||||||||||||||||||||||||||||||||||
ExpectedError string | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
func (test *SpecTest) TestName() string { | ||||||||||||||||||||||||||||||||||||||
return test.Name | ||||||||||||||||||||||||||||||||||||||
func (test *ShareTest) TestName() string { | ||||||||||||||||||||||||||||||||||||||
return "share " + test.Name | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
func (test *SpecTest) Run(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||
panic("implement") | ||||||||||||||||||||||||||||||||||||||
// Returns the number of unique signers in the message signers list | ||||||||||||||||||||||||||||||||||||||
func (test *ShareTest) GetUniqueMessageSignersCount() int { | ||||||||||||||||||||||||||||||||||||||
uniqueSigners := make(map[uint64]bool) | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
for _, element := range test.Message.Signers { | ||||||||||||||||||||||||||||||||||||||
uniqueSigners[element] = true | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
return len(uniqueSigners) | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+27
to
+35
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.
Suggested change
not anything crucial, but this is more memory-efficient since it doesn't actually store any data |
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
func (test *ShareTest) Run(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// Validate message | ||||||||||||||||||||||||||||||||||||||
err := test.Message.Validate() | ||||||||||||||||||||||||||||||||||||||
if len(test.ExpectedError) != 0 { | ||||||||||||||||||||||||||||||||||||||
require.EqualError(t, err, test.ExpectedError) | ||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||
require.NoError(t, err) | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// Get unique signers | ||||||||||||||||||||||||||||||||||||||
numSigners := test.GetUniqueMessageSignersCount() | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// Test expected thresholds results | ||||||||||||||||||||||||||||||||||||||
require.Equal(t, test.ExpectedHasPartialQuorum, test.Share.HasPartialQuorum(numSigners)) | ||||||||||||||||||||||||||||||||||||||
require.Equal(t, test.ExpectedHasQuorum, test.Share.HasQuorum(numSigners)) | ||||||||||||||||||||||||||||||||||||||
require.Equal(t, test.ExpectedFullCommittee, (len(test.Share.Committee) == numSigners)) | ||||||||||||||||||||||||||||||||||||||
} |
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.
typo?