-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
a7c907e
to
e073828
Compare
e073828
to
15aac03
Compare
addresses review comment #457 (comment)
15aac03
to
23a4a41
Compare
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) |
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.
We should use require.NoError(t, err)
here and elsewhere
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.
addressed in 0c630f0
|
||
func TestCreateSignedMessageSucceeds(t *testing.T) { | ||
var msg *warp.UnsignedMessage // to be signed | ||
chainID, err := ids.ToID(utils.RandomBytes(32)) |
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.
Let's use ids.GenerateTestID
here.
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.
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 { |
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.
Let's use require.NoError
rather than panicking.
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.
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) |
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.
Let's use constants.UnitTestID
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.
addressed in fc24e7a
aggregator, mockNetwork := instantiateAggregator(t) | ||
|
||
subnetID, err := ids.ToID(utils.RandomBytes(32)) | ||
require.Equal(t, nil, err) |
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.
require.Equal(t, nil, err) | |
require.NoError(t, err) |
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.
addressed in 0c630f0
|
||
aggregator, mockNetwork := instantiateAggregator(t) | ||
|
||
subnetID, err := ids.ToID(utils.RandomBytes(32)) |
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.
Let's use ids.GenerateTestID
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.
addressed in 408b68f
addresses review comment #467 (comment)
addresses review comment #467 (comment)
networkID := uint32(0) | ||
msg, err = warp.NewUnsignedMessage( | ||
msg, err := warp.NewUnsignedMessage( |
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.
With this change, we don't need the declaration for msg
on line 237
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.
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 |
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.
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 { |
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.
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
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.
Great point, thanks for calling it out. I removed the public key logging in fd04dc5
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.
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.
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.
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.
addresses review comment #457 (comment)
Why this should be merged
How this works
How this was tested
How is this documented