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

Test - Validator #340

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Test - Validator #340

wants to merge 15 commits into from

Conversation

MatheusFranco99
Copy link
Contributor

@MatheusFranco99 MatheusFranco99 commented Jan 3, 2024

SSV Tests

Added tests for the Validator structure.

Tests:

  • Process message with no data.
  • Invalid message type.
  • Invalid message ID.
  • Invalid duty.
  • Invalid data for consensus message.
  • Invalid data for partial signature message.
  • Valid consensus message.
  • Valid partial signature message.

Solving one element of issue 25.

@MatheusFranco99 MatheusFranco99 self-assigned this Jan 3, 2024
@MatheusFranco99 MatheusFranco99 marked this pull request as ready for review January 3, 2024 09:09
Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

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

hmm...
I see Alon did add this as an issue but on another instance he told me that we don't need this in spec... I also didn't plan doing such tests for the spec rethink... putting this on hold for now

"github.com/bloxapp/ssv-spec/types/testingutils"
)

func ValidConsensus() tests.SpecTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

add comment

@GalRogozinski GalRogozinski self-requested a review January 10, 2024 19:35
}

func (test *ValidatorTest) GetPostState() (interface{}, error) {
return nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

as part of the post-mortem about the deneb bug, we concluded that we should generate jsons for all tests..
so might as well implement this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding. Thanks!

Comment on lines 106 to 122
for _, msg := range test.OutputMessages {
found := false
for index2, msg2 := range broadcastedMsgs {
if usedIndexes[index2] {
continue
}
if bytes.Equal(msg.GetData(), msg2.GetData()) {
if msg.GetType() == msg2.GetType() && msg.GetID() == msg2.GetID() {
found = true
usedIndexes[index2] = true
break
}
}
}
if !found {
panic(fmt.Sprintf("Broadcasted message not found in output messages: %v", msg))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This checks that OutputMessages are a subset of broadcastedMsgs but not the other way around?
meaning that could be a BroadcastedMsg that is missing in OutputMessage?

I think maybe more tests are like this? I just never really inspected the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before it I do:

require.Len(t, broadcastedMsgs, len(test.OutputMessages))

So I think they are tested to be equal. What do you think?

Comment on lines 88 to 98
require.Len(t, broadcastedRoots, len(test.BeaconBroadcastedRoots))
for _, r1 := range test.BeaconBroadcastedRoots {
found := false
for _, r2 := range broadcastedRoots {
if r1 == hex.EncodeToString(r2[:]) {
found = true
break
}
}
require.Truef(t, found, "broadcasted beacon root not found")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same issue as below I guess

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before it I also check the length. But indeed I should add an "already used" map as in the other check. Adding it.

Duties []*types.Duty
Messages []*types.SSVMessage
OutputMessages []*types.SSVMessage
BeaconBroadcastedRoots []string
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed you don't really use this field for the tests...
Not much harm that it is here I suppose

your choice whether to remove it or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which field?

Copy link
Contributor

Choose a reason for hiding this comment

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

BeaconBroadcastedRoots

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@GalRogozinski GalRogozinski Feb 19, 2024

Choose a reason for hiding this comment

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

it is just that in the tests themselves I noticed it was always empty
but arguably that's also a check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see. Will take a look. Thx!

@MatheusFranco99
Copy link
Contributor Author

@GalRogozinski
This PR added tests for the validator structure, which we almost didn't have. I think it may be useful to have such tests. But the structure changed a lot since then. To merge it, I would need to do some work here

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.

2 participants