-
Notifications
You must be signed in to change notification settings - Fork 9
Added Utils unit tests - envelope and crypto #103
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR adds comprehensive unit tests for two utility modules - envelope wrapper and crypto - while adding nil checks for improved error handling. The changes enhance test coverage for cryptographic key serialization/parsing functions and envelope wrapping/unwrapping operations.
- Added nil input validation to crypto functions with corresponding error messages
- Created comprehensive test suites covering both valid and invalid input scenarios
- Refactored envelope wrapper to separate payload wrapping from full envelope wrapping
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| utils/signature/sigtest/crypto_test.go | New comprehensive test suite for crypto functions with edge cases |
| utils/signature/sigtest/crypto.go | Added nil check for signing key serialization |
| utils/serialization/envelope_wrapper_test.go | New test suite for envelope operations with error scenarios |
| utils/serialization/envelope_wrapper.go | Added nil header validation and refactored envelope wrapping |
| } | ||
|
|
||
| // WrapEnvelope wraps a payload with its header and returns an envelope. | ||
| func WrapEnvelope(data []byte, header *common.Header) []byte { |
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.
minor:
| func WrapEnvelope(data []byte, header *common.Header) []byte { | |
| func WrapEnvelope(serializedPayload []byte, header *common.Header) []byte { |
| header := &common.Header{ | ||
| ChannelHeader: []byte("not-a-channel-header"), | ||
| } | ||
| payload := &common.Payload{ | ||
| Header: header, | ||
| Data: []byte("some data"), | ||
| } |
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.
| header := &common.Header{ | |
| ChannelHeader: []byte("not-a-channel-header"), | |
| } | |
| payload := &common.Payload{ | |
| Header: header, | |
| Data: []byte("some data"), | |
| } | |
| payload := &common.Payload{ | |
| Header: &common.Header{ | |
| ChannelHeader: []byte("not-a-channel-header"), | |
| }, | |
| Data: []byte("some data"), | |
| } |
| }, | ||
|
|
||
| // { | ||
| // // TODO: find an invalid example? |
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.
minor: Remove
| defer func() { | ||
| if r := recover(); r != nil { | ||
| t.Errorf("SerializeSigningKey() panics: %v", r) | ||
| } | ||
| }() |
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.
major: remove
| } | ||
| } | ||
|
|
||
| func TestSerializeSigningKey(t *testing.T) { |
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.
major: missing t.Parallel()
| if key == nil { | ||
| return nil, errors.New("key is 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.
major: Also add this check to SerializeVerificationKey()
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestSerializeVerificationKey(t *testing.T) { |
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 suggest merging both tests (verification and serialization) and covering all test cases (including errors).
Signed-off-by: Effi-S <effi.szt@gmail.com>
Signed-off-by: Effi-S <effi.szt@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Effi-S <57197982+Effi-S@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Effi-S <57197982+Effi-S@users.noreply.github.com>
Signed-off-by: Effi-S <effi.szt@gmail.com>
…ad2a514477b29d5e1229160034bc7345b03b2f539e5de01746 Signed-off-by: Effi-S <effi.szt@gmail.com>
7e6c2fc to
914f0f8
Compare
Signed-off-by: Effi-S <effi.szt@gmail.com>
Signed-off-by: Effi-S <effi.szt@gmail.com>
…ializeAndParseSigningKey Signed-off-by: Effi-S <effi.szt@gmail.com>
Type of change
Description
envelope: nil checks + unit tests + minor refactorcrypto: nil checka + unit testsRelated issues