Merge pull request #206 from guggero/makefile

ci: add Makefile, use golangci-lint, parallelize CI actions
This commit is contained in:
Olaoluwa Osuntokun 2021-11-29 10:29:20 -08:00 committed by GitHub
commit 9c4bbabe7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 268 additions and 172 deletions

View file

@ -1,31 +1,64 @@
name: Build and Test name: Build and Test
on: [push, pull_request] on: [push, pull_request]
env:
# go needs absolute directories, using the $HOME variable doesn't work here.
GOCACHE: /home/runner/work/go/pkg/build
GOPATH: /home/runner/work/go
GO_VERSION: 1.16.8
jobs: jobs:
build: build:
name: Go CI name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
matrix:
go: [1.14, 1.15]
steps: steps:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: ${{ matrix.go }} go-version: ${{ env.GO_VERSION }}
- name: Check out source - name: Check out source
uses: actions/checkout@v2 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 - name: Build
env: run: make build
GO111MODULE: "on"
run: go build ./... test-cover:
name: Unit coverage
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- name: Check out source
uses: actions/checkout@v2
- name: Test - name: Test
env: run: make unit-cover
GO111MODULE: "on"
run: |
sh ./goclean.sh
- name: Send btcutil coverage - name: Send btcutil coverage
uses: shogo82148/actions-goveralls@v1 uses: shogo82148/actions-goveralls@v1
with: with:
path-to-profile: profile.cov path-to-profile: coverage.txt
- name: Send btcutil coverage for psbt package
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: psbt/coverage.txt
test-race:
name: Unit race
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- name: Check out source
uses: actions/checkout@v2
- name: Test
run: make unit-race

2
.gitignore vendored
View file

@ -26,3 +26,5 @@ _cgo_export.*
_testmain.go _testmain.go
*.exe *.exe
coverage.txt
psbt/coverage.txt

54
.golangci.yml Normal file
View file

@ -0,0 +1,54 @@
run:
# timeout for analysis
deadline: 10m
linters-settings:
govet:
# Don't report about shadowed variables
check-shadowing: false
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
linters:
enable-all: true
disable:
# Global variables are used in many places throughout the code base.
- gochecknoglobals
# Some lines are over 80 characters on purpose and we don't want to make them
# even longer by marking them as 'nolint'.
- lll
# We don't care (enough) about misaligned structs to lint that.
- maligned
# We have long functions, especially in tests. Moving or renaming those would
# trigger funlen problems that we may not want to solve at that time.
- funlen
# Disable for now as we haven't yet tuned the sensitivity to our codebase
# yet. Enabling by default for example, would also force new contributors to
# potentially extensively refactor code, when they want to smaller change to
# land.
- gocyclo
# Instances of table driven tests that don't pre-allocate shouldn't trigger
# the linter.
- prealloc
# Init functions are used by loggers throughout the codebase.
- gochecknoinits
# Explicit types are okay.
- interfacer
issues:
exclude-rules:
# Exclude gosec from running for tests so that tests with weak randomness
# (math/rand) will pass the linter.
- path: _test\.go
linters:
- gosec
#- errcheck
- dupl

116
Makefile Normal file
View file

