Skip to content

Conversation

@Effi-S
Copy link
Contributor

@Effi-S Effi-S commented Aug 6, 2025

Type of change

  • Testing

Description

  1. envelope: nil checks + unit tests + minor refactor
  2. crypto: nil checka + unit tests

Related issues

@Effi-S Effi-S requested a review from liran-funaro August 7, 2025 08:49
@cendhu cendhu requested a review from Copilot August 7, 2025 10:32
Copy link

Copilot AI left a 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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor:

Suggested change
func WrapEnvelope(data []byte, header *common.Header) []byte {
func WrapEnvelope(serializedPayload []byte, header *common.Header) []byte {

Comment on lines +59 to +65
header := &common.Header{
ChannelHeader: []byte("not-a-channel-header"),
}
payload := &common.Payload{
Header: header,
Data: []byte("some data"),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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?
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: Remove

Comment on lines 67 to 71
defer func() {
if r := recover(); r != nil {
t.Errorf("SerializeSigningKey() panics: %v", r)
}
}()
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

major: missing t.Parallel()

Comment on lines +35 to +37
if key == nil {
return nil, errors.New("key is nil")
}
Copy link
Contributor

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) {
Copy link
Contributor

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).

Effi-S and others added 6 commits October 29, 2025 11:52
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>
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>
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