From 11cdb91e422df50874ca685bbac5a7b6486b3fac Mon Sep 17 00:00:00 2001 From: Fedor Partanskiy Date: Sun, 17 May 2026 23:07:40 +0300 Subject: [PATCH] bump go to 1.25.10 and libs Signed-off-by: Fedor Partanskiy --- .github/workflows/test.yml | 8 +++-- .golangci.yml | 26 +++++++++------- go.mod | 12 ++++---- go.sum | 40 ++++++++++++------------ pkg/cid/cid_test.go | 16 +++++++--- pkg/cid/interfaces.go | 1 - shim/handler.go | 19 +++++++++--- shim/handler_test.go | 5 ++- shim/internal/client.go | 1 - shim/internal/config.go | 7 +++-- shim/internal/config_test.go | 23 ++++++++------ shim/internal/server_test.go | 1 - shim/shim.go | 1 - shim/shim_test.go | 10 ++---- shim/stub.go | 59 ++++++++++++++++++++++-------------- shim/stub_test.go | 5 ++- 16 files changed, 132 insertions(+), 102 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80709d7a..2b7d6570 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,12 +13,14 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: "1.21" + go-version: "1.25.10" - name: Staticcheck run: make staticcheck - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v9 with: - version: latest + version: v2.9.0 + skip-cache: true + problem-matchers: true - name: Unit test run: make unit-test diff --git a/.golangci.yml b/.golangci.yml index 803ec673..0faef546 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,22 +1,26 @@ # See https://golangci-lint.run/usage/configuration/ - +version: "2" run: timeout: 5m + concurrency: 4 + go: "1.25" linters: - disable-all: true + default: none enable: - - errcheck - - gofmt - - goimports - gosec - - gosimple + - staticcheck - govet - ineffassign - misspell - - typecheck - unused -linters-settings: - gosec: - excludes: - - 'G115' # safe to exclude type conversion overflow checks in this repository since the integer values will always be low + settings: + gosec: + excludes: + - G115 # safe to exclude type conversion overflow checks in this repository since the integer values will always be low +formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports \ No newline at end of file diff --git a/go.mod b/go.mod index 00915bf2..57cb4058 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,11 @@ module github.com/hyperledger/fabric-chaincode-go/v2 -go 1.24.0 +go 1.25.10 require ( github.com/hyperledger/fabric-protos-go-apiv2 v0.3.7 github.com/stretchr/testify v1.11.1 - google.golang.org/grpc v1.80.0 + google.golang.org/grpc v1.81.1 google.golang.org/protobuf v1.36.11 ) @@ -13,10 +13,10 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/net v0.49.0 // indirect - golang.org/x/sys v0.40.0 // indirect - golang.org/x/text v0.33.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516 // indirect + golang.org/x/net v0.54.0 // indirect + golang.org/x/sys v0.44.0 // indirect + golang.org/x/text v0.37.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260511170946-3700d4141b60 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 111736f7..ae87489b 100644 --- a/go.sum +++ b/go.sum @@ -27,28 +27,28 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= -go.opentelemetry.io/otel v1.39.0 h1:8yPrr/S0ND9QEfTfdP9V+SiwT4E0G7Y5MO7p85nis48= -go.opentelemetry.io/otel v1.39.0/go.mod h1:kLlFTywNWrFyEdH0oj2xK0bFYZtHRYUdv1NklR/tgc8= -go.opentelemetry.io/otel/metric v1.39.0 h1:d1UzonvEZriVfpNKEVmHXbdf909uGTOQjA0HF0Ls5Q0= -go.opentelemetry.io/otel/metric v1.39.0/go.mod h1:jrZSWL33sD7bBxg1xjrqyDjnuzTUB0x1nBERXd7Ftcs= -go.opentelemetry.io/otel/sdk v1.39.0 h1:nMLYcjVsvdui1B/4FRkwjzoRVsMK8uL/cj0OyhKzt18= -go.opentelemetry.io/otel/sdk v1.39.0/go.mod h1:vDojkC4/jsTJsE+kh+LXYQlbL8CgrEcwmt1ENZszdJE= -go.opentelemetry.io/otel/sdk/metric v1.39.0 h1:cXMVVFVgsIf2YL6QkRF4Urbr/aMInf+2WKg+sEJTtB8= -go.opentelemetry.io/otel/sdk/metric v1.39.0/go.mod h1:xq9HEVH7qeX69/JnwEfp6fVq5wosJsY1mt4lLfYdVew= -go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI= -go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA= -golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o= -golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8= -golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= -golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= -golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= +go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I= +go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0= +go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM= +go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY= +go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg= +go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg= +go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw= +go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A= +go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A= +go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0= +golang.org/x/net v0.54.0 h1:2zJIZAxAHV/OHCDTCOHAYehQzLfSXuf/5SoL/Dv6w/w= +golang.org/x/net v0.54.0/go.mod h1:Sj4oj8jK6XmHpBZU/zWHw3BV3abl4Kvi+Ut7cQcY+cQ= +golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ= +golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc= +golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516 h1:sNrWoksmOyF5bvJUcnmbeAmQi8baNhqg5IWaI3llQqU= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ= -google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM= -google.golang.org/grpc v1.80.0/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260511170946-3700d4141b60 h1:seT2EwLWM78plQ7wcDfuWBc/4FAEAXDDiaSol4ku4qo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260511170946-3700d4141b60/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= +google.golang.org/grpc v1.81.1 h1:VnnIIZ88UzOOKLukQi+ImGz8O1Wdp8nAGGnvOfEIWQQ= +google.golang.org/grpc v1.81.1/go.mod h1:xGH9GfzOyMTGIOXBJmXt+BX/V0kcdQbdcuwQ/zNw42I= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/pkg/cid/cid_test.go b/pkg/cid/cid_test.go index 04b9db18..00a2ff1e 100644 --- a/pkg/cid/cid_test.go +++ b/pkg/cid/cid_test.go @@ -29,6 +29,7 @@ KoZIzj0EAwIDRwAwRAIgCoXaCdU8ZiRKkai0QiXJM/GL5fysLnmG2oZ6XOIdwtsC IEmCsI8Mhrvx1doTbEOm7kmIrhQwUVDBNXCWX1t3kJVN -----END CERTIFICATE----- ` + const certWithAttrs = `-----BEGIN CERTIFICATE----- MIIB6TCCAY+gAwIBAgIUHkmY6fRP0ANTvzaBwKCkMZZPUnUwCgYIKoZIzj0EAwIw GzEZMBcGA1UEAxMQZmFicmljLWNhLXNlcnZlcjAeFw0xNzA5MDgwMzQyMDBaFw0x @@ -133,8 +134,10 @@ func TestIdemix(t *testing.T) { func getMockStub() (cid.ChaincodeStubInterface, error) { stub := &mockStub{} - sid := &msp.SerializedIdentity{Mspid: "SampleOrg", - IdBytes: []byte(certWithOutAttrs)} + sid := &msp.SerializedIdentity{ + Mspid: "SampleOrg", + IdBytes: []byte(certWithOutAttrs), + } b, err := proto.Marshal(sid) if err != nil { return nil, err @@ -145,8 +148,10 @@ func getMockStub() (cid.ChaincodeStubInterface, error) { func getMockStubWithAttrs() (cid.ChaincodeStubInterface, error) { stub := &mockStub{} - sid := &msp.SerializedIdentity{Mspid: "SampleOrg", - IdBytes: []byte(certWithAttrs)} + sid := &msp.SerializedIdentity{ + Mspid: "SampleOrg", + IdBytes: []byte(certWithAttrs), + } b, err := proto.Marshal(sid) if err != nil { return nil, err @@ -161,7 +166,8 @@ func getIdemixMockStubWithAttrs() (cid.ChaincodeStubInterface, error) { if err != nil { return nil, err } - sid := &msp.SerializedIdentity{Mspid: "idemixOrg", + sid := &msp.SerializedIdentity{ + Mspid: "idemixOrg", IdBytes: idBytes, } b, err := proto.Marshal(sid) diff --git a/pkg/cid/interfaces.go b/pkg/cid/interfaces.go index 140ffe98..b67e4930 100644 --- a/pkg/cid/interfaces.go +++ b/pkg/cid/interfaces.go @@ -17,7 +17,6 @@ type ChaincodeStubInterface interface { // ClientIdentity represents information about the identity that submitted the // transaction type ClientIdentity interface { - // GetID returns the ID associated with the invoking identity. This ID // is guaranteed to be unique within the MSP. GetID() (string, error) diff --git a/shim/handler.go b/shim/handler.go index d9daa5d6..331ffaaf 100644 --- a/shim/handler.go +++ b/shim/handler.go @@ -548,8 +548,12 @@ func (h *Handler) sendBatch(channelID string, txid string, writes []*peer.WriteR return nil } -func (h *Handler) handleGetStateByRange(collection, startKey, endKey string, metadata []byte, - channelID string, txid string) (*peer.QueryResponse, error) { +func (h *Handler) handleGetStateByRange( + collection, startKey, endKey string, + metadata []byte, + channelID string, + txid string, +) (*peer.QueryResponse, error) { // Send GET_STATE_BY_RANGE message to peer chaincode support payloadBytes := marshalOrPanic(&peer.GetStateByRange{Collection: collection, StartKey: startKey, EndKey: endKey, Metadata: metadata}) msg := &peer.ChaincodeMessage{Type: peer.ChaincodeMessage_GET_STATE_BY_RANGE, Payload: payloadBytes, Txid: txid, ChannelId: channelID} @@ -651,8 +655,13 @@ func (h *Handler) handleQueryStateClose(id, channelID, txid string) (*peer.Query return nil, fmt.Errorf("incorrect chaincode message %s received. Expecting %s or %s", responseMsg.Type, peer.ChaincodeMessage_RESPONSE, peer.ChaincodeMessage_ERROR) } -func (h *Handler) handleGetQueryResult(collection string, query string, metadata []byte, - channelID string, txid string) (*peer.QueryResponse, error) { +func (h *Handler) handleGetQueryResult( + collection string, + query string, + metadata []byte, + channelID string, + txid string, +) (*peer.QueryResponse, error) { // Send GET_QUERY_RESULT message to peer chaincode support payloadBytes := marshalOrPanic(&peer.GetQueryResult{Collection: collection, Query: query, Metadata: metadata}) msg := &peer.ChaincodeMessage{Type: peer.ChaincodeMessage_GET_QUERY_RESULT, Payload: payloadBytes, Txid: txid, ChannelId: channelID} @@ -853,7 +862,7 @@ func (h *Handler) handleMessage(msg *peer.ChaincodeMessage, errc chan error) err if err != nil { payload := []byte(err.Error()) errorMsg := &peer.ChaincodeMessage{Type: peer.ChaincodeMessage_ERROR, Payload: payload, Txid: msg.Txid} - h.serialSend(errorMsg) //nolint:errcheck + h.serialSend(errorMsg) //nolint:gosec return err } diff --git a/shim/handler_test.go b/shim/handler_test.go index b751f356..36a01e90 100644 --- a/shim/handler_test.go +++ b/shim/handler_test.go @@ -60,7 +60,7 @@ func TestNewHandler_CreatedState(t *testing.T) { func TestHandlerState(t *testing.T) { t.Parallel() - var tests = []struct { + tests := []struct { name string state state msg *peer.ChaincodeMessage @@ -135,7 +135,7 @@ func TestHandlerState(t *testing.T) { func TestHandleMessage(t *testing.T) { t.Parallel() - var tests = []struct { + tests := []struct { name string msg *peer.ChaincodeMessage msgType peer.ChaincodeMessage_Type @@ -294,5 +294,4 @@ func TestHandlePeerCalls(t *testing.T) { _, err = h.handleGetHistoryForKey("key", "channel", "txid") assert.ErrorContains(t, err, "cannot create response channel") - } diff --git a/shim/internal/client.go b/shim/internal/client.go index 4516375d..4375202c 100644 --- a/shim/internal/client.go +++ b/shim/internal/client.go @@ -27,7 +27,6 @@ func NewClientConn( tlsConf *tls.Config, kaOpts keepalive.ClientParameters, ) (*grpc.ClientConn, error) { - dialOpts := []grpc.DialOption{ grpc.WithKeepaliveParams(kaOpts), grpc.WithDefaultCallOptions( diff --git a/shim/internal/config.go b/shim/internal/config.go index d174494d..c6600715 100644 --- a/shim/internal/config.go +++ b/shim/internal/config.go @@ -48,7 +48,7 @@ func LoadConfig() (Config, error) { var key []byte path, set := os.LookupEnv("CORE_TLS_CLIENT_KEY_FILE") if set { - key, err = os.ReadFile(path) + key, err = os.ReadFile(path) //nolint:gosec if err != nil { return Config{}, fmt.Errorf("failed to read private key file: %s", err) } @@ -66,7 +66,7 @@ func LoadConfig() (Config, error) { var cert []byte path, set = os.LookupEnv("CORE_TLS_CLIENT_CERT_FILE") if set { - cert, err = os.ReadFile(path) + cert, err = os.ReadFile(path) //nolint:gosec if err != nil { return Config{}, fmt.Errorf("failed to read public key file: %s", err) } @@ -132,7 +132,8 @@ func LoadTLSConfig(isserver bool, key, cert, root []byte) (*tls.Config, error) { if isserver { tlscfg.ClientCAs = rootCertPool tlscfg.SessionTicketsDisabled = true - tlscfg.CipherSuites = []uint16{tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + tlscfg.CipherSuites = []uint16{ + tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, diff --git a/shim/internal/config_test.go b/shim/internal/config_test.go index 63586fd8..be40ad16 100644 --- a/shim/internal/config_test.go +++ b/shim/internal/config_test.go @@ -29,6 +29,7 @@ IRoYMsQximSiU7XvGCYLslx4GauhRANCAARBGdslxalpg0dxk9GwVhi+Qw9oKZPE n1hWPFmusDKtNbDLsHd9k1lU+SWnJKYlg7hmaUvxC1lR2M6KmvAwSUfN -----END PRIVATE KEY----- ` + var certPEM = `-----BEGIN CERTIFICATE----- MIICaTCCAhCgAwIBAgIQS46wcUDY2nJ2gQ/7fp/ptzAKBggqhkjOPQQDAjB2MQsw CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy @@ -45,6 +46,7 @@ Y2OHBH8AAAEwCgYIKoZIzj0EAwIDRwAwRAIgWgxAuGibD+Da/qCLBryJMDGlyIrx HV+tI33lEy1B9qoCIEJD4xipI2WYp1sHmK2nxYPcoTb9WLFdNZ6twKZyw9c8 -----END CERTIFICATE----- ` + var rootPEM = `-----BEGIN CERTIFICATE----- MIICSTCCAe+gAwIBAgIQWpamEC5/D2N5JKS8FEpgTzAKBggqhkjOPQQDAjB2MQsw CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy @@ -173,7 +175,7 @@ func TestLoadBase64EncodedConfig(t *testing.T) { PermitWithoutStream: true, } - var tests = []struct { + tests := []struct { name string env map[string]string expected Config @@ -300,7 +302,7 @@ func TestLoadBase64EncodedConfig(t *testing.T) { test := test t.Run(test.name, func(t *testing.T) { for k, v := range test.env { - os.Setenv(k, v) + os.Setenv(k, v) //nolint:gosec } conf, err := LoadConfig() if test.errMsg == "" { @@ -320,7 +322,8 @@ func TestLoadBase64EncodedConfig(t *testing.T) { Certificates: []tls.Certificate{clientCert}, ClientCAs: rootPool, SessionTicketsDisabled: true, - CipherSuites: []uint16{tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + CipherSuites: []uint16{ + tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, @@ -335,7 +338,8 @@ func TestLoadBase64EncodedConfig(t *testing.T) { Certificates: []tls.Certificate{clientCert}, RootCAs: nil, SessionTicketsDisabled: true, - CipherSuites: []uint16{tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + CipherSuites: []uint16{ + tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, @@ -346,7 +350,7 @@ func TestLoadBase64EncodedConfig(t *testing.T) { } // additional tests to differentiate client vs server - var tlsTests = []struct { + tlsTests := []struct { name string issrv bool key []byte @@ -486,7 +490,7 @@ func TestLoadPEMEncodedConfig(t *testing.T) { PermitWithoutStream: true, } - var tests = []struct { + tests := []struct { name string env map[string]string expected Config @@ -565,7 +569,7 @@ func TestLoadPEMEncodedConfig(t *testing.T) { test := test t.Run(test.name, func(t *testing.T) { for k, v := range test.env { - os.Setenv(k, v) + os.Setenv(k, v) //nolint:gosec } conf, err := LoadConfig() if test.errMsg == "" { @@ -631,7 +635,8 @@ func TestTLSClientWithChaincodeServer(t *testing.T) { Certificates: []tls.Certificate{cert}, ClientCAs: rootPool, SessionTicketsDisabled: true, - CipherSuites: []uint16{tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + CipherSuites: []uint16{ + tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, @@ -642,7 +647,7 @@ func TestTLSClientWithChaincodeServer(t *testing.T) { } // given server is good and expects valid TLS connection, test good and invalid scenarios - var tlsTests = []struct { + tlsTests := []struct { name string issrv bool clientKey []byte diff --git a/shim/internal/server_test.go b/shim/internal/server_test.go index 03d0e855..5b178f9a 100644 --- a/shim/internal/server_test.go +++ b/shim/internal/server_test.go @@ -12,7 +12,6 @@ import ( "time" "github.com/hyperledger/fabric-chaincode-go/v2/shim/internal" - "github.com/stretchr/testify/assert" "google.golang.org/grpc/keepalive" ) diff --git a/shim/shim.go b/shim/shim.go index f9e263bd..268f738e 100644 --- a/shim/shim.go +++ b/shim/shim.go @@ -104,7 +104,6 @@ func chatWithPeer(chaincodename string, stream PeerChaincodeStream, cc Chaincode // Register on the stream if err = handler.serialSend(&peer.ChaincodeMessage{Type: peer.ChaincodeMessage_REGISTER, Payload: payload}); err != nil { return fmt.Errorf("error sending chaincode REGISTER: %s", err) - } // holds return values from gRPC Recv below diff --git a/shim/shim_test.go b/shim/shim_test.go index 15ef616a..f21b8971 100644 --- a/shim/shim_test.go +++ b/shim/shim_test.go @@ -23,8 +23,7 @@ type MockQueryIteratorInterface interface { } func TestStart(t *testing.T) { - - var tests = []struct { + tests := []struct { name string envVars map[string]string peerAddress string @@ -129,7 +128,7 @@ func TestStart(t *testing.T) { test := test t.Run(test.name, func(t *testing.T) { for k, v := range test.envVars { - os.Setenv(k, v) + os.Setenv(k, v) //nolint:gosec defer os.Unsetenv(k) } peerAddress = &test.peerAddress @@ -138,12 +137,10 @@ func TestStart(t *testing.T) { assert.EqualError(t, err, test.expectedErr) }) } - } func TestChaincodeServerStart(t *testing.T) { - - var tests = []struct { + tests := []struct { name string ccsrv ChaincodeServer streamGetter func(name string) (ClientStream, error) @@ -199,5 +196,4 @@ func TestChaincodeServerStart(t *testing.T) { } }) } - } diff --git a/shim/stub.go b/shim/stub.go index 9f6cec31..45729c1f 100644 --- a/shim/stub.go +++ b/shim/stub.go @@ -61,7 +61,6 @@ func newChaincodeStub(handler *Handler, channelID, txid string, input *peer.Chai stub.proposal = &peer.Proposal{} err = proto.Unmarshal(signedProposal.ProposalBytes, stub.proposal) if err != nil { - return nil, fmt.Errorf("failed to extract Proposal from SignedProposal: %s", err) } @@ -437,9 +436,10 @@ func createQueryResponseMetadata(metadataBytes []byte) (*peer.QueryResponseMetad return metadata, nil } -func (s *ChaincodeStub) handleGetStateByRange(collection, startKey, endKey string, - metadata []byte) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error) { - +func (s *ChaincodeStub) handleGetStateByRange( + collection, startKey, endKey string, + metadata []byte, +) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error) { response, err := s.handler.handleGetStateByRange(collection, startKey, endKey, metadata, s.ChannelID, s.TxID) if err != nil { return nil, nil, err @@ -454,9 +454,10 @@ func (s *ChaincodeStub) handleGetStateByRange(collection, startKey, endKey strin return iterator, responseMetadata, nil } -func (s *ChaincodeStub) handleGetQueryResult(collection, query string, - metadata []byte) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error) { - +func (s *ChaincodeStub) handleGetQueryResult( + collection, query string, + metadata []byte, +) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error) { response, err := s.handler.handleGetQueryResult(collection, query, metadata, s.ChannelID, s.TxID) if err != nil { return nil, nil, err @@ -583,9 +584,11 @@ func createQueryMetadata(pageSize int32, bookmark string) ([]byte, error) { } // GetStateByRangeWithPagination ... -func (s *ChaincodeStub) GetStateByRangeWithPagination(startKey, endKey string, pageSize int32, - bookmark string) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error) { - +func (s *ChaincodeStub) GetStateByRangeWithPagination( + startKey, endKey string, + pageSize int32, + bookmark string, +) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error) { if startKey == "" { startKey = emptyKeySubstitute } @@ -604,9 +607,12 @@ func (s *ChaincodeStub) GetStateByRangeWithPagination(startKey, endKey string, p } // GetStateByPartialCompositeKeyWithPagination ... -func (s *ChaincodeStub) GetStateByPartialCompositeKeyWithPagination(objectType string, keys []string, - pageSize int32, bookmark string) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error) { - +func (s *ChaincodeStub) GetStateByPartialCompositeKeyWithPagination( + objectType string, + keys []string, + pageSize int32, + bookmark string, +) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error) { collection := "" metadata, err := createQueryMetadata(pageSize, bookmark) @@ -622,8 +628,11 @@ func (s *ChaincodeStub) GetStateByPartialCompositeKeyWithPagination(objectType s } // GetQueryResultWithPagination ... -func (s *ChaincodeStub) GetQueryResultWithPagination(query string, pageSize int32, - bookmark string) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error) { +func (s *ChaincodeStub) GetQueryResultWithPagination( + query string, + pageSize int32, + bookmark string, +) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error) { // Access public data by setting the collection to empty string collection := "" @@ -635,8 +644,10 @@ func (s *ChaincodeStub) GetQueryResultWithPagination(query string, pageSize int3 } // GetAllStatesCompositeKeyWithPagination ... -func (s *ChaincodeStub) GetAllStatesCompositeKeyWithPagination(pageSize int32, - bookmark string) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error) { +func (s *ChaincodeStub) GetAllStatesCompositeKeyWithPagination( + pageSize int32, + bookmark string, +) (StateQueryIteratorInterface, *peer.QueryResponseMetadata, error) { collection := "" metadata, err := createQueryMetadata(pageSize, bookmark) if err != nil { @@ -693,23 +704,25 @@ func (iter *CommonIterator) HasNext() bool { // or KeyModification depending on the result type (i.e., state (range/execute) // query, history query). Note that queryResult is an empty golang // interface that can hold values of any type. -func (iter *CommonIterator) getResultFromBytes(queryResultBytes *peer.QueryResultBytes, - rType resultType) (queryResult, error) { - - if rType == StateQueryResult { +func (iter *CommonIterator) getResultFromBytes( + queryResultBytes *peer.QueryResultBytes, + rType resultType, +) (queryResult, error) { + switch rType { + case StateQueryResult: stateQueryResult := &queryresult.KV{} if err := proto.Unmarshal(queryResultBytes.ResultBytes, stateQueryResult); err != nil { return nil, fmt.Errorf("error unmarshaling result from bytes: %s", err) } return stateQueryResult, nil - - } else if rType == HistoryQueryResult { + case HistoryQueryResult: historyQueryResult := &queryresult.KeyModification{} if err := proto.Unmarshal(queryResultBytes.ResultBytes, historyQueryResult); err != nil { return nil, err } return historyQueryResult, nil } + return nil, errors.New("wrong result type") } diff --git a/shim/stub_test.go b/shim/stub_test.go index 1f319108..6f9a7937 100644 --- a/shim/stub_test.go +++ b/shim/stub_test.go @@ -12,10 +12,9 @@ import ( "github.com/hyperledger/fabric-protos-go-apiv2/common" "github.com/hyperledger/fabric-protos-go-apiv2/ledger/queryresult" "github.com/hyperledger/fabric-protos-go-apiv2/peer" - "google.golang.org/protobuf/proto" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -258,7 +257,7 @@ func TestChaincodeStubHandlers(t *testing.T) { getMultipleKeysBytes, err := proto.Marshal(gmkResult) assert.NoError(t, err) - var tests = []struct { + tests := []struct { name string resType peer.ChaincodeMessage_Type payload []byte