diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..d82b525 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,31 @@ +name: Build and Test +on: [push, pull_request] +jobs: + build: + name: Go CI + runs-on: ubuntu-latest + strategy: + matrix: + go: [1.14, 1.15] + steps: + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + - name: Check out source + uses: actions/checkout@v2 + - name: Install Linters + run: "curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.31.0" + - name: Build + env: + GO111MODULE: "on" + run: go build ./... + - name: Test + env: + GO111MODULE: "on" + run: | + sh ./goclean.sh + - name: Send btcutil coverage + uses: shogo82148/actions-goveralls@v1 + with: + path-to-profile: profile.cov diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 251caec..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: go -go: - - "1.9.4" - - "1.10" -sudo: false -install: - - go get -d -t -v ./... - - go get -v github.com/alecthomas/gometalinter - - gometalinter --install -script: - - export PATH=$PATH:$HOME/gopath/bin - - ./goclean.sh -after_success: - - go get -v github.com/mattn/goveralls - - goveralls -coverprofile=profile.cov -service=travis-ci diff --git a/README.md b/README.md index 1d76cfb..fffb0f7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ btcutil ======= -[![Build Status](http://img.shields.io/travis/btcsuite/btcutil.svg)](https://travis-ci.org/btcsuite/btcutil) -[![Coverage Status](http://img.shields.io/coveralls/btcsuite/btcutil.svg)](https://coveralls.io/r/btcsuite/btcutil?branch=master) -[![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org) -[![GoDoc](http://img.shields.io/badge/godoc-reference-blue.svg)](http://godoc.org/github.com/btcsuite/btcutil) +[![Build Status](https://github.com/btcsuite/btcutil/workflows/Build%20and%20Test/badge.svg)](https://github.com/btcsuite/btcutil/actions) +[![ISC License](https://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org) +[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/btcsuite/btcutil) Package btcutil provides bitcoin-specific convenience functions and types. A comprehensive suite of tests is provided to ensure proper functionality. See diff --git a/bech32/bech32_test.go b/bech32/bech32_test.go index 3303d98..f28e028 100644 --- a/bech32/bech32_test.go +++ b/bech32/bech32_test.go @@ -21,11 +21,11 @@ func TestBech32(t *testing.T) { {"abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw", true}, {"11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j", true}, {"split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w", true}, - {"split1checkupstagehandshakeupstreamerranterredcaperred2y9e2w", false}, // invalid checksum - {"s lit1checkupstagehandshakeupstreamerranterredcaperredp8hs2p", false}, // invalid character (space) in hrp - {"spl\x7Ft1checkupstagehandshakeupstreamerranterredcaperred2y9e3w", false}, // invalid character (DEL) in hrp - {"split1cheo2y9e2w", false}, // invalid character (o) in data part - {"split1a2y9w", false}, // too short data part + {"split1checkupstagehandshakeupstreamerranterredcaperred2y9e2w", false}, // invalid checksum + {"s lit1checkupstagehandshakeupstreamerranterredcaperredp8hs2p", false}, // invalid character (space) in hrp + {"spl\x7Ft1checkupstagehandshakeupstreamerranterredcaperred2y9e3w", false}, // invalid character (DEL) in hrp + {"split1cheo2y9e2w", false}, // invalid character (o) in data part + {"split1a2y9w", false}, // too short data part {"1checkupstagehandshakeupstreamerranterredcaperred2y9e3w", false}, // empty hrp {"11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqsqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j", false}, // too long } diff --git a/certgen.go b/certgen.go index 26d1629..bbc45a4 100644 --- a/certgen.go +++ b/certgen.go @@ -110,7 +110,7 @@ func NewTLSCertPair(organization string, validUntil time.Time, extraHosts []stri KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign, - IsCA: true, // so can sign self. + IsCA: true, // so can sign self. BasicConstraintsValid: true, DNSNames: dnsNames, diff --git a/go.mod b/go.mod index d455377..089aadc 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.13 require ( github.com/aead/siphash v1.0.1 github.com/btcsuite/btcd v0.20.1-beta - github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495 + github.com/davecgh/go-spew v1.1.0 github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23 golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d ) diff --git a/go.sum b/go.sum index 088c1a3..2678e65 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtE github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495 h1:6IyqGr3fnd0tM3YxipK27TUskaOVUjU2nG45yzwcQKY= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +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/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= @@ -29,15 +31,18 @@ github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44 h1:9lP3x0pW80sDI6t1UMSLA4to18W7R7imwAI/sWS9S8Q= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d h1:2+ZP7EfsZV7Vvmx3TIqSlSzATMkTAKqM14YGFPoSKjI= golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= diff --git a/goclean.sh b/goclean.sh index 4130848..a9fe858 100755 --- a/goclean.sh +++ b/goclean.sh @@ -9,40 +9,38 @@ # 7. race detector (http://blog.golang.org/race-detector) # 8. test coverage (http://blog.golang.org/cover) # -# gometalint (github.com/alecthomas/gometalinter) is used to run each each -# static checker. set -ex # Automatic checks -test -z "$(gometalinter --disable-all \ ---enable=gofmt \ ---enable=goimports \ ---enable=golint \ ---enable=vet \ ---enable=gosimple \ ---enable=unconvert \ ---deadline=120s ./... | grep -v 'ExampleNew' 2>&1 | tee /dev/stderr)" -env GORACE="halt_on_error=1" go test -race ./... +for i in $(find . -name go.mod -type f -print); do + module=$(dirname ${i}) + echo "==> ${module}" -# Run test coverage on each subdirectories and merge the coverage profile. - -echo "mode: count" > profile.cov - -# Standard go tooling behavior is to ignore dirs with leading underscores. -for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -type d); -do -if ls $dir/*.go &> /dev/null; then - go test -covermode=count -coverprofile=$dir/profile.tmp $dir - if [ -f $dir/profile.tmp ]; then - cat $dir/profile.tmp | tail -n +2 >> profile.cov - rm $dir/profile.tmp + MODNAME=$(echo $module | sed -E -e "s/^$ROOTPATHPATTERN//" \ + -e 's,^/,,' -e 's,/v[0-9]+$,,') + if [ -z "$MODNAME" ]; then + MODNAME=. fi -fi + + # run tests + (cd $MODNAME && + echo "mode: atomic" > profile.cov && \ + env GORACE=halt_on_error=1 go test -race -covermode=atomic -coverprofile=profile.tmp ./... && \ + cat profile.tmp | tail -n +2 >> profile.cov && \ + rm profile.tmp && \ + go tool cover -func profile.cov + ) + + # check linters + (cd $MODNAME && \ + go mod download && \ + golangci-lint run --deadline=10m --disable-all \ + --enable=gofmt \ + --enable=goimports \ + --enable=golint \ + --enable=govet \ + --enable=gosimple \ + --enable=unconvert + ) done - -go tool cover -func profile.cov - -# To submit the test coverage result to coveralls.io, -# use goveralls (https://github.com/mattn/goveralls) -# goveralls -coverprofile=profile.cov -service=travis-ci diff --git a/internal_test.go b/internal_test.go index e31324f..7462da6 100644 --- a/internal_test.go +++ b/internal_test.go @@ -85,7 +85,7 @@ func TstAddressPubKey(serializedPubKey []byte, pubKeyFormat PubKeyFormat, pubKey, _ := btcec.ParsePubKey(serializedPubKey, btcec.S256()) return &AddressPubKey{ pubKeyFormat: pubKeyFormat, - pubKey: (*btcec.PublicKey)(pubKey), + pubKey: pubKey, pubKeyHashID: netID, } } diff --git a/psbt/partialsig.go b/psbt/partialsig.go index 7211d25..e11bb80 100644 --- a/psbt/partialsig.go +++ b/psbt/partialsig.go @@ -31,10 +31,7 @@ func (s PartialSigSorter) Less(i, j int) bool { // Bitcoin context (compressed/uncomp. OK). func validatePubkey(pubKey []byte) bool { _, err := btcec.ParsePubKey(pubKey, btcec.S256()) - if err != nil { - return false - } - return true + return err == nil } // validateSignature checks that the passed byte slice is a valid DER-encoded @@ -42,10 +39,7 @@ func validatePubkey(pubKey []byte) bool { // validate the signature against any message or public key. func validateSignature(sig []byte) bool { _, err := btcec.ParseDERSignature(sig, btcec.S256()) - if err != nil { - return false - } - return true + return err == nil } // checkValid checks that both the pbukey and sig are valid. See the methods diff --git a/psbt/utils.go b/psbt/utils.go index d372e49..c002b57 100644 --- a/psbt/utils.go +++ b/psbt/utils.go @@ -215,7 +215,7 @@ func serializeKVPairWithType(w io.Writer, kt uint8, keydata []byte, } // The final key to be written is: {type} || {keyData} - serializedKey := append([]byte{byte(kt)}, keydata...) + serializedKey := append([]byte{kt}, keydata...) return serializeKVpair(w, serializedKey, value) }