From 1d133626ba1d38ac3532d9cb09add1c91cb2e04a Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 26 Jun 2019 19:27:56 -0500 Subject: [PATCH 1/3] chaincfg: Run gofmt -s. --- chaincfg/mainnetparams.go | 2 +- chaincfg/regnetparams.go | 2 +- chaincfg/simnetparams.go | 2 +- chaincfg/testnetparams.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chaincfg/mainnetparams.go b/chaincfg/mainnetparams.go index 221416338f..cb992e87ab 100644 --- a/chaincfg/mainnetparams.go +++ b/chaincfg/mainnetparams.go @@ -45,7 +45,7 @@ func MainNetParams() *Params { Nonce: 0x00000000, StakeVersion: 0, }, - Transactions: []*wire.MsgTx{&wire.MsgTx{ + Transactions: []*wire.MsgTx{{ SerType: wire.TxSerializeFull, Version: 1, TxIn: []*wire.TxIn{{ diff --git a/chaincfg/regnetparams.go b/chaincfg/regnetparams.go index 96565a0f8a..3bab25e31f 100644 --- a/chaincfg/regnetparams.go +++ b/chaincfg/regnetparams.go @@ -49,7 +49,7 @@ func RegNetParams() *Params { StakeVersion: 0, Height: 0, }, - Transactions: []*wire.MsgTx{&wire.MsgTx{ + Transactions: []*wire.MsgTx{{ SerType: wire.TxSerializeFull, Version: 1, TxIn: []*wire.TxIn{{ diff --git a/chaincfg/simnetparams.go b/chaincfg/simnetparams.go index c4ebfbf33e..a9f23b5de7 100644 --- a/chaincfg/simnetparams.go +++ b/chaincfg/simnetparams.go @@ -50,7 +50,7 @@ func SimNetParams() *Params { StakeVersion: 0, Height: 0, }, - Transactions: []*wire.MsgTx{&wire.MsgTx{ + Transactions: []*wire.MsgTx{{ SerType: wire.TxSerializeFull, Version: 1, TxIn: []*wire.TxIn{{ diff --git a/chaincfg/testnetparams.go b/chaincfg/testnetparams.go index e7d3bb0c50..a5353a36d4 100644 --- a/chaincfg/testnetparams.go +++ b/chaincfg/testnetparams.go @@ -34,7 +34,7 @@ func TestNet3Params() *Params { Nonce: 0x18aea41a, StakeVersion: 6, }, - Transactions: []*wire.MsgTx{&wire.MsgTx{ + Transactions: []*wire.MsgTx{{ SerType: wire.TxSerializeFull, Version: 1, TxIn: []*wire.TxIn{{ From 9df07027aef23bf33b65b716be3a08362ba424eb Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 26 Jun 2019 19:29:41 -0500 Subject: [PATCH 2/3] TravisCI: Test and lint latest version modules. The current approach of the CI tests of specifying the path to the directory that contains the module only tests version 1 of the module despite there being newer version available. The same is true for the lints. This resolves the test portion by obtaining a list of all modules required by the root go.mod file and providing the entire module path, which includes the version, to the go test command instead of the directory. Unfortunately, the linter does not recognize full module paths, however it will lint the latest module version from within the module directory itself, so this resolves the linting case by stripping the full module path and version down to the directory and changing into the directory to perform the lint checks. --- run_tests.sh | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index 3419c27634..79852e538f 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -41,23 +41,28 @@ testrepo () { cp "$REPO" "$GOPATH/bin/" # run tests on all modules - ROOTPATH=$($GO list -m -f {{.Dir}} 2>/dev/null) + ROOTPATH=$($GO list -m) ROOTPATHPATTERN=$(echo $ROOTPATH | sed 's/\\/\\\\/g' | sed 's/\//\\\//g') - MODPATHS=$($GO list -m -f {{.Dir}} all 2>/dev/null | grep "^$ROOTPATHPATTERN"\ - | sed -e "s/^$ROOTPATHPATTERN//" -e 's/^\\//' -e 's/^\///') - MODPATHS=". $MODPATHS" + MODPATHS=$($GO list -m all | grep "^$ROOTPATHPATTERN" | cut -d' ' -f1) for module in $MODPATHS; do echo "==> ${module}" - env CC=gcc $GO test -short -tags rpctest ./${module}/... + env CC=gcc $GO test -short -tags rpctest ${module}/... # check linters - golangci-lint run --build-tags rpctest --disable-all --deadline=10m \ - --enable=gofmt \ - --enable=gosimple \ - --enable=unconvert \ - --enable=ineffassign \ - --enable=govet \ - --enable=misspell ./${module}/... + MODNAME=$(echo $module | sed -e "s/^$ROOTPATHPATTERN//" \ + -e 's/^\///' -e 's/\/v[0-9]\+$//') + if [ -z "$MODNAME" ]; then + MODNAME=. + fi + (cd $MODNAME && \ + golangci-lint run --build-tags=rpctest --disable-all --deadline=10m \ + --enable=gofmt \ + --enable=gosimple \ + --enable=unconvert \ + --enable=ineffassign \ + --enable=govet \ + --enable=misspell \ + ) done echo "------------------------------------------" From 3203401fc5187de903a34e2b6314d95dc4a66e17 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 26 Jun 2019 19:47:17 -0500 Subject: [PATCH 3/3] main: Add requires for new version modules. This adds requires for newer module versions that are not yet fully integrated to the main go.mod file and a new file with a build tag to ignore it which imports those modules to prevent go mod tidy from removing the otherwise unused entries. --- go.mod | 5 ++++- go.sum | 2 -- require.go | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 require.go diff --git a/go.mod b/go.mod index 09e407905b..cd61c43876 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/decred/dcrd/chaincfg v1.5.1 github.com/decred/dcrd/chaincfg/chainhash v1.0.1 github.com/decred/dcrd/connmgr v1.0.2 - github.com/decred/dcrd/database v1.0.3 + github.com/decred/dcrd/database v1.1.0 github.com/decred/dcrd/dcrec v1.0.0 github.com/decred/dcrd/dcrec/secp256k1 v1.0.2 github.com/decred/dcrd/dcrjson/v2 v2.0.0 @@ -43,10 +43,12 @@ replace ( github.com/decred/dcrd/blockchain/stake => ./blockchain/stake github.com/decred/dcrd/certgen => ./certgen github.com/decred/dcrd/chaincfg/chainhash => ./chaincfg/chainhash + github.com/decred/dcrd/chaincfg/v2 => ./chaincfg github.com/decred/dcrd/connmgr => ./connmgr github.com/decred/dcrd/database => ./database github.com/decred/dcrd/dcrec => ./dcrec github.com/decred/dcrd/dcrjson/v2 => ./dcrjson + github.com/decred/dcrd/dcrutil/v2 => ./dcrutil github.com/decred/dcrd/fees => ./fees github.com/decred/dcrd/gcs => ./gcs github.com/decred/dcrd/hdkeychain/v2 => ./hdkeychain @@ -56,5 +58,6 @@ replace ( github.com/decred/dcrd/mining => ./mining github.com/decred/dcrd/peer => ./peer github.com/decred/dcrd/rpcclient/v2 => ./rpcclient + github.com/decred/dcrd/txscript/v2 => ./txscript github.com/decred/dcrd/wire => ./wire ) diff --git a/go.sum b/go.sum index 74bc69be7a..f0620f57ca 100644 --- a/go.sum +++ b/go.sum @@ -23,8 +23,6 @@ github.com/decred/dcrd/chaincfg v1.4.0 h1:dIJhXQooiVW5AVZ0c4brylsiwkc8KSawpZ3NPq github.com/decred/dcrd/chaincfg v1.4.0/go.mod h1:ypuM30F+XgZmZTFfAkWHWd0lwwkWWAOAQYNRkRDlYLc= github.com/decred/dcrd/chaincfg v1.5.1 h1:u1Xbq0VTnAXIHW5ECqrWe0VYSgf5vWHqpSiwoLBzxAQ= github.com/decred/dcrd/chaincfg v1.5.1/go.mod h1:FukMzTjkwzjPU+hK7CqDMQe3NMbSZAYU5PAcsx1wlv0= -github.com/decred/dcrd/chaincfg/v2 v2.0.2 h1:VeGY52lHuYT01tIGbvYj+OO0GaGxGaJmnh+4vGca1+U= -github.com/decred/dcrd/chaincfg/v2 v2.0.2/go.mod h1:hpKvhLCDAD/xDZ3V1Pqpv9fIKVYYi11DyxETguazyvg= github.com/decred/dcrd/dcrec/edwards v0.0.0-20180721005212-59fe2b293f69/go.mod h1:+ehP0Hk/mesyZXttxCtBbhPX23BMpZJ1pcVBqUfbmvU= github.com/decred/dcrd/dcrec/edwards v0.0.0-20181208004914-a0816cf4301f/go.mod h1:+ehP0Hk/mesyZXttxCtBbhPX23BMpZJ1pcVBqUfbmvU= github.com/decred/dcrd/dcrec/edwards v0.0.0-20190130161649-59ed4247a1d5/go.mod h1:+ehP0Hk/mesyZXttxCtBbhPX23BMpZJ1pcVBqUfbmvU= diff --git a/require.go b/require.go new file mode 100644 index 0000000000..e25a7a998b --- /dev/null +++ b/require.go @@ -0,0 +1,20 @@ +// Copyright (c) 2019 The Decred developers +// Use of this source code is governed by an ISC +// license that can be found in the LICENSE file. + +// +build ignore + +// This file exists to prevent go mod tidy from removing requires for newer +// module versions that are not yet fully integrated and to allow them to be +// automatically discovered by the testing infrastructure. +// +// It is excluded from the build to avoid including unused modules in the final +// binary. + +package main + +import ( + _ "github.com/decred/dcrd/chaincfg/v2" + _ "github.com/decred/dcrd/dcrutil/v2" + _ "github.com/decred/dcrd/txscript/v2" +)