From 47d58e5bfcd80f91c6e5701d36fc29eee7b38688 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 6 Mar 2019 12:54:01 +0100 Subject: [PATCH 01/11] migrated from dep to Go modules - remove dep artifacts - remove traces of dep from make file: go build will handle those for us - update circelci config to go1.12 --- .circleci/config.yml | 4 ++-- Gopkg.lock | 47 -------------------------------------------- Gopkg.toml | 42 --------------------------------------- Makefile | 12 +++-------- go.mod | 12 +++++++++++ go.sum | 12 +++++++++++ 6 files changed, 29 insertions(+), 100 deletions(-) delete mode 100644 Gopkg.lock delete mode 100644 Gopkg.toml create mode 100644 go.mod create mode 100644 go.sum diff --git a/.circleci/config.yml b/.circleci/config.yml index 92c1a4ca..7367cc19 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: circleci/golang:1.10.3 + - image: circleci/golang:1.12.0 environment: GOBIN: /tmp/workspace/bin @@ -21,7 +21,7 @@ jobs: export PATH="$GOBIN:$PATH" go env go version - make get_tools && make get_vendor_deps && make test + make get_tools && make && make test - save_cache: key: v1-dep-{{ .Branch }} paths: diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index 4589d933..00000000 --- a/Gopkg.lock +++ /dev/null @@ -1,47 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - name = "github.com/davecgh/go-spew" - packages = ["spew"] - revision = "346938d642f2ec3594ed81d874461961cd0faa76" - version = "v1.1.0" - -[[projects]] - name = "github.com/golang/protobuf" - packages = [ - "proto", - "proto/proto3_proto", - "proto/test_proto", - "ptypes/any" - ] - revision = "b4deda0973fb4c70b50d226b1af49f3da59f5265" - version = "v1.1.0" - -[[projects]] - branch = "master" - name = "github.com/google/gofuzz" - packages = ["."] - revision = "24818f796faf91cd76ec7bddd72458fbced7a6c1" - -[[projects]] - name = "github.com/pmezard/go-difflib" - packages = ["difflib"] - revision = "792786c7400a136282c1664665ae0a8db921c6c2" - version = "v1.0.0" - -[[projects]] - name = "github.com/stretchr/testify" - packages = [ - "assert", - "require" - ] - revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686" - version = "v1.2.2" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "8ca44333ad8ca8f143fc1513ae309425e548d9deb7c567eb18d197a4fef9a250" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index cc862455..00000000 --- a/Gopkg.toml +++ /dev/null @@ -1,42 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" -# -# [prune] -# non-go = false -# go-tests = true -# unused-packages = true - - -[[constraint]] - name = "github.com/davecgh/go-spew" - version = "1.1.0" - -[[constraint]] - branch = "master" - name = "github.com/google/gofuzz" - -[[constraint]] - name = "github.com/stretchr/testify" - version = "1.2.1" - -[prune] - go-tests = true - unused-packages = true diff --git a/Makefile b/Makefile index c322d019..392b395e 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,8 @@ GOTOOLS = \ - github.com/golang/dep/cmd/dep \ gopkg.in/alecthomas/gometalinter.v2 -GOTOOLS_CHECK = dep gometalinter.v2 +GOTOOLS_CHECK = gometalinter.v2 -all: check_tools get_vendor_deps test metalinter +all: check_tools test metalinter ######################################## ### Build @@ -32,11 +31,6 @@ update_tools: @echo "--> Updating tools" @go get -u $(GOTOOLS) -get_vendor_deps: - @rm -rf vendor/ - @echo "--> Running dep ensure" - @dep ensure - ######################################## ### Testing @@ -108,4 +102,4 @@ test_golang1.10rc: # To avoid unintended conflicts with file names, always add to .PHONY # unless there is a reason not to. # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html -.PHONY: build install check_tools get_tools update_tools get_vendor_deps test fmt metalinter metalinter_all +.PHONY: build install check_tools get_tools update_tools test fmt metalinter metalinter_all diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..410e80ee --- /dev/null +++ b/go.mod @@ -0,0 +1,12 @@ +module github.com/tendermint/go-amino + +go 1.12 + +require ( + github.com/davecgh/go-spew v1.1.0 + github.com/golang/protobuf v1.1.0 + github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/testify v1.2.2 + golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..c7a1307c --- /dev/null +++ b/go.sum @@ -0,0 +1,12 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/protobuf v1.1.0 h1:0iH4Ffd/meGoXqF2lSAhZHt8X+cPgkfn/cb6Cce5Vpc= +github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck= +github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= From 859d01d9af2c43472a8be903a950558bd38ea2e8 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 6 Mar 2019 13:21:36 +0100 Subject: [PATCH 02/11] try to fix circleci --- .circleci/config.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7367cc19..a710b906 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,18 +3,12 @@ jobs: build: docker: - image: circleci/golang:1.12.0 - environment: - GOBIN: /tmp/workspace/bin - - working_directory: /go/src/github.com/tendermint/go-amino steps: - - run: mkdir -p /tmp/workspace/bin - - run: mkdir -p /tmp/workspace/profiles - checkout - restore_cache: keys: - - v1-dep-{{ .Branch }} + - go-mod-v1-{{ checksum "go.sum" }} - run: name: test command: | @@ -23,6 +17,6 @@ jobs: go version make get_tools && make && make test - save_cache: - key: v1-dep-{{ .Branch }} + key: go-mod-v1-{{ checksum "go.sum" }} paths: - - /go/pkg + - "/go/pkg/mod" From c16f67e9a4a3428d9075449c01039bf0cd87200d Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 6 Mar 2019 13:41:44 +0100 Subject: [PATCH 03/11] switch to golangci-linter instead of metalinter - do we need to add all those deps to go.sum, too? --- .golangci.yml | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 51 +++++++------------------------------------- 2 files changed, 67 insertions(+), 43 deletions(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..45cabe20 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,59 @@ +run: + deadline: 1m + +linters: + enable-all: true + disable: + - gocyclo + - golint + - maligned + - errcheck + - staticcheck + - dupl + - ineffassign + - interfacer + - unconvert + - goconst + - unparam + - nakedret + - lll + - gochecknoglobals + - gocritic + - gochecknoinits + - scopelint + - stylecheck + +# linters-settings: +# govet: +# check-shadowing: true +# golint: +# min-confidence: 0 +# gocyclo: +# min-complexity: 10 +# maligned: +# suggest-new: true +# dupl: +# threshold: 100 +# goconst: +# min-len: 2 +# min-occurrences: 2 +# depguard: +# list-type: blacklist +# packages: +# # logging is allowed only by logutils.Log, logrus +# # is allowed to use only in logutils package +# - github.com/sirupsen/logrus +# misspell: +# locale: US +# lll: +# line-length: 140 +# goimports: +# local-prefixes: github.com/golangci/golangci-lint +# gocritic: +# enabled-tags: +# - performance +# - style +# - experimental +# disabled-checks: +# - wrapperFunc +# - commentFormatting # https://github.com/go-critic/go-critic/issues/755 diff --git a/Makefile b/Makefile index 392b395e..ebae476b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ GOTOOLS = \ - gopkg.in/alecthomas/gometalinter.v2 -GOTOOLS_CHECK = gometalinter.v2 + github.com/golangci/golangci-lint/cmd/golangci-lint +GOTOOLS_CHECK = golangci-lint all: check_tools test metalinter @@ -25,7 +25,6 @@ check_tools: get_tools: @echo "--> Installing tools" go get -u -v $(GOTOOLS) - @gometalinter.v2 --install update_tools: @echo "--> Updating tools" @@ -36,7 +35,7 @@ update_tools: ### Testing test: - go test $(shell go list ./... | grep -v vendor) + go test -v $(shell go list ./... | grep -v vendor) gofuzz_binary: rm -rf tests/fuzz/binary/corpus/ @@ -60,46 +59,12 @@ gofuzz_json: fmt: @go fmt ./... -metalinter: - @echo "==> Running linter" - gometalinter.v2 --vendor --deadline=600s --disable-all \ - --enable=deadcode \ - --enable=goconst \ - --enable=goimports \ - --enable=gosimple \ - --enable=ineffassign \ - --enable=megacheck \ - --enable=misspell \ - --enable=staticcheck \ - --enable=safesql \ - --enable=structcheck \ - --enable=unconvert \ - --enable=unused \ - --enable=varcheck \ - --enable=vetshadow \ - ./... - - #--enable=maligned \ - #--enable=gas \ - #--enable=aligncheck \ - #--enable=dupl \ - #--enable=errcheck \ - #--enable=gocyclo \ - #--enable=golint \ <== comments on anything exported - #--enable=gotype \ - #--enable=interfacer \ - #--enable=unparam \ - #--enable=vet \ - -metalinter_all: - protoc $(INCLUDE) --lint_out=. types/*.proto - gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./... - - -test_golang1.10rc: - docker run -it -v "$(CURDIR):/go/src/github.com/tendermint/go-amino" -w "/go/src/github.com/tendermint/go-amino" golang:1.10-rc /bin/bash -ci "make get_tools all" +# look into .golangci.yml for enabling / disabling linters +lint: + @echo "--> Running linter" + @golangci-lint run # To avoid unintended conflicts with file names, always add to .PHONY # unless there is a reason not to. # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html -.PHONY: build install check_tools get_tools update_tools test fmt metalinter metalinter_all +.PHONY: build install check_tools get_tools update_tools test From cdab3d9486452213dafe1c218397609b1be976fa Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 6 Mar 2019 14:06:48 +0100 Subject: [PATCH 04/11] downgrade github.com/stretchr/testify to v1.2.0 - otherwise tests fail (bug in testify) -> deal with this in a separate PR --- go.mod | 6 +++--- go.sum | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 410e80ee..0525e69f 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/tendermint/go-amino go 1.12 require ( - github.com/davecgh/go-spew v1.1.0 - github.com/golang/protobuf v1.1.0 + github.com/davecgh/go-spew v1.1.1 + github.com/golang/protobuf v1.3.0 github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.2.2 + github.com/stretchr/testify v1.2.0 golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 // indirect ) diff --git a/go.sum b/go.sum index c7a1307c..43823a04 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,20 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/golang/protobuf v1.1.0 h1:0iH4Ffd/meGoXqF2lSAhZHt8X+cPgkfn/cb6Cce5Vpc= -github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk= +github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.0 h1:LThGCOvhuJic9Gyd1VBCkhyUXmO8vKaBFvBsJ2k03rg= +github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= From 2f188fe5dfff4dd3755c574f7bb270760686b4a8 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 6 Mar 2019 14:18:20 +0100 Subject: [PATCH 05/11] use exact same versions as in dep --- go.mod | 6 +++--- go.sum | 16 ++++------------ json_test.go | 3 +++ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 0525e69f..410e80ee 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/tendermint/go-amino go 1.12 require ( - github.com/davecgh/go-spew v1.1.1 - github.com/golang/protobuf v1.3.0 + github.com/davecgh/go-spew v1.1.0 + github.com/golang/protobuf v1.1.0 github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.2.0 + github.com/stretchr/testify v1.2.2 golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 // indirect ) diff --git a/go.sum b/go.sum index 43823a04..c7a1307c 100644 --- a/go.sum +++ b/go.sum @@ -1,20 +1,12 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk= -github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= +github.com/golang/protobuf v1.1.0 h1:0iH4Ffd/meGoXqF2lSAhZHt8X+cPgkfn/cb6Cce5Vpc= +github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.0 h1:LThGCOvhuJic9Gyd1VBCkhyUXmO8vKaBFvBsJ2k03rg= -github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= diff --git a/json_test.go b/json_test.go index 90bc11f3..233373fc 100644 --- a/json_test.go +++ b/json_test.go @@ -214,6 +214,9 @@ func TestUnmarshalFunc(t *testing.T) { // Binary doesn't support decoding to a func... assert.Panics(t, func() { err := cdc.UnmarshalBinaryLengthPrefixed(binBytes, &obj) + t.Log(err) + // TODO: this doesn't panic; update testify and other deps and + // fix test(s) assert.Fail(t, "should have paniced but got err: %v", err) }) assert.Panics(t, func() { From 9dc895ff2f308e5dfd207b03dac69ac83229b0ee Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 6 Mar 2019 15:56:17 +0100 Subject: [PATCH 06/11] Fix JSON tests #256 - some go vet lints (redundant type) --- go.mod | 7 +++---- go.sum | 14 ++++++++++---- json_test.go | 53 ++++++++++++++++++++++++++++------------------------ 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/go.mod b/go.mod index 410e80ee..299e8eec 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,9 @@ module github.com/tendermint/go-amino go 1.12 require ( - github.com/davecgh/go-spew v1.1.0 - github.com/golang/protobuf v1.1.0 + github.com/davecgh/go-spew v1.1.1 + github.com/golang/protobuf v1.3.0 github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.2.2 + github.com/stretchr/testify v1.3.0 golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 // indirect ) diff --git a/go.sum b/go.sum index c7a1307c..93686c0d 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,18 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/golang/protobuf v1.1.0 h1:0iH4Ffd/meGoXqF2lSAhZHt8X+cPgkfn/cb6Cce5Vpc= -github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk= +github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= diff --git a/json_test.go b/json_test.go index 233373fc..e4cdae28 100644 --- a/json_test.go +++ b/json_test.go @@ -173,32 +173,33 @@ type innerFP struct { func TestUnmarshalMap(t *testing.T) { binBytes := []byte(`dontcare`) - jsonBytes := []byte(`{"2": 2}`) obj := new(map[string]int) cdc := amino.NewCodec() // Binary doesn't support decoding to a map... + // TODO: move out binary tests from json_test.go ... assert.Panics(t, func() { - err := cdc.UnmarshalBinaryLengthPrefixed(binBytes, &obj) + err := cdc.UnmarshalBinaryBare(binBytes, &obj) assert.Fail(t, "should have paniced but got err: %v", err) }) assert.Panics(t, func() { - err := cdc.UnmarshalBinaryLengthPrefixed(binBytes, obj) + err := cdc.UnmarshalBinaryBare(binBytes, obj) assert.Fail(t, "should have paniced but got err: %v", err) }) // ... nor encoding it. assert.Panics(t, func() { - bz, err := cdc.MarshalBinaryLengthPrefixed(obj) + bz, err := cdc.MarshalBinaryBare(obj) assert.Fail(t, "should have paniced but got bz: %X err: %v", bz, err) }) - // JSON doesn't support decoding to a map... - assert.Panics(t, func() { - err := cdc.UnmarshalJSON(jsonBytes, &obj) - assert.Fail(t, "should have paniced but got err: %v", err) - }) - assert.Panics(t, func() { - err := cdc.UnmarshalJSON(jsonBytes, obj) - assert.Fail(t, "should have paniced but got err: %v", err) - }) + + invalidJSONMapBytes := []byte(`{"some_key": 2}`) + // we expect quoted values for javascript / JSON numbers: + err := cdc.UnmarshalJSON(invalidJSONMapBytes, &obj) + assert.Error(t, err) + + validJSONMapBytes := []byte(`{"some_key": "2"}`) + err = cdc.UnmarshalJSON(validJSONMapBytes, obj) + assert.NoError(t, err) + // ... nor encoding it. assert.Panics(t, func() { bz, err := cdc.MarshalJSON(obj) @@ -212,15 +213,18 @@ func TestUnmarshalFunc(t *testing.T) { obj := func() {} cdc := amino.NewCodec() // Binary doesn't support decoding to a func... + + err := cdc.UnmarshalBinaryLengthPrefixed(binBytes, &obj) + // on length prefixed we return an error: + assert.Error(t, err) + assert.Panics(t, func() { - err := cdc.UnmarshalBinaryLengthPrefixed(binBytes, &obj) - t.Log(err) - // TODO: this doesn't panic; update testify and other deps and - // fix test(s) + err := cdc.UnmarshalBinaryBare(binBytes, &obj) + // panics with "unknown field type Func" assert.Fail(t, "should have paniced but got err: %v", err) }) assert.Panics(t, func() { - err := cdc.UnmarshalBinaryLengthPrefixed(binBytes, obj) + err := cdc.UnmarshalBinaryBare(binBytes, obj) assert.Fail(t, "should have paniced but got err: %v", err) }) // ... nor encoding it. @@ -233,10 +237,11 @@ func TestUnmarshalFunc(t *testing.T) { err := cdc.UnmarshalJSON(jsonBytes, &obj) assert.Fail(t, "should have paniced but got err: %v", err) }) - assert.Panics(t, func() { - err := cdc.UnmarshalJSON(jsonBytes, obj) - assert.Fail(t, "should have paniced but got err: %v", err) - }) + + err = cdc.UnmarshalJSON(jsonBytes, obj) + // UnmarshalJSON expects a pointer + assert.Error(t, err) + // ... nor encoding it. assert.Panics(t, func() { bz, err := cdc.MarshalJSON(obj) @@ -563,7 +568,7 @@ func TestMarshalJSONMap(t *testing.T) { Map2nil: (map[string]SimpleStruct)(nil), Map2empty: map[string]SimpleStruct{}, - Map3: map[string]*SimpleStruct{"foo": &SimpleStruct{Foo: 1, Bar: []byte("bar")}}, + Map3: map[string]*SimpleStruct{"foo": {Foo: 1, Bar: []byte("bar")}}, Map3nil: (map[string]*SimpleStruct)(nil), Map3empty: map[string]*SimpleStruct{}, @@ -584,7 +589,7 @@ func TestMarshalJSONMap(t *testing.T) { Map2nil: map[string]SimpleStruct{}, Map2empty: map[string]SimpleStruct{}, - Map3: map[string]*SimpleStruct{"foo": &SimpleStruct{Foo: 1, Bar: []byte("bar")}}, + Map3: map[string]*SimpleStruct{"foo": {Foo: 1, Bar: []byte("bar")}}, Map3nil: map[string]*SimpleStruct{}, Map3empty: map[string]*SimpleStruct{}, From 6884c398d35009b948174280de0e8b2d672383c2 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 6 Mar 2019 16:01:23 +0100 Subject: [PATCH 07/11] remove traces of metalinter --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ebae476b..3e1b99c8 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ GOTOOLS = \ github.com/golangci/golangci-lint/cmd/golangci-lint GOTOOLS_CHECK = golangci-lint -all: check_tools test metalinter +all: check_tools test ######################################## ### Build From 1c31ba6437318985fcb5d182cbebcaae9ca7041e Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 6 Mar 2019 16:07:50 +0100 Subject: [PATCH 08/11] add back updated versions of Gopkg.toml / Gopkg.lock (matching the updated versions in modules) --- Gopkg.lock | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Gopkg.toml | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 Gopkg.lock create mode 100644 Gopkg.toml diff --git a/Gopkg.lock b/Gopkg.lock new file mode 100644 index 00000000..ef498e39 --- /dev/null +++ b/Gopkg.lock @@ -0,0 +1,66 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" + name = "github.com/davecgh/go-spew" + packages = ["spew"] + pruneopts = "UT" + revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" + version = "v1.1.1" + +[[projects]] + digest = "1:239c4c7fd2159585454003d9be7207167970194216193a8a210b8d29576f19c9" + name = "github.com/golang/protobuf" + packages = [ + "proto", + "ptypes", + "ptypes/any", + "ptypes/duration", + "ptypes/timestamp", + ] + pruneopts = "UT" + revision = "c823c79ea1570fb5ff454033735a8e68575d1d0f" + version = "v1.3.0" + +[[projects]] + branch = "master" + digest = "1:3ee90c0d94da31b442dde97c99635aaafec68d0b8a3c12ee2075c6bdabeec6bb" + name = "github.com/google/gofuzz" + packages = ["."] + pruneopts = "UT" + revision = "24818f796faf91cd76ec7bddd72458fbced7a6c1" + +[[projects]] + digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" + name = "github.com/pmezard/go-difflib" + packages = ["difflib"] + pruneopts = "UT" + revision = "792786c7400a136282c1664665ae0a8db921c6c2" + version = "v1.0.0" + +[[projects]] + digest = "1:5da8ce674952566deae4dbc23d07c85caafc6cfa815b0b3e03e41979cedb8750" + name = "github.com/stretchr/testify" + packages = [ + "assert", + "require", + ] + pruneopts = "UT" + revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053" + version = "v1.3.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = [ + "github.com/davecgh/go-spew/spew", + "github.com/golang/protobuf/proto", + "github.com/golang/protobuf/ptypes", + "github.com/golang/protobuf/ptypes/timestamp", + "github.com/google/gofuzz", + "github.com/stretchr/testify/assert", + "github.com/stretchr/testify/require", + ] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 00000000..7d98ffaf --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,42 @@ +# Gopkg.toml example +# +# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" +# +# [prune] +# non-go = false +# go-tests = true +# unused-packages = true + + +[[constraint]] + name = "github.com/davecgh/go-spew" + version = "1.1.1" + +[[constraint]] + branch = "master" + name = "github.com/google/gofuzz" + +[[constraint]] + name = "github.com/stretchr/testify" + version = "1.3.0" + +[prune] + go-tests = true + unused-packages = true From a27ab2be004f227ee0b516a7d2742b23794c07f8 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Wed, 6 Mar 2019 16:16:45 +0100 Subject: [PATCH 09/11] re-enable linter, disable a few which currently won't pass (will be addressed in followup PR) --- .golangci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 45cabe20..17ac61a8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,6 +6,13 @@ linters: disable: - gocyclo - golint + - gosimple + - goimports + - gofmt + - unused + - govet + - deadcode + - structcheck - maligned - errcheck - staticcheck From 8b5eeb880c6bb92e02c551055b8cebf10777d75c Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Thu, 7 Mar 2019 17:44:46 +0100 Subject: [PATCH 10/11] gofmt -s -w and re-enable gofmt (does more than go fmt) --- .golangci.yml | 1 - Makefile | 6 +++--- binary_test.go | 4 ++-- reflect.go | 2 +- tests/fuzz/binary/init-corpus/main.go | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 17ac61a8..80bf5625 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,7 +8,6 @@ linters: - golint - gosimple - goimports - - gofmt - unused - govet - deadcode diff --git a/Makefile b/Makefile index 3e1b99c8..46d7f4d9 100644 --- a/Makefile +++ b/Makefile @@ -24,11 +24,11 @@ check_tools: get_tools: @echo "--> Installing tools" - go get -u -v $(GOTOOLS) + go get -v $(GOTOOLS) update_tools: @echo "--> Updating tools" - @go get -u $(GOTOOLS) + @go get -u -v $(GOTOOLS) ######################################## @@ -67,4 +67,4 @@ lint: # To avoid unintended conflicts with file names, always add to .PHONY # unless there is a reason not to. # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html -.PHONY: build install check_tools get_tools update_tools test +.PHONY: build install check_tools get_tools fmt lint test diff --git a/binary_test.go b/binary_test.go index 077b96e6..2dfee79f 100644 --- a/binary_test.go +++ b/binary_test.go @@ -204,7 +204,7 @@ func TestStructPointerSlice1(t *testing.T) { var f3 = Foo{ A: "k", B: 2, - C: []*Foo{&Foo{}, &Foo{}, &Foo{}}, + C: []*Foo{{}, {}, {}}, D: "j", } bz2, err := cdc.MarshalBinaryLengthPrefixed(f3) @@ -232,7 +232,7 @@ func TestStructPointerSlice2(t *testing.T) { bz, err := cdc.MarshalBinaryLengthPrefixed(f) assert.Error(t, err, "nil elements of a slice/array not supported when empty_elements field tag set.") - f.C = []*Foo{&Foo{}, &Foo{}, &Foo{}} + f.C = []*Foo{{}, {}, {}} bz, err = cdc.MarshalBinaryLengthPrefixed(f) assert.NoError(t, err) diff --git a/reflect.go b/reflect.go index bbf35ed6..97cfeac0 100644 --- a/reflect.go +++ b/reflect.go @@ -132,7 +132,7 @@ func defaultValue(rt reflect.Type) (rv reflect.Value) { switch rt.Kind() { case reflect.Ptr: // Dereference all the way and see if it's a time type. - rt_:= rt.Elem() + rt_ := rt.Elem() for rt_.Kind() == reflect.Ptr { rt_ = rt_.Elem() } diff --git a/tests/fuzz/binary/init-corpus/main.go b/tests/fuzz/binary/init-corpus/main.go index 95dc4d29..1fba7268 100644 --- a/tests/fuzz/binary/init-corpus/main.go +++ b/tests/fuzz/binary/init-corpus/main.go @@ -58,7 +58,7 @@ func main() { UvarintAr: [4]uint64{0x99808080FFFFFF77, 0xFF0202FFFFFFFF77, 0xAE21FF0051F23F77, 0x1045880011AABBCC}, UintAr: [4]uint{0x80808080, 0x110202FF, 0xAE21FF00, 0x10458800}, StringAr: [4]string{"Tendermint", "Fuzzing", "Blue", "410DDC670CF9BFD7"}, - TimeAr: [4]time.Time{time.Time{}, time.Time{}.Add(1000 * hour * 24), time.Time{}.Add(20 * time.Minute)}, + TimeAr: [4]time.Time{{}, time.Time{}.Add(1000 * hour * 24), time.Time{}.Add(20 * time.Minute)}, } ss := tests.SlicesStruct{ @@ -67,7 +67,7 @@ func main() { Int32Sl: []int32{0x6FFFFFFF, 0x5FFFFFFF, 0x7FFFFFFF, 0x7F000000}, Int64Sl: []int64{0x6FFFFFFFFFFFF, 0x5FFFFFFFFFFFF, 0x7FFFFFFFFFFFF, 0x80808000FFFFF}, VarintSl: []int64{0x5FFFFFFFFFFFF, 0x7FFFFFFFFFFFF, 0x6FFFFFFFFFFFF, 0x80808000FFFFF}, - IntSl: []int{0x6FFFFFFF, 0x7FFFFFFF, math.MaxInt32, 0x5FFFFFFF}, + IntSl: []int{0x6FFFFFFF, 0x7FFFFFFF, math.MaxInt32, 0x5FFFFFFF}, ByteSl: []byte{0xAD, 0xBE, 0xDE, 0xEF}, Uint8Sl: []uint8{0xFF, 0x00, 0x88, 0xFF}, Uint16Sl: []uint16{0xFFFF, 0xFFFF, 0xFF00, 0x8800}, From a6b4eb355c0b783af2c221226b4671b9a8052489 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Thu, 7 Mar 2019 17:45:22 +0100 Subject: [PATCH 11/11] remove verbose flag --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 46d7f4d9..04ecb907 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ update_tools: ### Testing test: - go test -v $(shell go list ./... | grep -v vendor) + go test $(shell go list ./... | grep -v vendor) gofuzz_binary: rm -rf tests/fuzz/binary/corpus/