Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge dev into upstream v0.2.1 #8

Merged
merged 13 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
name: Test unit

on:
push:
branches:
- main
- 'release/**'
pull_request:

jobs:
test-unit:
strategy:
fail-fast: false
matrix:
go-version: [ 1.21.x ]
goarch: [ "amd64" ]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
env:
GOARCH: ${{ matrix.goarch }}

- name: Test
run: make test-unit

- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
name: code-coverage-report
path: coverage.out

sonar-cloud:
if: false
needs: test-unit
name: SonarCloud
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Download code coverage results
uses: actions/download-artifact@v3
with:
name: code-coverage-report

- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
test/sepolia.keystore
test/ethtxmanager-persistence.json
test/ethtxmanager-persistence.json.tmp
coverage.out
41 changes: 31 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
---
run:
timeout: 5m
skip-dirs:
- test


linters:
enable:
- whitespace
- gosec
- whitespace # Tool for detection of leading and trailing whitespace
- gosec # Security problems
- gci
- misspell
- gomnd
- gofmt
- goimports
- misspell # Misspelled English words in comments
- mnd
- gofmt # Whether the code was gofmt-ed
- goimports # Unused imports
- revive
- unconvert
- wastedassign # Finds wasted assignment statements
- unconvert # Unnecessary type conversions
- prealloc # Finds slice declarations that could potentially be pre-allocated
- predeclared # Finds code that shadows one of Go's predeclared identifiers
- nolintlint # Ill-formed or insufficient nolint directives
- makezero # Finds slice declarations with non-zero initial length
- importas # Enforces consistent import aliases
- dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
- errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- goconst # Repeated strings that could be replaced by a constant
- forcetypeassert # Finds forced type assertions
- tparallel # Detects inappropriate usage of t.Parallel() method in your Go test codes
- thelper # Detects golang test helpers without t.Helper() call and checks the consistency of test helpers
- errcheck # Errcheck is a go lint rule for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- lll # Long lines

linters-settings:
revive:
rules:
- name: exported
arguments:
- disableStutteringCheck
goconst:
min-len: 4
min-occurrences: 3

issues:
exclude-rules:
- path: _test\.go
linters:
- gosec
- lll
exclude-dirs:
- test
include:
- EXC0012 # EXC0012 revive: Annoying issue about not having a comment. The rare codebase has such comments
- EXC0014 # EXC0014 revive: Annoying issue about not having a comment. The rare codebase has such comments
Expand Down
10 changes: 10 additions & 0 deletions .mockery.yml
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added by v0.2.1 0xPolygon/zkevm-ethtx-manager.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
with-expecter: true
dir: "mocks"
filename: "{{.InterfaceName | lower }}.generated.go"
mockname: "{{.InterfaceName}}"
outpkg: "mocks"
packages:
github.com/0xPolygon/zkevm-ethtx-manager/types:
interfaces:
EthermanInterface:
config:
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,31 @@ check-go:
check-curl:
@which curl > /dev/null || (echo "Error: curl is not installed" && exit 1)

.PHONY: check-mockery
check-mockery:
@which mockery > /dev/null || (echo "Error: mockery is not installed" && exit 1)

# Targets that require the checks
build: check-go
lint: check-go
install-linter: check-go check-curl

.PHONY: install-linter
install-linter: ## Installs the linter
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.54.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.59.1

.PHONY: lint
lint: ## Runs the linter
export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/golangci-lint run

.PHONY: test-unit
test-unit:
trap '$(STOP)' EXIT; MallocNanoZone=0 go test -count=1 -short -race -p 1 -covermode=atomic -coverprofile=coverage.out -coverpkg ./... -timeout 200s ./...

.PHONY: generate-mocks
generate-mocks: ## Generates mocks and other autogenerated types
mockery

## Help display.
## Pulls comments from beside commands and prints a nicely formatted
## display with the commands and their usage information.
Expand Down
41 changes: 41 additions & 0 deletions common/common.go
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added by v0.2.1 0xPolygon/zkevm-ethtx-manager.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package common

import "github.com/ethereum/go-ethereum/common"

const (
// Base10 decimal base
Base10 = 10
// Gwei represents 1000000000 wei
Gwei = 1000000000

// SQLLiteDriverName is the name for the SQL lite driver
SQLLiteDriverName = "sqlite3"
)

// ToAddressPtr converts a string to a common.Address pointer or returns nil if empty.
func ToAddressPtr(addr string) *common.Address {
if addr == "" {
return nil
}

address := common.HexToAddress(addr)
return &address
}

// ToUint64Ptr is a helper to create uint64 pointer
func ToUint64Ptr(v uint64) *uint64 {
return &v
}

// SlicePtrsToSlice converts a slice of pointers to a slice of values.
func SlicePtrsToSlice[T any](ptrSlice []*T) []T {
// Create a new slice to hold the values
res := make([]T, len(ptrSlice))
// Dereference each pointer and add the value to the result slice
for i, ptr := range ptrSlice {
if ptr != nil {
res[i] = *ptr
}
}
return res
}
15 changes: 0 additions & 15 deletions config/types/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package types

import (
"time"

"github.com/invopop/jsonschema"
)

// Duration is a wrapper type that parses time duration from text.
Expand All @@ -25,16 +23,3 @@ func (d *Duration) UnmarshalText(data []byte) error {
func NewDuration(duration time.Duration) Duration {
return Duration{duration}
}

// JSONSchema returns a custom schema to be used for the JSON Schema generation of this type
func (Duration) JSONSchema() *jsonschema.Schema {
return &jsonschema.Schema{
Type: "string",
Title: "Duration",
Description: "Duration expressed in units: [ns, us, ms, s, m, h, d]",
Examples: []interface{}{
"1m",
"300ms",
},
}
}
110 changes: 0 additions & 110 deletions encoding/encoding.go

This file was deleted.

2 changes: 1 addition & 1 deletion etherman/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package etherman

import (
"github.com/0xPolygonHermez/zkevm-ethtx-manager/etherman/etherscan"
"github.com/0xPolygon/zkevm-ethtx-manager/etherman/etherscan"
"github.com/ethereum/go-ethereum/common"
)

Expand Down
Loading
Loading