Skip to content

Commit

Permalink
Merge pull request ethereum#395 from maticnetwork/testing-flags
Browse files Browse the repository at this point in the history
Restores linters and separate kinds of tests
  • Loading branch information
JekaMas authored May 23, 2022
2 parents 63bedf3 + 2930d04 commit 87a2e52
Show file tree
Hide file tree
Showing 19 changed files with 409 additions and 35 deletions.
92 changes: 76 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,80 @@
name: CI
on: [push, pull_request]
on:
push:
branches:
- "master"
pull_request:
branches:
- "**"
types: [opened, synchronize]

concurrency:
group: build-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
tests:
if: (github.event.action != 'closed' || github.event.pull_request.merged == true)
strategy:
matrix:
os: [ ubuntu-20.04, macos-11 ] # list of os: https://github.com/actions/virtual-environments
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: "Build binaries"
run: make all
- name: "Run tests"
run: make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: ./cover.out
- uses: actions/checkout@v3
- run: |
git submodule update --init --recursive --force
git fetch --no-tags --prune --depth=1 origin +refs/heads/master:refs/remotes/origin/master
- uses: actions/setup-go@v3
with:
go-version: 1.18.x

- name: Install dependencies on Linux
if: runner.os == 'Linux'
run: sudo apt update && sudo apt install build-essential

- name: Golang-ci install
if: runner.os == 'Linux'
run: make lintci-deps

- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/Library/Caches/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-

- name: Build
run: make all

# TODO: make it work

# - name: Reproducible build test
# run: |
# make geth
# shasum -a256 ./build/bin/geth > bor1.sha256
# make geth
# shasum -a256 ./build/bin/geth > bor2.sha256
# if ! cmp -s bor1.sha256 bor2.sha256; then
# echo >&2 "Reproducible build broken"; cat bor1.sha256; cat bor2.sha256; exit 1
# fi

- name: Lint
if: runner.os == 'Linux'
run: make lint

- name: Test
run: make test

#- name: Data race tests
# run: make test-race

- name: test-integration
run: make test-integration

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: ./cover.out
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/**/*dapps*
build/_vendor/pkg

cover.out

#*
.#*
*#
Expand Down
154 changes: 145 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,139 @@ run:
skip-dirs-use-default: true
skip-files:
- core/genesis_alloc.go
- gen_.*.go
- .*_gen.go

linters:
disable-all: true
enable:
- deadcode
- goconst
- goimports
- gosimple
- govet
- ineffassign
- misspell
# - staticcheck
- unconvert
# - unused
- varcheck
- bodyclose
- containedctx
- contextcheck
- decorder
- durationcheck
- errchkjson
- errname
- exhaustive
- exportloopref
- gocognit
- gofmt
- gomnd
- gomoddirectives
- gosec
- makezero
- nestif
- nilerr
- nilnil
- noctx
#- nosprintfhostport # TODO: do we use IPv6?
- paralleltest
- prealloc
- predeclared
#- promlinter
#- revive
- tagliatelle
- tenv
- thelper
- tparallel
- unconvert
- unparam
- wsl
#- errorlint causes stack overflow. TODO: recheck after each golangci update

linters-settings:
gofmt:
simplify: true
auto-fix: false

goconst:
min-len: 3 # minimum length of string constant
min-occurrences: 6 # minimum number of occurrences
min-occurrences: 2 # minimum number of occurrences
numbers: true

goimports:
local-prefixes: github.com/ethereum/go-ethereum

nestif:
min-complexity: 3

prealloc:
for-loops: true

gocritic:
# Which checks should be enabled; can't be combined with 'disabled-checks';
# See https://go-critic.github.io/overview#checks-overview
# To check which checks are enabled run `GL_DEBUG=gocritic ./build/bin/golangci-lint run`
# By default list of stable checks is used.
enabled-checks:
- badLock
- filepathJoin
- sortSlice
- sprintfQuotedString
- syncMapLoadAndDelete
- weakCond
- boolExprSimplify
- httpNoBody
- ioutilDeprecated
- nestingReduce
- preferFilepathJoin
- redundantSprint
- stringConcatSimplify
- timeExprSimplify
- typeAssertChain
- yodaStyleExpr
- truncateCmp
- equalFold
- preferDecodeRune
- preferFprint
- preferStringWriter
- preferWriteByte
- sliceClear
#- ruleguard

# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
disabled-checks:
- regexpMust
- exitAfterDefer
- dupBranchBody
- singleCaseSwitch
- unlambda
- captLocal
- commentFormatting
- ifElseChain
- importShadow
- builtinShadow

# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
enabled-tags:
- performance
- diagnostic
- opinionated
- style
disabled-tags:
- experimental
govet:
disable:
- deepequalerrors
- fieldalignment
- shadow
- unsafeptr
check-shadowing: true
enable-all: true
settings:
printf:
# Run `go tool vet help printf` to see available settings for `printf` analyzer.
funcs:
- (github.com/ethereum/go-ethereum/log.Logger).Trace
- (github.com/ethereum/go-ethereum/log.Logger).Debug
- (github.com/ethereum/go-ethereum/log.Logger).Info
- (github.com/ethereum/go-ethereum/log.Logger).Warn
- (github.com/ethereum/go-ethereum/log.Logger).Error
- (github.com/ethereum/go-ethereum/log.Logger).Crit