@ -0,0 +1,116 @@
PKG := github.com/btcsuite/btcutil
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
GOACC_PKG := github.com/ory/go-acc
GOIMPORTS_PKG := golang.org/x/tools/cmd/goimports
GO_BIN := ${GOPATH}/bin
LINT_BIN := $(GO_BIN)/golangci-lint
GOACC_BIN := $(GO_BIN)/go-acc
LINT_COMMIT := v1.18.0
GOACC_COMMIT := 80342ae2e0fcf265e99e76bcc4efd022c7c3811b
DEPGET := cd /tmp && GO111MODULE=on go get -v
GOBUILD := GO111MODULE=on go build -v
GOINSTALL := GO111MODULE=on go install -v
GOTEST := GO111MODULE=on go test
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
RM := rm -f
CP := cp
MAKE := make
XARGS := xargs -L 1
# Linting uses a lot of memory, so keep it under control by limiting the number
# of workers if requested.
ifneq ($(workers),)
LINT_WORKERS = --concurrency=$(workers)
endif
LINT = $(LINT_BIN) run -v $(LINT_WORKERS)
GREEN := "\\033[0;32m"
NC := "\\033[0m"
define print
echo $(GREEN)$1$(NC)
endef
default: build
all: build check
# ============
# DEPENDENCIES
# ============
$(LINT_BIN):
@$(call print, "Fetching linter")
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
$(GOACC_BIN):
@$(call print, "Fetching go-acc")
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)
goimports:
@$(call print, "Installing goimports.")
$(DEPGET) $(GOIMPORTS_PKG)
# ============
# INSTALLATION
# ============
build:
@$(call print, "Compiling btcutil.")
$(GOBUILD) $(PKG)/...
# =======
# TESTING
# =======
check: unit
unit:
@$(call print, "Running unit tests.")
$(GOTEST) ./... -test.timeout=20m
cd psbt; $(GOTEST) ./... -test.timeout=20m
unit-cover: $(GOACC_BIN)
@$(call print, "Running unit coverage tests.")
$(GOACC_BIN) ./...
cd psbt; $(GOACC_BIN) ./...
unit-race:
@$(call print, "Running unit race tests.")
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
cd psbt; env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
# =========
# UTILITIES
# =========
fmt: goimports
@$(call print, "Fixing imports.")
goimports -w $(GOFILES_NOVENDOR)
@$(call print, "Formatting source.")
gofmt -l -w -s $(GOFILES_NOVENDOR)
lint: $(LINT_BIN)
@$(call print, "Linting source.")
$(LINT)
clean:
@$(call print, "Cleaning source.$(NC)")
$(RM) coverage.txt psbt/coverage.txt
.PHONY: all \
default \
build \
check \
unit \
unit-cover \
unit-race \
fmt \
lint \
clean

View file

@ -41,7 +41,7 @@ var (
// ErrUnknownAddressType describes an error where an address can not // ErrUnknownAddressType describes an error where an address can not
// decoded as a specific address type due to the string encoding // decoded as a specific address type due to the string encoding
// begining with an identifier byte unknown to any standard or // beginning with an identifier byte unknown to any standard or
// registered (via chaincfg.Register) network. // registered (via chaincfg.Register) network.
ErrUnknownAddressType = errors.New("unknown address type") ErrUnknownAddressType = errors.New("unknown address type")
@ -294,7 +294,7 @@ func NewAddressPubKeyHash(pkHash []byte, net *chaincfg.Params) (*AddressPubKeyHa
// newAddressPubKeyHash is the internal API to create a pubkey hash address // newAddressPubKeyHash is the internal API to create a pubkey hash address
// with a known leading identifier byte for a network, rather than looking // with a known leading identifier byte for a network, rather than looking
// it up through its parameters. This is useful when creating a new address // it up through its parameters. This is useful when creating a new address
// structure from a string encoding where the identifer byte is already // structure from a string encoding where the identifier byte is already
// known. // known.
func newAddressPubKeyHash(pkHash []byte, netID byte) (*AddressPubKeyHash, error) { func newAddressPubKeyHash(pkHash []byte, netID byte) (*AddressPubKeyHash, error) {
// Check for a valid pubkey hash length. // Check for a valid pubkey hash length.
@ -333,7 +333,7 @@ func (a *AddressPubKeyHash) String() string {
} }
// Hash160 returns the underlying array of the pubkey hash. This can be useful // Hash160 returns the underlying array of the pubkey hash. This can be useful
// when an array is more appropiate than a slice (for example, when used as map // when an array is more appropriate than a slice (for example, when used as map
// keys). // keys).
func (a *AddressPubKeyHash) Hash160() *[ripemd160.Size]byte { func (a *AddressPubKeyHash) Hash160() *[ripemd160.Size]byte {
return &a.hash return &a.hash
@ -361,7 +361,7 @@ func NewAddressScriptHashFromHash(scriptHash []byte, net *chaincfg.Params) (*Add
// newAddressScriptHashFromHash is the internal API to create a script hash // newAddressScriptHashFromHash is the internal API to create a script hash
// address with a known leading identifier byte for a network, rather than // address with a known leading identifier byte for a network, rather than
// looking it up through its parameters. This is useful when creating a new // looking it up through its parameters. This is useful when creating a new
// address structure from a string encoding where the identifer byte is already // address structure from a string encoding where the identifier byte is already
// known. // known.
func newAddressScriptHashFromHash(scriptHash []byte, netID byte) (*AddressScriptHash, error) { func newAddressScriptHashFromHash(scriptHash []byte, netID byte) (*AddressScriptHash, error) {
// Check for a valid script hash length. // Check for a valid script hash length.
@ -400,7 +400,7 @@ func (a *AddressScriptHash) String() string {
} }
// Hash160 returns the underlying array of the script hash. This can be useful // Hash160 returns the underlying array of the script hash. This can be useful
// when an array is more appropiate than a slice (for example, when used as map // when an array is more appropriate than a slice (for example, when used as map
// keys). // keys).
func (a *AddressScriptHash) Hash160() *[ripemd160.Size]byte { func (a *AddressScriptHash) Hash160() *[ripemd160.Size]byte {
return &a.hash return &a.hash

View file

@ -876,7 +876,7 @@ func TestAddresses(t *testing.T) {
// Encode again and compare against the original. // Encode again and compare against the original.
encoded := decoded.EncodeAddress() encoded := decoded.EncodeAddress()
if test.encoded != encoded { if test.encoded != encoded {
t.Errorf("%v: decoding and encoding produced different addressess: %v != %v", t.Errorf("%v: decoding and encoding produced different addresses: %v != %v",
test.name, test.encoded, encoded) test.name, test.encoded, encoded)
return return
} }

View file

@ -28,7 +28,7 @@ func checksum(input []byte) (cksum [4]byte) {
func CheckEncode(input []byte, version byte) string { func CheckEncode(input []byte, version byte) string {
b := make([]byte, 0, 1+len(input)+4) b := make([]byte, 0, 1+len(input)+4)
b = append(b, version) b = append(b, version)
b = append(b, input[:]...) b = append(b, input...)
cksum := checksum(b) cksum := checksum(b)
b = append(b, cksum[:]...) b = append(b, cksum[:]...)
return Encode(b) return Encode(b)

View file

@ -37,11 +37,14 @@ func TestBase58Check(t *testing.T) {
// test decoding // test decoding
res, version, err := base58.CheckDecode(test.out) res, version, err := base58.CheckDecode(test.out)
if err != nil { switch {
case err != nil:
t.Errorf("CheckDecode test #%d failed with err: %v", x, err) t.Errorf("CheckDecode test #%d failed with err: %v", x, err)
} else if version != test.version {
case version != test.version:
t.Errorf("CheckDecode test #%d failed: got version: %d want: %d", x, version, test.version) t.Errorf("CheckDecode test #%d failed: got version: %d want: %d", x, version, test.version)
} else if string(res) != test.in {
case string(res) != test.in:
t.Errorf("CheckDecode test #%d failed: got: %s want: %s", x, res, test.in) t.Errorf("CheckDecode test #%d failed: got: %s want: %s", x, res, test.in)
} }
} }
@ -56,7 +59,7 @@ func TestBase58Check(t *testing.T) {
// bytes are missing). // bytes are missing).
testString := "" testString := ""
for len := 0; len < 4; len++ { for len := 0; len < 4; len++ {
testString = testString + "x" testString += "x"
_, _, err = base58.CheckDecode(testString) _, _, err = base58.CheckDecode(testString)
if err != base58.ErrInvalidFormat { if err != base58.ErrInvalidFormat {
t.Error("Checkdecode test failed, expected ErrInvalidFormat") t.Error("Checkdecode test failed, expected ErrInvalidFormat")

View file

@ -362,7 +362,7 @@ func ConvertBits(data []byte, fromBits, toBits uint8, pad bool) ([]byte, error)
for _, b := range data { for _, b := range data {
// Discard unused bits. // Discard unused bits.
b = b << (8 - fromBits) b <<= 8 - fromBits
// How many bits remaining to extract from the input data. // How many bits remaining to extract from the input data.
remFromBits := fromBits remFromBits := fromBits
@ -383,7 +383,7 @@ func ConvertBits(data []byte, fromBits, toBits uint8, pad bool) ([]byte, error)
// Discard the bits we just extracted and get ready for // Discard the bits we just extracted and get ready for
// next iteration. // next iteration.
b = b << toExtract b <<= toExtract
remFromBits -= toExtract remFromBits -= toExtract
filledBits += toExtract filledBits += toExtract
@ -399,7 +399,7 @@ func ConvertBits(data []byte, fromBits, toBits uint8, pad bool) ([]byte, error)
// We pad any unfinished group if specified. // We pad any unfinished group if specified.
if pad && filledBits > 0 { if pad && filledBits > 0 {
nextByte = nextByte << (toBits - filledBits) nextByte <<= toBits - filledBits
regrouped = append(regrouped, nextByte) regrouped = append(regrouped, nextByte)
filledBits = 0 filledBits = 0
nextByte = 0 nextByte = 0

View file

@ -116,7 +116,7 @@ func NewMerkleBlock(block *btcutil.Block, filter *Filter) (*wire.MsgMerkleBlock,
Flags: make([]byte, (len(mBlock.bits)+7)/8), Flags: make([]byte, (len(mBlock.bits)+7)/8),
} }
for _, hash := range mBlock.finalHashes { for _, hash := range mBlock.finalHashes {
msgMerkleBlock.AddTxHash(hash) _ = msgMerkleBlock.AddTxHash(hash)
} }
for i := uint32(0); i < uint32(len(mBlock.bits)); i++ { for i := uint32(0); i < uint32(len(mBlock.bits)); i++ {
msgMerkleBlock.Flags[i/8] |= mBlock.bits[i] << (i % 8) msgMerkleBlock.Flags[i/8] |= mBlock.bits[i] << (i % 8)

View file

@ -61,7 +61,7 @@ func NewTLSCertPair(organization string, validUntil time.Time, extraHosts []stri
addIP := func(ipAddr net.IP) { addIP := func(ipAddr net.IP) {
for _, ip := range ipAddresses { for _, ip := range ipAddresses {
if bytes.Equal(ip, ipAddr) { if ip.Equal(ipAddr) {
return return
} }
} }

View file

@ -33,7 +33,7 @@ func (c *TestCoin) ValueAge() int64 { return int64(c.TxValue) * c.TxNumCon
func NewCoin(index int64, value btcutil.Amount, numConfs int64) coinset.Coin { func NewCoin(index int64, value btcutil.Amount, numConfs int64) coinset.Coin {
h := sha256.New() h := sha256.New()
h.Write([]byte(fmt.Sprintf("%d", index))) _, _ = h.Write([]byte(fmt.Sprintf("%d", index)))
hash, _ := chainhash.NewHash(h.Sum(nil)) hash, _ := chainhash.NewHash(h.Sum(nil))
c := &TestCoin{ c := &TestCoin{
TxHash: hash, TxHash: hash,

View file

@ -54,7 +54,7 @@ func RandomKey() ([gcs.KeySize]byte, error) {
} }
// Copy the byte slice to a [gcs.KeySize]byte array and return it. // Copy the byte slice to a [gcs.KeySize]byte array and return it.
copy(key[:], randKey[:]) copy(key[:], randKey)
return key, nil return key, nil
} }
@ -62,7 +62,7 @@ func RandomKey() ([gcs.KeySize]byte, error) {
// truncating the bytes of the hash to the appopriate key size. // truncating the bytes of the hash to the appopriate key size.
func DeriveKey(keyHash *chainhash.Hash) [gcs.KeySize]byte { func DeriveKey(keyHash *chainhash.Hash) [gcs.KeySize]byte {
var key [gcs.KeySize]byte var key [gcs.KeySize]byte
copy(key[:], keyHash.CloneBytes()[:]) copy(key[:], keyHash.CloneBytes())
return key return key
} }

View file

@ -19,9 +19,6 @@ import (
) )
var ( var (
// No need to allocate an err variable in every test
err error
// List of values for building a filter // List of values for building a filter
contents = [][]byte{ contents = [][]byte{
[]byte("Alex"), []byte("Alex"),

View file

@ -91,7 +91,7 @@ type Filter struct {
// BuildGCSFilter builds a new GCS filter with the collision probability of // BuildGCSFilter builds a new GCS filter with the collision probability of
// `1/(2**P)`, key `key`, and including every `[]byte` in `data` as a member of // `1/(2**P)`, key `key`, and including every `[]byte` in `data` as a member of
// the set. // the set.
func BuildGCSFilter(P uint8, M uint64, key [KeySize]byte, data [][]byte) (*Filter, error) { func BuildGCSFilter(P uint8, M uint64, key [KeySize]byte, data [][]byte) (*Filter, error) { // nolint:gocritic
// Some initial parameter checks: make sure we have data from which to // Some initial parameter checks: make sure we have data from which to
// build the filter, and make sure our parameters will fit the hash // build the filter, and make sure our parameters will fit the hash
// function we're using. // function we're using.
@ -174,7 +174,7 @@ func BuildGCSFilter(P uint8, M uint64, key [KeySize]byte, data [][]byte) (*Filte
// FromBytes deserializes a GCS filter from a known N, P, and serialized filter // FromBytes deserializes a GCS filter from a known N, P, and serialized filter
// as returned by Bytes(). // as returned by Bytes().
func FromBytes(N uint32, P uint8, M uint64, d []byte) (*Filter, error) { func FromBytes(N uint32, P uint8, M uint64, d []byte) (*Filter, error) { // nolint:gocritic
// Basic sanity check. // Basic sanity check.
if P > 32 { if P > 32 {
return nil, ErrPTooBig return nil, ErrPTooBig
@ -200,7 +200,7 @@ func FromBytes(N uint32, P uint8, M uint64, d []byte) (*Filter, error) {
// FromNBytes deserializes a GCS filter from a known P, and serialized N and // FromNBytes deserializes a GCS filter from a known P, and serialized N and
// filter as returned by NBytes(). // filter as returned by NBytes().
func FromNBytes(P uint8, M uint64, d []byte) (*Filter, error) { func FromNBytes(P uint8, M uint64, d []byte) (*Filter, error) { // nolint:gocritic
buffer := bytes.NewBuffer(d) buffer := bytes.NewBuffer(d)
N, err := wire.ReadVarInt(buffer, varIntProtoVer) N, err := wire.ReadVarInt(buffer, varIntProtoVer)
if err != nil { if err != nil {

View file

@ -27,7 +27,7 @@ var (
// Filters are conserved between tests but we must define with an // Filters are conserved between tests but we must define with an
// interface which functions we're testing because the gcsFilter type // interface which functions we're testing because the gcsFilter type
// isn't exported // isn't exported
filter, filter2, filter3, filter4, filter5 *gcs.Filter filter, filter2, filter3 *gcs.Filter
// We need to use the same key for building and querying the filters // We need to use the same key for building and querying the filters
key [gcs.KeySize]byte key [gcs.KeySize]byte
@ -328,6 +328,8 @@ func TestGCSFilterMatchAnySuite(t *testing.T) {
} }
for _, test := range funcs { for _, test := range funcs {
test := test
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
contentsCopy := make([][]byte, len(contents2)) contentsCopy := make([][]byte, len(contents2))
copy(contentsCopy, contents2) copy(contentsCopy, contents2)

View file

@ -28,7 +28,6 @@ func genRandFilterElements(numElements uint) ([][]byte, error) {
var ( var (
generatedFilter *gcs.Filter generatedFilter *gcs.Filter
filterErr error
) )
// BenchmarkGCSFilterBuild benchmarks building a filter. // BenchmarkGCSFilterBuild benchmarks building a filter.
@ -101,7 +100,7 @@ func BenchmarkGCSFilterMatch(b *testing.B) {
var localMatch bool var localMatch bool
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
localMatch, err = filter.Match(key, []byte("Nate")) _, err = filter.Match(key, []byte("Nate"))
if err != nil { if err != nil {
b.Fatalf("unable to match filter: %v", err) b.Fatalf("unable to match filter: %v", err)
} }
@ -115,8 +114,6 @@ func BenchmarkGCSFilterMatch(b *testing.B) {
} }
var ( var (
randElems1, _ = genRandFilterElements(1)
randElems10, _ = genRandFilterElements(10)
randElems100, _ = genRandFilterElements(100) randElems100, _ = genRandFilterElements(100)
randElems1000, _ = genRandFilterElements(1000) randElems1000, _ = genRandFilterElements(1000)
randElems10000, _ = genRandFilterElements(10000) randElems10000, _ = genRandFilterElements(10000)
@ -164,6 +161,8 @@ var matchAnyBenchmarks = []struct {
// BenchmarkGCSFilterMatchAny benchmarks the sort-and-zip MatchAny impl. // BenchmarkGCSFilterMatchAny benchmarks the sort-and-zip MatchAny impl.
func BenchmarkGCSFilterZipMatchAny(b *testing.B) { func BenchmarkGCSFilterZipMatchAny(b *testing.B) {
for _, test := range matchAnyBenchmarks { for _, test := range matchAnyBenchmarks {
test := test
b.Run(test.name, func(b *testing.B) { b.Run(test.name, func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
@ -188,6 +187,8 @@ func BenchmarkGCSFilterZipMatchAny(b *testing.B) {
// BenchmarkGCSFilterMatchAny benchmarks the hash-join MatchAny impl. // BenchmarkGCSFilterMatchAny benchmarks the hash-join MatchAny impl.
func BenchmarkGCSFilterHashMatchAny(b *testing.B) { func BenchmarkGCSFilterHashMatchAny(b *testing.B) {
for _, test := range matchAnyBenchmarks { for _, test := range matchAnyBenchmarks {
test := test
b.Run(test.name, func(b *testing.B) { b.Run(test.name, func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
@ -212,6 +213,8 @@ func BenchmarkGCSFilterHashMatchAny(b *testing.B) {
// BenchmarkGCSFilterMatchAny benchmarks the hybrid MatchAny impl. // BenchmarkGCSFilterMatchAny benchmarks the hybrid MatchAny impl.
func BenchmarkGCSFilterMatchAny(b *testing.B) { func BenchmarkGCSFilterMatchAny(b *testing.B) {
for _, test := range matchAnyBenchmarks { for _, test := range matchAnyBenchmarks {
test := test
b.Run(test.name, func(b *testing.B) { b.Run(test.name, func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()

View file

@ -1,46 +0,0 @@
#!/bin/bash
# The script does automatic checking on a Go package and its sub-packages, including:
# 1. gofmt (http://golang.org/cmd/gofmt/)
# 2. goimports (https://github.com/bradfitz/goimports)
# 3. golint (https://github.com/golang/lint)
# 4. go vet (http://golang.org/cmd/vet)
# 5. gosimple (https://github.com/dominikh/go-simple)
# 6. unconvert (https://github.com/mdempsky/unconvert)
# 7. race detector (http://blog.golang.org/race-detector)
# 8. test coverage (http://blog.golang.org/cover)
#
set -ex
# Automatic checks
for i in $(find . -name go.mod -type f -print); do
module=$(dirname ${i})
echo "==> ${module}"
MODNAME=$(echo $module | sed -E -e "s/^$ROOTPATHPATTERN//" \
-e 's,^/,,' -e 's,/v[0-9]+$,,')
if [ -z "$MODNAME" ]; then
MODNAME=.
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

View file

@ -13,7 +13,7 @@ import (
// Calculate the hash of hasher over buf. // Calculate the hash of hasher over buf.
func calcHash(buf []byte, hasher hash.Hash) []byte { func calcHash(buf []byte, hasher hash.Hash) []byte {
hasher.Write(buf) _, _ = hasher.Write(buf)
return hasher.Sum(nil) return hasher.Sum(nil)
} }

View file

@ -26,7 +26,7 @@ func BenchmarkDeriveHardened(b *testing.B) {
b.StartTimer() b.StartTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
masterKey.Derive(hdkeychain.HardenedKeyStart) _, _ = masterKey.Derive(hdkeychain.HardenedKeyStart)
} }
} }
@ -41,7 +41,7 @@ func BenchmarkDeriveNormal(b *testing.B) {
b.StartTimer() b.StartTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
masterKey.Derive(0) _, _ = masterKey.Derive(0)
} }
} }
@ -56,7 +56,7 @@ func BenchmarkPrivToPub(b *testing.B) {
b.StartTimer() b.StartTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
masterKey.Neuter() _, _ = masterKey.Neuter()
} }
} }
@ -64,7 +64,7 @@ func BenchmarkPrivToPub(b *testing.B) {
// extended key. // extended key.
func BenchmarkDeserialize(b *testing.B) { func BenchmarkDeserialize(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
hdkeychain.NewKeyFromString(bip0032MasterPriv1) _, _ = hdkeychain.NewKeyFromString(bip0032MasterPriv1)
} }
} }

View file

@ -277,7 +277,7 @@ func (k *ExtendedKey) Derive(i uint32) (*ExtendedKey, error) {
// data: // data:
// I = HMAC-SHA512(Key = chainCode, Data = data) // I = HMAC-SHA512(Key = chainCode, Data = data)
hmac512 := hmac.New(sha512.New, k.chainCode) hmac512 := hmac.New(sha512.New, k.chainCode)
hmac512.Write(data) _, _ = hmac512.Write(data)
ilr := hmac512.Sum(nil) ilr := hmac512.Sum(nil)
// Split "I" into two 32-byte sequences Il and Ir where: // Split "I" into two 32-byte sequences Il and Ir where:
@ -380,7 +380,7 @@ func (k *ExtendedKey) DeriveNonStandard(i uint32) (*ExtendedKey, error) {
binary.BigEndian.PutUint32(data[keyLen:], i) binary.BigEndian.PutUint32(data[keyLen:], i)
hmac512 := hmac.New(sha512.New, k.chainCode) hmac512 := hmac.New(sha512.New, k.chainCode)
hmac512.Write(data) _, _ = hmac512.Write(data)
ilr := hmac512.Sum(nil) ilr := hmac512.Sum(nil)
il := ilr[:len(ilr)/2] il := ilr[:len(ilr)/2]
@ -610,7 +610,7 @@ func NewMaster(seed []byte, net *chaincfg.Params) (*ExtendedKey, error) {
// First take the HMAC-SHA512 of the master key and the seed data: // First take the HMAC-SHA512 of the master key and the seed data:
// I = HMAC-SHA512(Key = "Bitcoin seed", Data = S) // I = HMAC-SHA512(Key = "Bitcoin seed", Data = S)
hmac512 := hmac.New(sha512.New, masterKey) hmac512 := hmac.New(sha512.New, masterKey)
hmac512.Write(seed) _, _ = hmac512.Write(seed)
lr := hmac512.Sum(nil) lr := hmac512.Sum(nil)
// Split "I" into two 32-byte sequences Il and Ir where: // Split "I" into two 32-byte sequences Il and Ir where:

View file

@ -983,7 +983,7 @@ func TestZero(t *testing.T) {
wantAddr := "1HT7xU2Ngenf7D4yocz2SAcnNLW7rK8d4E" wantAddr := "1HT7xU2Ngenf7D4yocz2SAcnNLW7rK8d4E"
addr, err := key.Address(&chaincfg.MainNetParams) addr, err := key.Address(&chaincfg.MainNetParams)
if err != nil { if err != nil {
t.Errorf("Addres s #%d (%s): unexpected error: %v", i, t.Errorf("Address #%d (%s): unexpected error: %v", i,
testName, err) testName, err)
return false return false
} }

View file

@ -1,72 +0,0 @@
github.com/conformal/btcutil/base58.go Base58Decode 100.00% (20/20)
github.com/conformal/btcutil/base58.go Base58Encode 100.00% (15/15)
github.com/conformal/btcutil/block.go Block.Tx 100.00% (12/12)
github.com/conformal/btcutil/wif.go WIF.String 100.00% (11/11)
github.com/conformal/btcutil/block.go Block.Transactions 100.00% (11/11)
github.com/conformal/btcutil/amount.go AmountUnit.String 100.00% (8/8)
github.com/conformal/btcutil/tx.go NewTxFromReader 100.00% (6/6)
github.com/conformal/btcutil/block.go NewBlockFromBytes 100.00% (6/6)
github.com/conformal/btcutil/block.go NewBlockFromReader 100.00% (6/6)
github.com/conformal/btcutil/address.go encodeAddress 100.00% (6/6)
github.com/conformal/btcutil/address.go newAddressPubKeyHash 100.00% (5/5)
github.com/conformal/btcutil/address.go newAddressScriptHashFromHash 100.00% (5/5)
github.com/conformal/btcutil/tx.go Tx.Sha 100.00% (5/5)
github.com/conformal/btcutil/block.go Block.Sha 100.00% (5/5)
github.com/conformal/btcutil/amount.go NewAmount 100.00% (5/5)
github.com/conformal/btcutil/amount.go round 100.00% (3/3)
github.com/conformal/btcutil/address.go NewAddressScriptHash 100.00% (2/2)
github.com/conformal/btcutil/amount.go Amount.Format 100.00% (2/2)
github.com/conformal/btcutil/tx.go NewTxFromBytes 100.00% (2/2)
github.com/conformal/btcutil/hash160.go calcHash 100.00% (2/2)
github.com/conformal/btcutil/address.go AddressPubKeyHash.Hash160 100.00% (1/1)
github.com/conformal/btcutil/block.go OutOfRangeError.Error 100.00% (1/1)
github.com/conformal/btcutil/block.go Block.MsgBlock 100.00% (1/1)
github.com/conformal/btcutil/tx.go Tx.MsgTx 100.00% (1/1)
github.com/conformal/btcutil/hash160.go Hash160 100.00% (1/1)
github.com/conformal/btcutil/block.go NewBlockFromBlockAndBytes 100.00% (1/1)
github.com/conformal/btcutil/block.go Block.Height 100.00% (1/1)
github.com/conformal/btcutil/block.go Block.SetHeight 100.00% (1/1)
github.com/conformal/btcutil/block.go NewBlock 100.00% (1/1)
github.com/conformal/btcutil/address.go AddressPubKeyHash.IsForNet 100.00% (1/1)
github.com/conformal/btcutil/address.go AddressPubKey.EncodeAddress 100.00% (1/1)
github.com/conformal/btcutil/address.go NewAddressPubKeyHash 100.00% (1/1)
github.com/conformal/btcutil/address.go AddressPubKeyHash.EncodeAddress 100.00% (1/1)
github.com/conformal/btcutil/address.go AddressPubKeyHash.ScriptAddress 100.00% (1/1)
github.com/conformal/btcutil/address.go AddressPubKeyHash.String 100.00% (1/1)
github.com/conformal/btcutil/address.go NewAddressScriptHashFromHash 100.00% (1/1)
github.com/conformal/btcutil/address.go AddressScriptHash.EncodeAddress 100.00% (1/1)
github.com/conformal/btcutil/address.go AddressScriptHash.ScriptAddress 100.00% (1/1)
github.com/conformal/btcutil/address.go AddressScriptHash.IsForNet 100.00% (1/1)
github.com/conformal/btcutil/address.go AddressScriptHash.String 100.00% (1/1)
github.com/conformal/btcutil/address.go AddressScriptHash.Hash160 100.00% (1/1)
github.com/conformal/btcutil/address.go AddressPubKey.ScriptAddress 100.00% (1/1)
github.com/conformal/btcutil/address.go AddressPubKey.IsForNet 100.00% (1/1)
github.com/conformal/btcutil/address.go AddressPubKey.String 100.00% (1/1)
github.com/conformal/btcutil/tx.go NewTx 100.00% (1/1)
github.com/conformal/btcutil/tx.go Tx.SetIndex 100.00% (1/1)
github.com/conformal/btcutil/amount.go Amount.ToUnit 100.00% (1/1)
github.com/conformal/btcutil/tx.go Tx.Index 100.00% (1/1)
github.com/conformal/btcutil/amount.go Amount.String 100.00% (1/1)
github.com/conformal/btcutil/amount.go Amount.MulF64 100.00% (1/1)
github.com/conformal/btcutil/appdata.go appDataDir 92.00% (23/25)
github.com/conformal/btcutil/block.go Block.TxLoc 88.89% (8/9)
github.com/conformal/btcutil/block.go Block.Bytes 88.89% (8/9)
github.com/conformal/btcutil/address.go NewAddressPubKey 87.50% (7/8)
github.com/conformal/btcutil/address.go DecodeAddress 85.00% (17/20)
github.com/conformal/btcutil/wif.go DecodeWIF 85.00% (17/20)
github.com/conformal/btcutil/address.go AddressPubKey.serialize 80.00% (4/5)
github.com/conformal/btcutil/block.go Block.TxSha 75.00% (3/4)
github.com/conformal/btcutil/wif.go paddedAppend 66.67% (2/3)
github.com/conformal/btcutil/wif.go NewWIF 66.67% (2/3)
github.com/conformal/btcutil/certgen.go NewTLSCertPair 0.00% (0/54)
github.com/conformal/btcutil/wif.go WIF.SerializePubKey 0.00% (0/4)
github.com/conformal/btcutil/address.go AddressPubKey.AddressPubKeyHash 0.00% (0/3)
github.com/conformal/btcutil/address.go AddressPubKey.Format 0.00% (0/1)
github.com/conformal/btcutil/address.go AddressPubKey.PubKey 0.00% (0/1)
github.com/conformal/btcutil/address.go AddressPubKey.SetFormat 0.00% (0/1)
github.com/conformal/btcutil/wif.go WIF.IsForNet 0.00% (0/1)
github.com/conformal/btcutil/appdata.go AppDataDir 0.00% (0/1)
github.com/conformal/btcutil/net.go interfaceAddrs 0.00% (0/1)
github.com/conformal/btcutil ------------------------------- 75.88% (258/340)

View file

@ -64,6 +64,8 @@ func TestEncodeDecodeWIF(t *testing.T) {
} }
for _, validCase := range validEncodeCases { for _, validCase := range validEncodeCases {
validCase := validCase
t.Run(validCase.name, func(t *testing.T) { t.Run(validCase.name, func(t *testing.T) {
priv, _ := btcec.PrivKeyFromBytes(btcec.S256(), validCase.privateKey) priv, _ := btcec.PrivKeyFromBytes(btcec.S256(), validCase.privateKey)
wif, err := NewWIF(priv, validCase.net, validCase.compress) wif, err := NewWIF(priv, validCase.net, validCase.compress)
@ -122,6 +124,8 @@ func TestEncodeDecodeWIF(t *testing.T) {
} }
for _, invalidCase := range invalidDecodeCases { for _, invalidCase := range invalidDecodeCases {
invalidCase := invalidCase
t.Run(invalidCase.name, func(t *testing.T) { t.Run(invalidCase.name, func(t *testing.T) {
decodedWif, err := DecodeWIF(invalidCase.wif) decodedWif, err := DecodeWIF(invalidCase.wif)
if decodedWif != nil { if decodedWif != nil {