From 22b4663f7a3f13fcb3019090801c798d1bda5c53 Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 10 Mar 2025 17:40:53 +0900 Subject: [PATCH 1/3] Makefile: Update dependencies and improve installation commands --- Makefile | 60 +++++++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 3825005c..ef8459a2 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,15 @@ PKG := github.com/btcsuite/btcd -LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint +LINT_PKG := github.com/golangci/golangci-lint/v2/cmd/golangci-lint GOIMPORTS_PKG := golang.org/x/tools/cmd/goimports -GO_BIN := ${GOPATH}/bin +GO_BIN := ${shell go env GOBIN} LINT_BIN := $(GO_BIN)/golangci-lint +GOIMPORTS_BIN := $(GO_BIN)/goimports -LINT_COMMIT := v1.18.0 +LINT_COMMIT := v2.1.6 +GOIMPORTS_COMMIT := a24facf9e5586c95743d2f4ad15d148c7a8cf00b -DEPGET := cd /tmp && go install -v GOBUILD := go build -v GOINSTALL := go install -v DEV_TAGS := rpctest @@ -16,20 +17,14 @@ GOTEST_DEV = go test -v -tags=$(DEV_TAGS) GOTEST := go test -v COVER_FLAGS = -coverprofile=coverage.txt -covermode=atomic -coverpkg=$(PKG)/... -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_TIMEOUT := 5m -LINT = $(LINT_BIN) run -v $(LINT_WORKERS) +LINT = $(LINT_BIN) run -v $(LINT_WORKERS) --timeout=$(LINT_TIMEOUT) GREEN := "\\033[0;32m" NC := "\\033[0m" @@ -49,12 +44,12 @@ all: build check $(LINT_BIN): @$(call print, "Fetching linter") - $(DEPGET) $(LINT_PKG)@$(LINT_COMMIT) + $(GOINSTALL) $(LINT_PKG)@$(LINT_COMMIT) #? goimports: Install goimports goimports: @$(call print, "Installing goimports.") - $(DEPGET) $(GOIMPORTS_PKG) + $(GOINSTALL) $(GOIMPORTS_PKG)@$(GOIMPORTS_COMMIT) # ============ # INSTALLATION @@ -95,30 +90,28 @@ check: unit unit: @$(call print, "Running unit tests.") $(GOTEST_DEV) ./... -test.timeout=20m - cd btcec; $(GOTEST_DEV) ./... -test.timeout=20m - cd btcutil; $(GOTEST_DEV) ./... -test.timeout=20m - cd btcutil/psbt; $(GOTEST_DEV) ./... -test.timeout=20m + cd btcec && $(GOTEST_DEV) ./... -test.timeout=20m + cd btcutil && $(GOTEST_DEV) ./... -test.timeout=20m + cd btcutil/psbt && $(GOTEST_DEV) ./... -test.timeout=20m #? unit-cover: Run unit coverage tests unit-cover: @$(call print, "Running unit coverage tests.") $(GOTEST) $(COVER_FLAGS) ./... + # We need to remove the /v2 pathing from the module to have it work - # nicely with the CI tool we use to render live code coverage. - cd btcec; $(GOTEST) $(COVER_FLAGS) ./...; \ - sed -i.bak 's/v2\///g' coverage.txt - - cd btcutil; $(GOTEST) $(COVER_FLAGS) ./... - - cd btcutil/psbt; $(GOTEST) $(COVER_FLAGS) ./... + # nicely with the CI tool we use to render live code coverage. + cd btcec && $(GOTEST) $(COVER_FLAGS) ./... && sed -i.bak 's/v2\///g' coverage.txt + cd btcutil && $(GOTEST) $(COVER_FLAGS) ./... + cd btcutil/psbt && $(GOTEST) $(COVER_FLAGS) ./... #? unit-race: Run unit race tests 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 btcec; env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./... - cd btcutil; env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./... - cd btcutil/psbt; env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./... + cd btcec && env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./... + cd btcutil && env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./... + cd btcutil/psbt && env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./... # ========= # UTILITIES @@ -127,9 +120,9 @@ unit-race: #? fmt: Fix imports and formatting source fmt: goimports @$(call print, "Fixing imports.") - goimports -w $(GOFILES_NOVENDOR) + $(GOIMPORTS_BIN) -w . @$(call print, "Formatting source.") - gofmt -l -w -s $(GOFILES_NOVENDOR) + gofmt -l -w -s . #? lint: Lint source lint: $(LINT_BIN) @@ -139,8 +132,8 @@ lint: $(LINT_BIN) #? clean: Clean source clean: @$(call print, "Cleaning source.$(NC)") - $(RM) coverage.txt btcec/coverage.txt btcutil/coverage.txt btcutil/psbt/coverage.txt - + rm -f coverage.txt btcec/coverage.txt btcutil/coverage.txt btcutil/psbt/coverage.txt + #? tidy-module: Run 'go mod tidy' for all modules tidy-module: echo "Running 'go mod tidy' for all modules" @@ -155,11 +148,12 @@ tidy-module: unit-race \ fmt \ lint \ - clean + clean \ + tidy-module #? help: Get more info on make commands help: Makefile @echo " Choose a command run in btcd:" @sed -n 's/^#?//p' $< | column -t -s ':' | sort | sed -e 's/^/ /' -.PHONY: help +.PHONY: help \ No newline at end of file From f19065176be276ecce070a5339cc899f2b3f01f4 Mon Sep 17 00:00:00 2001 From: Kim Date: Mon, 10 Mar 2025 17:42:32 +0900 Subject: [PATCH 2/3] multi: apply make fmt to all files --- btcutil/psbt/partialsig.go | 1 + rpcclient/chain_test.go | 6 +++--- rpcclient/example_test.go | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/btcutil/psbt/partialsig.go b/btcutil/psbt/partialsig.go index dfb70049..9d24c49b 100644 --- a/btcutil/psbt/partialsig.go +++ b/btcutil/psbt/partialsig.go @@ -2,6 +2,7 @@ package psbt import ( "bytes" + "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2/ecdsa" ) diff --git a/rpcclient/chain_test.go b/rpcclient/chain_test.go index ad1fb7aa..464506d0 100644 --- a/rpcclient/chain_test.go +++ b/rpcclient/chain_test.go @@ -146,7 +146,7 @@ func TestClientConnectedToWSServerRunner(t *testing.T) { } testTable := []TestTableItem{ - TestTableItem{ + { Name: "TestGetChainTxStatsAsyncSuccessTx", TestCase: func(t *testing.T) { client, serverReceivedChannel, cleanup := makeClient(t) @@ -159,7 +159,7 @@ func TestClientConnectedToWSServerRunner(t *testing.T) { } }, }, - TestTableItem{ + { Name: "TestGetChainTxStatsAsyncShutdownError", TestCase: func(t *testing.T) { client, _, cleanup := makeClient(t) @@ -192,7 +192,7 @@ func TestClientConnectedToWSServerRunner(t *testing.T) { } }, }, - TestTableItem{ + { Name: "TestGetBestBlockHashAsync", TestCase: func(t *testing.T) { client, serverReceivedChannel, cleanup := makeClient(t) diff --git a/rpcclient/example_test.go b/rpcclient/example_test.go index 9ba9adad..9b3ac0f3 100644 --- a/rpcclient/example_test.go +++ b/rpcclient/example_test.go @@ -6,6 +6,7 @@ package rpcclient import ( "fmt" + "github.com/btcsuite/btcd/btcjson" ) From 106cde6adb267ffc891f89eb6efeed3060756c9a Mon Sep 17 00:00:00 2001 From: Kim Date: Fri, 11 Jul 2025 18:39:41 +0900 Subject: [PATCH 3/3] golangci: add configuration file for linting --- .golangci.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..585854d5 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,4 @@ +version: "2" +issues: + # Only show newly introduced problems. + new-from-rev: 80b74d6c5a0088a66dc96df6777d21e15c04849c \ No newline at end of file