issues:
exclude-rules:
Expand All @@ -48,3 +159,28 @@ issues:
- path: cmd/faucet/
linters:
- deadcode
# Exclude some linters from running on tests files.
- path: test\.go
linters:
- gosec
- unused
- deadcode
- gocritic
- path: cmd/devp2p
linters:
- gosec
- unused
- deadcode
- gocritic
- path: metrics/sample\.go
linters:
- gosec
- gocritic
- path: p2p/simulations
linters:
- gosec
- gocritic
max-issues-per-linter: 0
max-same-issues: 0
#new: true
new-from-rev: origin/master
37 changes: 32 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@
.PHONY: geth-darwin geth-darwin-386 geth-darwin-amd64
.PHONY: geth-windows geth-windows-386 geth-windows-amd64

GOBIN = ./build/bin
GO ?= latest
GOBIN = $(CURDIR)/build/bin
GORUN = env GO111MODULE=on go run
GOPATH = $(shell go env GOPATH)

GIT_COMMIT ?= $(shell git rev-list -1 HEAD)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
GIT_TAG ?= $(shell git describe --tags `git rev-list --tags="v*" --max-count=1`)

PACKAGE = github.com/ethereum/go-ethereum
GO_FLAGS += -buildvcs=false
GO_FLAGS += -ldflags "-X ${PACKAGE}/params.GitCommit=${GIT_COMMIT} -X ${PACKAGE}/params.GitBranch=${GIT_BRANCH} -X ${PACKAGE}/params.GitTag=${GIT_TAG}"

TESTALL = $$(go list ./... | grep -v go-ethereum/cmd/)
TESTE2E = ./tests/...
GOTEST = GODEBUG=cgocheck=0 go test $(GO_FLAGS) -p 1

bor:
mkdir -p $(GOPATH)/bin/
go build -o $(GOBIN)/bor ./cmd/cli/main.go
Expand Down Expand Up @@ -41,11 +53,26 @@ ios:
@echo "Import \"$(GOBIN)/Geth.framework\" to use the library."

test:
# Skip mobile and cmd tests since they are being deprecated
go test -v $$(go list ./... | grep -v go-ethereum/cmd/) -cover -coverprofile=cover.out
$(GOTEST) --timeout 5m -shuffle=on -cover -coverprofile=cover.out $(TESTALL)

test-race:
$(GOTEST) --timeout 15m -race -shuffle=on $(TESTALL)

test-integration:
$(GOTEST) --timeout 30m -tags integration $(TESTE2E)

escape:
cd $(path) && go test -gcflags "-m -m" -run none -bench=BenchmarkJumpdest* -benchmem -memprofile mem.out

lint:
@./build/bin/golangci-lint run --config ./.golangci.yml

lintci-deps:
rm -f ./build/bin/golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.46.0

lint: ## Run linters.
$(GORUN) build/ci.go lint
goimports:
goimports -local "$(PACKAGE)" -w .

docs:
$(GORUN) cmd/clidoc/main.go -d ./docs/cli
Expand Down
5 changes: 5 additions & 0 deletions accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ import (
"testing"
"time"

"go.uber.org/goleak"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/leak"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
)

func TestSimulatedBackend(t *testing.T) {
defer goleak.VerifyNone(t, leak.IgnoreList()...)

var gasLimit uint64 = 8000029
key, _ := crypto.GenerateKey() // nolint: gosec
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
Expand Down
23 changes: 23 additions & 0 deletions common/leak/ignore_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package leak

import "go.uber.org/goleak"

func IgnoreList() []goleak.Option {
return []goleak.Option{
// a list of goroutne leaks that hard to fix due to external dependencies or too big refactoring needed
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/core.(*txSenderCacher).cache"),
goleak.IgnoreTopFunction("github.com/rjeczalik/notify.(*recursiveTree).dispatch"),
goleak.IgnoreTopFunction("github.com/rjeczalik/notify.(*recursiveTree).internal"),
goleak.IgnoreTopFunction("github.com/rjeczalik/notify.(*nonrecursiveTree).dispatch"),
goleak.IgnoreTopFunction("github.com/rjeczalik/notify.(*nonrecursiveTree).internal"),
goleak.IgnoreTopFunction("github.com/rjeczalik/notify._Cfunc_CFRunLoopRun"),

// todo: this leaks should be fixed
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/metrics.(*meterArbiter).tick"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/consensus/ethash.(*remoteSealer).loop"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/core.(*BlockChain).updateFutureBlocks"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/core/state/snapshot.(*diskLayer).generate"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/accounts/abi/bind/backends.nullSubscription.func1"),
goleak.IgnoreTopFunction("github.com/ethereum/go-ethereum/eth/filters.(*EventSystem).eventLoop"),
}
}
Loading

0 comments on commit 87a2e52

Please sign in to comment.