Skip to content
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

Merged
merged 6 commits into from
Jan 15, 2024
Merged

Type test: share #337

merged 6 commits into from
Jan 15, 2024

Conversation

MatheusFranco99
Copy link
Contributor

@MatheusFranco99 MatheusFranco99 commented Jan 2, 2024

Spec Test

New test type to verify share's functionality of checking quorums.

Tests:

  • Message with partial quorum
  • Message with quorum
  • Message with 3f+1 quorum
  • Message with no partial quorum
  • Message with no partial quorum with duplicate signers
  • Message with partial quorum with duplicate signers
  • Message with no quorum
  • Message with no quorum with duplicate signers
  • Message with quorum with duplicate signers

Solving one element of issue 25.

Comment on lines 10 to 23
func NoQuorum() *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: "no quorum",
Share: *share,
Message: *msg,
ExpectedHasPartialQuorum: true,
ExpectedHasQuorum: false,
ExpectedFullCommittee: false,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is pretty much the same as has_partial_quroum?
If so maybe we might as well delete this test and change the name of has_partial_quorum to account for 2 scenarios?

Having the same test for 2 different scenarios might also be an ok approach, but I think we have enough clutter in our tests anyhow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

Comment on lines +27 to +35
func (test *ShareTest) GetUniqueMessageSignersCount() int {
uniqueSigners := make(map[uint64]bool)

for _, element := range test.Message.Signers {
uniqueSigners[element] = true
}

return len(uniqueSigners)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (test *ShareTest) GetUniqueMessageSignersCount() int {
uniqueSigners := make(map[uint64]bool)
for _, element := range test.Message.Signers {
uniqueSigners[element] = true
}
return len(uniqueSigners)
}
func (test *ShareTest) GetUniqueMessageSignersCount() int {
uniqueSigners := make(map[uint64]struct{})
for _, signer := range test.Message.Signers {
uniqueSigners[signer] = struct{}{}
}
return len(uniqueSigners)
}

not anything crucial, but this is more memory-efficient since it doesn't actually store any data

@@ -96,6 +96,12 @@ func TestJson(t *testing.T) {
typedTest := &beacon.DepositDataSpecTest{}
require.NoError(t, json.Unmarshal(byts, &typedTest))
typedTest.Run(t)
case reflect.TypeOf(&share.ShareTest{}).String():
byts, err := json.Marshal(test)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

@GalRogozinski GalRogozinski merged commit fe5b9b4 into main Jan 15, 2024
2 checks passed
@GalRogozinski GalRogozinski deleted the test-share branch January 15, 2024 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants