Skip to content

Commit

Permalink
Merge dev into upstream v0.2.1 (#8)
Browse files Browse the repository at this point in the history
* option to avoid gas estimationi

* Quality Gate (0xPolygon#61)

* add linters

* fix: lint fix

* fix: lint make file

* feat: sonar

* fix: remove unused files

* try to include coverage

* fix: change sonar cloud project key

* small fix

* fix: comments

---------

Co-authored-by: Rachit Sonthalia <[email protected]>

* ensure tx order (0xPolygon#64)

* ensure tx order

* fix: linter

* change namespace (0xPolygon#65)

* fix nonce too low (0xPolygon#67)

* Nonce too low issues fix (0xPolygon#75)

* Serial nonce update (0xPolygon#74)

* feat: prepare txns before routines

* fix: remove forcedNonce feature

* feat: uts

* fix: lint

* lint fix

---------

Co-authored-by: Goran Rojovic <[email protected]>
Co-authored-by: Goran Rojovic <[email protected]>

* feat: implement SQL lite storage (0xPolygon#72)

* feat: initial scaffolding

* feat: insert implementation

* feat: change column types based on the SQL lite supported types

* feat: changed schema, first version of CRUD operations implementation

* refactor: extract common parts to helper functions

* chore: add comments

* fix: linter config warning

* refactor: simplify in-memory storage and fix deadlocks in case of errors

* feat: instantiate either in memory or sql storage

* chore: add comment

* test: fully covered memstorage feat minor renames

* feat: add github.com/mattn/go-sqlite3 as direct dependency

* fix: adapt the DB schema, fix issues and add unit tests for sql storage

* feat: increase coverage

* test: add some more unit tests

* fix: group variables

* refactor: rename PersistenceFilename config parameter

* fix: rename helper function (address comment part 1)

* feat: introduce meddler

* chore: remove useless comments

* fix: revert update logic to manually constructing SQL and address comments from @joanestebanr (part 1)

* fix: change some columns types (address comment from @joanestebanr 2nd part)

* fix: use meddler to construct on fly update statement, address comments from @joanestebanr (part 3)

* feat: remove in memory storage, change block_number to BIGINT (address @joanestebanr part 4)

* fix: remove redundant code

* feat: simplify building of UPDATE clause

* rebase fix

* refactor: build base select and base delete statement dynamically (address comment from @arnaubennassar)

* test: concurrent write to the database unit test

---------

Co-authored-by: Goran Rojovic <[email protected]>

* Rename config parameter `DBPath` to `StoragePath` (0xPolygon#77)

* fix if a tx is finalized very fast (0xPolygon#84)

* fix

* comment

* # This is a combination of 3 commits.
# This is the 1st commit message:

Merge `dev` into upstream v0.2.1

# This is the commit message #2:

Fix lint errs

# This is the commit message #3:

Comment interface method

* parent 4da7722
author Vui-Chee <[email protected]> 1731548943 +0800
committer Vui-Chee <[email protected]> 1731548943 +0800

parent 1b8de9d
author Vui-Chee <[email protected]> 1731476344 +0800
committer Vui-Chee <[email protected]> 1731548582 +0800

Merge `dev` into upstream v0.2.1

Fix lint errs

Comment interface method

Fix configure (#3)

* fix configure

* keep the same with genesis

Silence sonar cloud

go mod tidy

Add back hex ut to keep consistent with `dev`

---------

Co-authored-by: Arnau <[email protected]>
Co-authored-by: Goran Rojovic <[email protected]>
Co-authored-by: Rachit Sonthalia <[email protected]>
Co-authored-by: Toni Ramírez <[email protected]>
Co-authored-by: Stefan Negovanović <[email protected]>
Co-authored-by: Goran Rojovic <[email protected]>
Co-authored-by: Alonso Rodriguez <[email protected]>
  • Loading branch information
8 people authored Nov 14, 2024
1 parent 6018d38 commit 4891711
Show file tree
Hide file tree
Showing 47 changed files with 3,928 additions and 1,179 deletions.
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
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
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

0 comments on commit 4891711

Please sign in to comment.