Skip to content

Commit

Permalink
Resolves hyperledger#80, this commit contains dependency update from …
Browse files Browse the repository at this point in the history
…fabric-protos-go to fabric-protos-go-apiv2 and "github.com/golang/protobuf"(deprecated) to "google.golang.org/protobuf

Bumped google.golang.org/protobuf to v1.31.0 from v1.5.2

It can be noticed that the package "github.com/golang/protobuf" is still an indirect dependency used by google.golang.org/grpc/credentials v1.53.0, even the latest update v1.58.0 still does.

Made sure all tests passed.

CHANGES INCLUDE:

	SOURCE CODE
The "AssertProtoEqual" was borrowed from: // https://github.com/hyperledger/fabric-gateway/blob/cd1bc1f3fcf007bd97244120d9a8d112153322cd/pkg/internal/test/transaction.go#L20-L22
which is more apt to test the Protobufs of google.golang.org/protobuf/ implementation. It replaced assertEqual.

now := ptypes.TimestampNow() --> now := timestamp.Now()

IMPORTS
All Import aliases are kept.
"github.com/golang/protobuf/proto" --> "google.golang.org/protobuf/proto"

pb "github.com/hyperledger/fabric-protos-go/peer" --> pb "github.com/hyperledger/fabric-protos-go-apiv2/peer"

"github.com/golang/protobuf/ptypes/timestamp" --> timestamp "google.golang.org/protobuf/types/known/timestamppb"

"github.com/hyperledger/fabric-protos-go/ledger/queryresult" --> "github.com/hyperledger/fabric-protos-go-apiv2/ledger/queryresult"

"github.com/hyperledger/fabric-protos-go/ledger/msp" →
"github.com/hyperledger/fabric-protos-go-apiv2/ledger/msp"
"github.com/hyperledger/fabric-protos-go/common" --> "github.com/hyperledger/fabric-protos-go-apiv2/common"

Signed-off-by: tobigiwa <[email protected]>
  • Loading branch information
tobigiwa committed Sep 17, 2023
1 parent d626e9a commit 48328d5
Show file tree
Hide file tree
Showing 23 changed files with 71 additions and 63 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ module github.com/hyperledger/fabric-chaincode-go
go 1.20

require (
github.com/golang/protobuf v1.5.2
github.com/hyperledger/fabric-protos-go v0.3.0
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.0
github.com/stretchr/testify v1.8.2
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.31.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/hyperledger/fabric-protos-go v0.3.0 h1:MXxy44WTMENOh5TI8+PCK2x6pMj47Go2vFRKDHB2PZs=
github.com/hyperledger/fabric-protos-go v0.3.0/go.mod h1:WWnyWP40P2roPmmvxsUXSvVI/CF6vwY1K1UFidnKBys=
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.0 h1:DOmDMloF3vKKJKXz+CsZhFgkUmnXKzP5ei71yGIbeOw=
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.0/go.mod h1:smwq1q6eKByqQAp0SYdVvE1MvDoneF373j11XwWajgA=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
Expand Down Expand Up @@ -43,6 +44,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
4 changes: 2 additions & 2 deletions pkg/attrmgr/attrmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"errors"
"fmt"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric-protos-go-apiv2/msp"
"google.golang.org/protobuf/proto"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions pkg/cid/cid.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"encoding/pem"
"fmt"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-chaincode-go/pkg/attrmgr"
"github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric-protos-go-apiv2/msp"
"google.golang.org/protobuf/proto"
)

// GetID returns the ID associated with the invoking identity. This ID
Expand Down
4 changes: 2 additions & 2 deletions pkg/cid/cid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"encoding/base64"
"testing"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-chaincode-go/pkg/cid"
"github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric-protos-go-apiv2/msp"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/proto"
)

const certWithOutAttrs = `-----BEGIN CERTIFICATE-----
Expand Down
6 changes: 3 additions & 3 deletions pkg/statebased/statebasedimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"fmt"
"sort"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric-protos-go-apiv2/common"
"github.com/hyperledger/fabric-protos-go-apiv2/msp"
"google.golang.org/protobuf/proto"
)

// stateEP implements the KeyEndorsementPolicy
Expand Down
6 changes: 3 additions & 3 deletions pkg/statebased/statebasedimpl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ package statebased_test
import (
"testing"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-chaincode-go/pkg/statebased"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric-protos-go-apiv2/common"
"github.com/hyperledger/fabric-protos-go-apiv2/msp"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/proto"
)

func TestAddOrg(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion shim/chaincodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"errors"

"github.com/hyperledger/fabric-chaincode-go/shim/internal"
pb "github.com/hyperledger/fabric-protos-go/peer"
pb "github.com/hyperledger/fabric-protos-go-apiv2/peer"

"google.golang.org/grpc/keepalive"
)
Expand Down
4 changes: 2 additions & 2 deletions shim/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"fmt"
"sync"

"github.com/golang/protobuf/proto"
pb "github.com/hyperledger/fabric-protos-go/peer"
pb "github.com/hyperledger/fabric-protos-go-apiv2/peer"
"google.golang.org/protobuf/proto"
)

type state string
Expand Down
2 changes: 1 addition & 1 deletion shim/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"

"github.com/hyperledger/fabric-chaincode-go/shim/internal/mock"
peerpb "github.com/hyperledger/fabric-protos-go/peer"
peerpb "github.com/hyperledger/fabric-protos-go-apiv2/peer"

"github.com/stretchr/testify/assert"
)
Expand Down
6 changes: 3 additions & 3 deletions shim/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
package shim

import (
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/hyperledger/fabric-protos-go/ledger/queryresult"
pb "github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric-protos-go-apiv2/ledger/queryresult"
pb "github.com/hyperledger/fabric-protos-go-apiv2/peer"
timestamp "google.golang.org/protobuf/types/known/timestamppb"
)

// Chaincode interface must be implemented by all chaincodes. The fabric runs
Expand Down
2 changes: 1 addition & 1 deletion shim/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"crypto/tls"
"time"

peerpb "github.com/hyperledger/fabric-protos-go/peer"
peerpb "github.com/hyperledger/fabric-protos-go-apiv2/peer"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/keepalive"
Expand Down
2 changes: 1 addition & 1 deletion shim/internal/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

pb "github.com/hyperledger/fabric-protos-go/peer"
pb "github.com/hyperledger/fabric-protos-go-apiv2/peer"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
Expand Down
2 changes: 1 addition & 1 deletion shim/internal/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"time"

. "github.com/hyperledger/fabric-chaincode-go/shim/internal"
peerpb "github.com/hyperledger/fabric-protos-go/peer"
peerpb "github.com/hyperledger/fabric-protos-go-apiv2/peer"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down
2 changes: 1 addition & 1 deletion shim/internal/mock/client_stream.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shim/internal/mock/peer_chaincode_stream.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shim/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package shim

import (
pb "github.com/hyperledger/fabric-protos-go/peer"
pb "github.com/hyperledger/fabric-protos-go-apiv2/peer"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions shim/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"os"
"unicode/utf8"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-chaincode-go/shim/internal"
peerpb "github.com/hyperledger/fabric-protos-go/peer"
peerpb "github.com/hyperledger/fabric-protos-go-apiv2/peer"
"google.golang.org/protobuf/proto"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion shim/shim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"

"github.com/hyperledger/fabric-chaincode-go/shim/internal/mock"
peerpb "github.com/hyperledger/fabric-protos-go/peer"
peerpb "github.com/hyperledger/fabric-protos-go-apiv2/peer"

"github.com/stretchr/testify/assert"
)
Expand Down
10 changes: 5 additions & 5 deletions shim/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"os"
"unicode/utf8"

"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/ledger/queryresult"
pb "github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric-protos-go-apiv2/common"
"github.com/hyperledger/fabric-protos-go-apiv2/ledger/queryresult"
pb "github.com/hyperledger/fabric-protos-go-apiv2/peer"
"google.golang.org/protobuf/proto"
timestamp "google.golang.org/protobuf/types/known/timestamppb"
)

// ChaincodeStub is an object passed to chaincode for shim side handling of
Expand Down
44 changes: 25 additions & 19 deletions shim/stub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ import (
"os"
"testing"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-chaincode-go/shim/internal/mock"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/ledger/queryresult"
peerpb "github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric-protos-go-apiv2/common"
"github.com/hyperledger/fabric-protos-go-apiv2/ledger/queryresult"
peerpb "github.com/hyperledger/fabric-protos-go-apiv2/peer"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"

timestamp "google.golang.org/protobuf/types/known/timestamppb"

"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func toChaincodeArgs(args ...string) [][]byte {
Expand All @@ -28,6 +30,10 @@ func toChaincodeArgs(args ...string) [][]byte {
return ccArgs
}

func AssertProtoEqual(t *testing.T, expected protoreflect.ProtoMessage, actual protoreflect.ProtoMessage) {
require.True(t, proto.Equal(expected, actual), "Expected %v, got %v", expected, actual)
}

func TestNewChaincodeStub(t *testing.T) {
expectedArgs := toChaincodeArgs("function", "arg1", "arg2")
expectedDecorations := map[string][]byte{"decoration-key": []byte("decoration-value")}
Expand Down Expand Up @@ -119,7 +125,7 @@ func TestNewChaincodeStub(t *testing.T) {
prop := &peerpb.Proposal{}
err = proto.Unmarshal(tt.signedProposal.ProposalBytes, prop)
assert.NoError(t, err)
assert.Equal(t, prop, stub.proposal)
AssertProtoEqual(t, prop, stub.proposal)

assert.Equal(t, expectedCreator, stub.creator)
assert.Equal(t, expectedTransient, stub.transient)
Expand Down Expand Up @@ -193,7 +199,7 @@ func TestChaincodeStubAccessors(t *testing.T) {
}

func TestChaincodeStubGetTxTimestamp(t *testing.T) {
now := ptypes.TimestampNow()
now := timestamp.Now()
tests := []struct {
proposal *peerpb.Proposal
ts *timestamp.Timestamp
Expand Down Expand Up @@ -399,7 +405,7 @@ func TestChaincodeStubHandlers(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error for GetQueryResult: %s", err)
}
assert.Equal(t, expectedResult, kv)
AssertProtoEqual(t, expectedResult, kv)

sqi, err = s.GetPrivateDataQueryResult("col", "query")
if err != nil {
Expand All @@ -409,7 +415,7 @@ func TestChaincodeStubHandlers(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error for GetPrivateDataQueryResult: %s", err)
}
assert.Equal(t, expectedResult, kv)
AssertProtoEqual(t, expectedResult, kv)

_, err = s.GetPrivateDataQueryResult("", "query")
assert.EqualError(t, err, "collection must not be an empty string")
Expand All @@ -423,14 +429,14 @@ func TestChaincodeStubHandlers(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error for GetStateByRange: %s", err)
}
assert.Equal(t, expectedResult, kv)
AssertProtoEqual(t, expectedResult, kv)
// second result
assert.True(t, sqi.HasNext())
kv, err = sqi.Next()
if err != nil {
t.Fatalf("Unexpected error for GetStateByRange: %s", err)
}
assert.Equal(t, expectedResult, kv)
AssertProtoEqual(t, expectedResult, kv)
err = sqi.Close()
assert.NoError(t, err)

Expand All @@ -439,7 +445,7 @@ func TestChaincodeStubHandlers(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error for GetStateByRangeWithPagination: %s", err)
}
assert.Equal(t, expectedResult, kv)
AssertProtoEqual(t, expectedResult, kv)
assert.Equal(t, "book", qrm.GetBookmark())
assert.Equal(t, int32(1), qrm.GetFetchedRecordsCount())

Expand All @@ -451,7 +457,7 @@ func TestChaincodeStubHandlers(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error for GetPrivateDataByRange: %s", err)
}
assert.Equal(t, expectedResult, kv)
AssertProtoEqual(t, expectedResult, kv)

_, err = s.GetPrivateDataByRange("", "", "end")
assert.EqualError(t, err, "collection must not be an empty string")
Expand All @@ -461,14 +467,14 @@ func TestChaincodeStubHandlers(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error for GetStateByPartialCompositeKey: %s", err)
}
assert.Equal(t, expectedResult, kv)
AssertProtoEqual(t, expectedResult, kv)

sqi, err = s.GetPrivateDataByPartialCompositeKey("col", "object", []string{"attr1", "attr2"})
kv, err = sqi.Next()
if err != nil {
t.Fatalf("Unexpected error for GetPrivateDataByPartialCompositeKey: %s", err)
}
assert.Equal(t, expectedResult, kv)
AssertProtoEqual(t, expectedResult, kv)

_, err = s.GetPrivateDataByPartialCompositeKey("", "object", []string{"attr1", "attr2"})
assert.EqualError(t, err, "collection must not be an empty string")
Expand All @@ -483,7 +489,7 @@ func TestChaincodeStubHandlers(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error for GetStateByPartialCompositeKeyWithPagination: %s", err)
}
assert.Equal(t, expectedResult, kv)
AssertProtoEqual(t, expectedResult, kv)
assert.Equal(t, "book", qrm.GetBookmark())
assert.Equal(t, int32(1), qrm.GetFetchedRecordsCount())

Expand All @@ -492,7 +498,7 @@ func TestChaincodeStubHandlers(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error forGetQueryResultWithPagination: %s", err)
}
assert.Equal(t, expectedResult, kv)
AssertProtoEqual(t, expectedResult, kv)
assert.Equal(t, "book", qrm.GetBookmark())
assert.Equal(t, int32(1), qrm.GetFetchedRecordsCount())
},
Expand Down Expand Up @@ -528,7 +534,7 @@ func TestChaincodeStubHandlers(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error for GetPrivateDataByRangee: %s", err)
}
assert.Equal(t, expectedResult, km)
AssertProtoEqual(t, expectedResult, km)
assert.False(t, hqi.HasNext())
},
},
Expand Down
Loading

0 comments on commit 48328d5

Please sign in to comment.