Skip to content

Commit

Permalink
Update fabric-protos
Browse files Browse the repository at this point in the history
New version of fabric-protos uses updated protoc and protobuf versions,
including protobuf-java v4. This change updates from protobuf-java v3 to
v4.

The change to use generics in the newer generated gRPC client stubs
means that the previous approach of mocking them using uber-go/mock is
not possible. This change uses mockery to mock the gRPC client
connection instead. Mockery does support mocking of most generics, and
mocking at the connection allows unit testing to be done using the
public API without test hooks to allow replacement of gRPC stubs.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
  • Loading branch information
bestbeforetoday committed Sep 30, 2024
1 parent 050e807 commit bdc2657
Show file tree
Hide file tree
Showing 21 changed files with 1,565 additions and 1,799 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ linters:
- govet
- ineffassign
- misspell
- testifylint
- typecheck
- unused

Expand Down
13 changes: 13 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
with-expecter: true
exported: true
filename: "{{.InterfaceName | lower}}_mock_test.go"
mockname: "Mock{{.InterfaceName | firstUpper}}"
unroll-variadic: false
packages:
google.golang.org/grpc:
config:
dir: pkg/client
outpkg: client
interfaces:
ClientConnInterface:
ClientStream:
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ scenario_dir := $(base_dir)/scenario

go_bin_dir := $(shell go env GOPATH)/bin

mockery_version := 2.46.0
kernel_name := $(shell uname -s)
machine_hardware := $(shell uname -m)

# PEER_IMAGE_PULL is where to pull peer image from, it can be set by external env variable
# In fabric-gateway main branch it should reflect the location of the latest fabric main branch image
PEER_IMAGE_PULL ?= hyperledger-fabric.jfrog.io/fabric-peer:amd64-2.5-stable
Expand Down Expand Up @@ -143,10 +147,18 @@ scan-java-osv-scanner:
go install github.com/google/osv-scanner/cmd/osv-scanner@latest
osv-scanner scan --lockfile='$(java_dir)/pom.xml'

.PHONY: install-mockery
install-mockery:
curl --fail --location \
'https://github.com/vektra/mockery/releases/download/v$(mockery_version)/mockery_$(mockery_version)_$(kernel_name)_$(machine_hardware).tar.gz' \
| tar -C '$(go_bin_dir)' -xzf - mockery

$(go_bin_dir)/mockery:
$(MAKE) install-mockery

.PHONY: generate
generate:
go install go.uber.org/mock/mockgen@latest
go generate '$(go_dir)/...'
generate: $(go_bin_dir)/mockery
cd '$(base_dir)' && mockery

.PHONY: vendor-chaincode
vendor-chaincode:
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ go 1.22.0

require (
github.com/cucumber/godog v0.14.1
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.3
github.com/google/go-cmp v0.6.0
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.4
github.com/miekg/pkcs11 v1.1.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
go.uber.org/mock v0.4.0
golang.org/x/crypto v0.27.0
google.golang.org/grpc v1.67.0
google.golang.org/protobuf v1.34.2
Expand All @@ -23,6 +23,7 @@ require (
github.com/hashicorp/go-memdb v1.3.4 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.3 h1:Xpd6fzG/KjAOHJsq7EQXY2l+qi/y8muxBaY7R6QWABk=
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.3/go.mod h1:2pq0ui6ZWA0cC8J+eCErgnMDCS1kPOEYVY+06ZAK0qE=
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.4 h1:YJrd+gMaeY0/vsN0aS0QkEKTivGoUnSRIXxGJ7KI+Pc=
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.4/go.mod h1:bau/6AJhvEcu9GKKYHlDXAxXKzYNfhP6xu2GXuxEcFk=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand All @@ -46,14 +46,14 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
Expand Down
16 changes: 8 additions & 8 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<javaVersion>8</javaVersion>
<bouncyCastleVersion>1.78.1</bouncyCastleVersion>
<skipUnitTests>${skipTests}</skipUnitTests>
<pmdVersion>7.5.0</pmdVersion>
<pmdVersion>7.6.0</pmdVersion>
</properties>

<dependencyManagement>
Expand All @@ -55,22 +55,22 @@
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.0</version>
<version>5.11.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-bom</artifactId>
<version>1.68.0</version>
<version>1.67.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Override transitive dependency from grpc-protobuf:1.66.0 to avoid CVE-2024-7254 -->
<!-- Override transitive dependency from grpc-protobuf to avoid CVE-2024-7254 -->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-bom</artifactId>
<version>3.25.5</version>
<version>4.28.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -97,7 +97,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.13.0</version>
<version>5.14.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -146,7 +146,7 @@
<dependency>
<groupId>org.hyperledger.fabric</groupId>
<artifactId>fabric-protos</artifactId>
<version>0.3.3</version>
<version>0.3.4</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -530,7 +530,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.5</version>
<version>3.2.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down
4 changes: 2 additions & 2 deletions node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"license": "Apache-2.0",
"dependencies": {
"@grpc/grpc-js": "^1.11.0",
"@hyperledger/fabric-protos": "^0.3.0",
"@hyperledger/fabric-protos": "^0.3.4",
"@noble/curves": "^1.6.0",
"google-protobuf": "^3.21.0"
},
Expand All @@ -57,6 +57,6 @@
"ts-jest": "^29.2.4",
"typedoc": "^0.26.6",
"typescript": "~5.5.4",
"typescript-eslint": "~8.5.0"
"typescript-eslint": "^8.7.0"
}
}
Loading

0 comments on commit bdc2657

Please sign in to comment.