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

Signature Aggregator: Happy path unit test #467

Merged
merged 13 commits into from
Sep 11, 2024
Merged

Conversation

feuGeneA
Copy link
Contributor

addresses review comment #457 (comment)

Why this should be merged

How this works

How this was tested

How is this documented

@feuGeneA feuGeneA force-pushed the sig-agg-unit-test-happy-path branch 3 times, most recently from a7c907e to e073828 Compare August 30, 2024 19:06
Base automatically changed from sig-agg-unit-tests to main August 30, 2024 19:06
@feuGeneA feuGeneA changed the title happy path test Signature Aggregator: Happy path unit test Aug 30, 2024
@feuGeneA feuGeneA force-pushed the sig-agg-unit-test-happy-path branch from e073828 to 15aac03 Compare August 30, 2024 19:07
addresses review comment #457 (comment)
func TestCreateSignedMessageFailsWithNoValidators(t *testing.T) {
aggregator, mockNetwork := instantiateAggregator(t)
msg, err := warp.NewUnsignedMessage(0, ids.Empty, []byte{})
require.Equal(t, err, nil)
require.Equal(t, nil, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use require.NoError(t, err) here and elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed in 0c630f0


func TestCreateSignedMessageSucceeds(t *testing.T) {
var msg *warp.UnsignedMessage // to be signed
chainID, err := ids.ToID(utils.RandomBytes(32))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use ids.GenerateTestID here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed in 408b68f

func TestCreateSignedMessageSucceeds(t *testing.T) {
var msg *warp.UnsignedMessage // to be signed
chainID, err := ids.ToID(utils.RandomBytes(32))
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use require.NoError rather than panicking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this isn't necessary now that we're using GenerateTestID, since it doesn't return an error

if err != nil {
panic(err)
}
networkID := uint32(0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use constants.UnitTestID

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed in fc24e7a

aggregator, mockNetwork := instantiateAggregator(t)

subnetID, err := ids.ToID(utils.RandomBytes(32))
require.Equal(t, nil, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
require.Equal(t, nil, err)
require.NoError(t, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed in 0c630f0


aggregator, mockNetwork := instantiateAggregator(t)

subnetID, err := ids.ToID(utils.RandomBytes(32))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use ids.GenerateTestID

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed in 408b68f

networkID := uint32(0)
msg, err = warp.NewUnsignedMessage(
msg, err := warp.NewUnsignedMessage(
Copy link
Contributor

Choose a reason for hiding this comment

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

With this change, we don't need the declaration for msg on line 237

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes but I like the readability of having the declaration there. The name of the test/function tells you a message is going to be signed, and then the very first line shows you (not just tells you with comments) that we're starting to construct the message to be signed.

@@ -212,12 +212,12 @@ type ConnectedCanonicalValidators struct {
ConnectedWeight uint64
TotalValidatorWeight uint64
ValidatorSet []*warp.Validator
nodeValidatorIndexMap map[ids.NodeID]int
NodeValidatorIndexMap map[ids.NodeID]int
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that I love this struct having all of it's fields exported instead of using getters/setters but every other field is already exported so not a blocker for this PR

@@ -41,7 +42,16 @@ func (c *Cache) Get(msgID ids.ID) (map[PublicKeyBytes]SignatureBytes, bool) {
cachedValue, isCached := c.signatures.Get(msgID)

if isCached {
c.logger.Debug("cache hit", zap.Stringer("msgID", msgID))
var encodedKeys []string
for key := range cachedValue {
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a very performance sensitive applications but I think it's weird that we are doing this work here just to construct the Debug level log message.

In practice this ends up being O(n^2) cost for debug logging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point, thanks for calling it out. I removed the public key logging in fd04dc5

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah if it was useful we could have gotten around by checking log level or putting it in a function call if this logger supports lazy eval.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not saying it's worth while here but it looks like:
if s.logger.Enabled(logging.Debug) {
would let us do more complex logging when debugging.

@feuGeneA feuGeneA merged commit 3f911e9 into main Sep 11, 2024
8 checks passed
@feuGeneA feuGeneA deleted the sig-agg-unit-test-happy-path branch September 11, 2024 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants