Skip to content

Commit cae9d23

Browse files
committed
Linter Fixes
Signed-off-by: Effi-S <effi.szt@gmail.com>
1 parent 2d8c910 commit cae9d23

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

utils/serialization/envelope_wrapper_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
16
package serialization_test
27

38
import (
49
"testing"
510

11+
"github.com/stretchr/testify/require"
12+
613
"github.com/hyperledger/fabric-protos-go-apiv2/common"
14+
"github.com/hyperledger/fabric/protoutil"
15+
716
"github.com/hyperledger/fabric-x-committer/utils/serialization"
817
"github.com/hyperledger/fabric-x-committer/utils/test"
9-
"github.com/hyperledger/fabric/protoutil"
10-
"github.com/stretchr/testify/require"
1118
)
1219

13-
// UnwrapEnvelope function with invalid inputs
20+
// TestUnwrapEnvelopeBadInput tests UnwrapEnvelope function with invalid inputs.
1421
func TestUnwrapEnvelopeBadInput(t *testing.T) {
1522
t.Run("Not an envelope", func(t *testing.T) {
23+
t.Parallel()
1624
_, _, err := serialization.UnwrapEnvelope([]byte("invalid input"))
1725
require.Error(t, err)
1826
})
1927

2028
t.Run("OK Header with an invalid payload", func(t *testing.T) {
29+
t.Parallel()
2130
envelope := &common.Envelope{
2231
Payload: []byte("not-a-payload"),
2332
}
@@ -29,6 +38,7 @@ func TestUnwrapEnvelopeBadInput(t *testing.T) {
2938
})
3039

3140
t.Run(" OK Payload with a nil Header", func(t *testing.T) {
41+
t.Parallel()
3242
payload := &common.Payload{
3343
Header: nil,
3444
Data: []byte("some data"),
@@ -45,6 +55,7 @@ func TestUnwrapEnvelopeBadInput(t *testing.T) {
4555
})
4656

4757
t.Run("OK payload but invalid ChannelHeader", func(t *testing.T) {
58+
t.Parallel()
4859
header := &common.Header{
4960
ChannelHeader: []byte("not-a-channel-header"),
5061
}
@@ -64,9 +75,9 @@ func TestUnwrapEnvelopeBadInput(t *testing.T) {
6475
})
6576
}
6677

67-
// Test properly wrapped envelope is unwrapped correctly
78+
// TestUnwrapEnvelopeGoodInput Tests properly wrapped envelope is unwrapped correctly.
6879
func TestUnwrapEnvelopeGoodInput(t *testing.T) {
69-
80+
t.Parallel()
7081
// -1- Check unwrap envelope has no error
7182
originalPayload := []byte("test payload")
7283
originalChannelHeader := &common.ChannelHeader{
@@ -75,7 +86,6 @@ func TestUnwrapEnvelopeGoodInput(t *testing.T) {
7586
originalHeader := &common.Header{
7687
ChannelHeader: protoutil.MarshalOrPanic(originalChannelHeader),
7788
}
78-
7989
wrappedEnvelope := serialization.WrapEnvelope(originalPayload, originalHeader)
8090
payload, channelHeader, err := serialization.UnwrapEnvelope(wrappedEnvelope)
8191

utils/signature/sigtest/crypto.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func SerializeVerificationKey(key *ecdsa.PublicKey) ([]byte, error) {
3232

3333
// SerializeSigningKey encodes a ECDSA private key into a PEM file.
3434
func SerializeSigningKey(key *ecdsa.PrivateKey) ([]byte, error) {
35-
3635
if key == nil {
3736
return nil, errors.New("key is nil")
3837
}

utils/signature/sigtest/crypto_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
16
package sigtest
27

38
import (
49
"crypto/ecdsa"
510
"crypto/elliptic"
611
"crypto/rand"
7-
"fmt"
812
"testing"
913

1014
"github.com/stretchr/testify/require"
1115
)
1216

1317
func TestSerializeVerificationKey(t *testing.T) {
18+
t.Parallel()
1419
tests := []struct {
1520
name string
1621
curve elliptic.Curve
@@ -43,6 +48,7 @@ func TestSerializeVerificationKey(t *testing.T) {
4348

4449
for _, tt := range tests {
4550
t.Run(tt.name, func(t *testing.T) {
51+
t.Parallel()
4652
privKey, err := ecdsa.GenerateKey(tt.curve, rand.Reader)
4753
require.NoError(t, err)
4854

@@ -57,7 +63,6 @@ func TestSerializeVerificationKey(t *testing.T) {
5763
}
5864

5965
func TestSerializeSigningKey(t *testing.T) {
60-
6166
// Panic can happen from unwanted side effects when nil and empty Keys are passed
6267
defer func() {
6368
if r := recover(); r != nil {
@@ -66,31 +71,37 @@ func TestSerializeSigningKey(t *testing.T) {
6671
}()
6772

6873
t.Run("Key Empty", func(t *testing.T) {
74+
t.Parallel()
6975
emptyKey := &ecdsa.PrivateKey{}
7076
_, err := SerializeSigningKey(emptyKey)
7177
require.Error(t, err)
7278
})
7379
t.Run("Key is nil", func(t *testing.T) {
80+
t.Parallel()
7481
_, err := SerializeSigningKey(nil)
7582
require.Error(t, err)
7683
})
7784

7885
t.Run("Key OK", func(t *testing.T) {
86+
t.Parallel()
7987
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
88+
require.NoError(t, err)
8089
key, err := SerializeSigningKey(privateKey)
81-
fmt.Println(key)
90+
require.NotNil(t, key)
8291
require.NoError(t, err)
8392
})
84-
8593
}
8694

8795
func TestParseSigningKey(t *testing.T) {
8896
t.Run("Key is nil", func(t *testing.T) {
97+
t.Parallel()
8998
_, err := ParseSigningKey(nil)
9099
require.Error(t, err)
91100
})
92101
t.Run("Key OK", func(t *testing.T) {
102+
t.Parallel()
93103
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
104+
require.NoError(t, err)
94105
key, err := SerializeSigningKey(privateKey)
95106
require.NoError(t, err)
96107
_, err = ParseSigningKey(key)

0 commit comments

Comments
 (0)