From 7c450788e16b906b513719196ab5a69d7aa5ae02 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Thu, 18 Jul 2024 16:39:58 +0530 Subject: [PATCH 1/7] fix::> basic makefile ready --- Makefile | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..805cb33b --- /dev/null +++ b/Makefile @@ -0,0 +1,68 @@ +test: + @go test ./... + +test-verbose: + @go test ./... -v + +bench: + @go test -bench=. + +rpc-test: + @go test -v ./rpc -env [mainnet|devnet|testnet|mock] + +simple-call: + @if [ ! -f ./examples/.env ]; then \ + echo "This example calls two contract functions, with and without calldata. It uses an ERC20 token, but it can be any smart contract.\n"; \ + echo "Steps:\n"; \ + echo " - Rename the '.env.template' file located at the root of the 'examples' folder to '.env'"; \ + echo " - Uncomment, and assign your Sepolia testnet endpoint to the RPC_PROVIDER_URL variable in the '.env' file"; \ + echo " - Uncomment, and assign your account address to the ACCOUNT_ADDRESS variable in the '.env' file"; \ + echo " - Execute "; \ + echo "The calls outputs will be returned at the end of the execution."; \ + else \ + go run ./examples/simpleCall/main.go; \ + fi + +deploy-account: + @if [ ! -f ./examples/.env ]; then \ + echo "This example uses a pre-existing class on the Sepolia network to deploy a new account contract. To successfully run this example, you will need: 1) a Sepolia endpoint, and 2) some Sepolia ETH to fund the precomputed address.\n"; \ + echo "Steps:\n"; \ + echo " - Rename the '.env.template' file located at the root of the 'examples' folder to '.env'"; \ + echo " - Uncomment, and assign your Sepolia testnet endpoint to the RPC_PROVIDER_URL variable in the '.env' file"; \ + echo " - Execute "; \ + echo " - Fund the precomputed address using a starknet faucet, eg https://starknet-faucet.vercel.app/"; \ + echo " - Press any key, then enter"; \ + echo "At this point your account should be deployed on testnet, and you can use a block explorer like Voyager to view your transaction using the transaction hash."; \ + else \ + go run ./examples/deployAccount/main.go; \ + fi + +simple-invoke: + @if [ ! -f ./examples/.env ]; then \ + echo "This example sends an invoke transaction with calldata. It uses an ERC20 token, but it can be any smart contract.\n"; \ + echo "Steps:\n"; \ + echo " - Rename the '.env.template' file located at the root of the 'examples' folder to '.env'"; \ + echo " - Uncomment, and assign your Sepolia testnet endpoint to the RPC_PROVIDER_URL variable in the '.env' file"; \ + echo " - Uncomment, and assign your account address to the ACCOUNT_ADDRESS variable in the '.env' file (make sure to have a few ETH in it)"; \ + echo " - Uncomment, and assign your starknet public key to the PUBLIC_KEY variable in the '.env' file"; \ + echo " - Uncomment, and assign your private key to the PRIVATE_KEY variable in the '.env' file"; \ + echo " - Execute ; \ + echo "The transaction hash and status will be returned at the end of the execution."; \ + else \ + go run ./examples/simpleInvoke/main.go; \ + fi + +deploy-contractUDC: + @if [ ! -f ./examples/.env ]; then \ + echo "This example deploys an ERC20 token using the UDC (Universal Deployer Contract) smart contract.\n"; \ + echo "Steps:\n"; \ + echo " - Rename the '.env.template' file located at the root of the 'examples' folder to '.env'"; \ + echo " - Uncomment, and assign your Sepolia testnet endpoint to the RPC_PROVIDER_URL variable in the '.env' file"; \ + echo " - Uncomment, and assign your account address to the ACCOUNT_ADDRESS variable in the '.env' file (make sure to have a few ETH in it)"; \ + echo " - Uncomment, and assign your starknet public key to the PUBLIC_KEY variable in the '.env' file"; \ + echo " - Uncomment, and assign your private key to the PRIVATE_KEY variable in the '.env' file"; \ + echo " - Execute "; \ + echo "The transaction hash and status will be returned at the end of the execution."; \ + else \ + go run ./examples/deployContractUDC/main.go; \ + fi From 4dfe63b5b34657be0a88c52dd7c643da0d4402e0 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Thu, 18 Jul 2024 22:11:56 +0530 Subject: [PATCH 2/7] fix::> Make file updated for linters and formatters --- Makefile | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 805cb33b..3daa3674 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,32 @@ test: - @go test ./... - -test-verbose: @go test ./... -v +rpc-test: + @go test -v ./rpc -env [mainnet|devnet|testnet|mock] + bench: @go test -bench=. -rpc-test: - @go test -v ./rpc -env [mainnet|devnet|testnet|mock] +install-deps: | install-gofumpt install-mockgen install-golangci-lint + +install-gofumpt: + go install mvdan.cc/gofumpt@latest + +install-mockgen: + go install go.uber.org/mock/mockgen@latest + +install-golangci-lint: + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 + +lint: + @which golangci-lint || make install-golangci-lint + golangci-lint run + +tidy: + go mod tidy + +format: + gofumpt -l -w . simple-call: @if [ ! -f ./examples/.env ]; then \ From f2d542cb391c295b4350a113c41128b3dcaacca8 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Thu, 18 Jul 2024 22:12:15 +0530 Subject: [PATCH 3/7] fix::> golangci yaml template ready --- .golangci.yaml | 166 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 .golangci.yaml diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 00000000..afa92713 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,166 @@ +linters-settings: + depguard: + rules: + logger: + deny: + - pkg: github.com/sirupsen/logrus + desc: use github.com/NethermindEth/starknet.go/utils for logging + dupl: + threshold: 100 + funlen: + lines: 120 + statements: 50 + goconst: + min-len: 2 + min-occurrences: 3 + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + disabled-checks: + - sloppyReassign + - dupImport # https://github.com/go-critic/go-critic/issues/845 + - ifElseChain + - octalLiteral + - whyNoLint + - unnamedResult + gocyclo: + min-complexity: 15 + goimports: + local-prefixes: github.com/golangci/golangci-lint + mnd: + # don't include the "operation" and "assign" + checks: + - argument + - case + - condition + - return + ignored-numbers: + - "0" + - "1" + - "2" + - "3" + ignored-functions: + - strings.SplitN + + govet: + shadow: true + settings: + printf: + funcs: + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + lll: + line-length: 140 + misspell: + locale: UK + nolintlint: + allow-unused: false # report any unused nolint directives + require-explanation: false # don't require an explanation for nolint directives + require-specific: false # don't require nolint directives to be specific about which linter is being skipped + + exhaustruct: + include: [] + +linters: + disable-all: true + enable: + - bodyclose + - depguard + - dogsled + - dupl + - errcheck + - exportloopref + - funlen + - gochecknoinits + - goconst + - gocritic + - gocyclo + - gofumpt + - mnd + - goprintffuncname + - gosec + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - nilerr + - noctx + - nolintlint + - staticcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - usestdlibvars + - whitespace + - tparallel + - gci + - exhaustruct + + # don't enable: + # - asciicheck + # - scopelint + # - gochecknoglobals + # - gocognit + # - godot + # - godox + # - goerr113 + # - interfacer + # - maligned + # - nestif + # - prealloc + # - testpackage + # - revive + # - wsl + +issues: + # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + - path: _test\.go + linters: + - mnd + - funlen + - lll + - gosec + - exhaustruct + + # - path-except: 'adapters/.+\.go' # run specified linters only on files that reside inside adapters + # linters: + # - exhaustruct + + - linters: + - lll + source: "^//go:generate " + + - path: pkg/golinters/errcheck.go + text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead" + - path: pkg/commands/run.go + text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead" + - path: pkg/commands/run.go + text: "SA1019: e.cfg.Run.Deadline is deprecated: Deadline exists for historical compatibility and should not be used." + + - path: pkg/golinters/gofumpt.go + text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead." + - path: pkg/golinters/staticcheck_common.go + text: "SA1019: settings.GoVersion is deprecated: use the global `run.go` instead." + - path: pkg/lint/lintersdb/manager.go + text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead." + - path: pkg/golinters/unused.go + text: "rangeValCopy: each iteration copies 160 bytes \\(consider pointers or indexing\\)" + exclude-dirs: + - test/testdata_etc # test files + - internal/cache # extracted from Go code + - internal/renameio # extracted from Go code + - internal/robustio # extracted from Go code + +run: + timeout: 5m \ No newline at end of file From b95bdbae0adf893e57dcfb957d00a0d8a827b3b9 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Tue, 23 Jul 2024 23:31:36 +0530 Subject: [PATCH 4/7] fix::> Makefile devnet code added --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 3daa3674..eb5962b9 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,9 @@ test: rpc-test: @go test -v ./rpc -env [mainnet|devnet|testnet|mock] +devnet-test: + @go test ./... -env devnet -v + bench: @go test -bench=. From d76726194a9e43d2ae95e064283e586ee6d70704 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Tue, 23 Jul 2024 23:54:52 +0530 Subject: [PATCH 5/7] fix::> basic linter config ready --- .golangci.yaml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index afa92713..ab28524c 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -47,7 +47,6 @@ linters-settings: - strings.SplitN govet: - shadow: true settings: printf: funcs: @@ -106,22 +105,6 @@ linters: - gci - exhaustruct - # don't enable: - # - asciicheck - # - scopelint - # - gochecknoglobals - # - gocognit - # - godot - # - godox - # - goerr113 - # - interfacer - # - maligned - # - nestif - # - prealloc - # - testpackage - # - revive - # - wsl - issues: # Excluding configuration per-path, per-linter, per-text and per-source exclude-rules: From 1addeacc4099df91a4e07b2833545f302e30f695 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Wed, 24 Jul 2024 00:07:39 +0530 Subject: [PATCH 6/7] fix::> linter working --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index eb5962b9..b9c3b982 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,8 @@ install-golangci-lint: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 lint: - @which golangci-lint || make install-golangci-lint - golangci-lint run + @command -v golangci-lint >/dev/null 2>&1 || { echo >&2 "golangci-lint not installed. Run 'make install-golangci-lint' to install it."; exit 1; } + @golangci-lint run tidy: go mod tidy From 30ef04bd5bc70263ae11064faedf9506a731895b Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Wed, 24 Jul 2024 09:12:27 +0530 Subject: [PATCH 7/7] fix::> changes in setup of lint --- Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b9c3b982..d14b1f8f 100644 --- a/Makefile +++ b/Makefile @@ -18,11 +18,17 @@ install-gofumpt: install-mockgen: go install go.uber.org/mock/mockgen@latest +GOPATH := $(shell go env GOPATH) +GOBIN := $(GOPATH)/bin + install-golangci-lint: - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 + @echo "Adding $(GOBIN) to PATH" + @export PATH=$(GOBIN):$$PATH && golangci-lint --version + @echo $PATH | grep go/bin -lint: - @command -v golangci-lint >/dev/null 2>&1 || { echo >&2 "golangci-lint not installed. Run 'make install-golangci-lint' to install it."; exit 1; } +lint: install-golangci-lint + @echo "Running golangci-lint" @golangci-lint run tidy: