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

Makefile for starknet.go #598

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
149 changes: 149 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
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:
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

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
95 changes: 95 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
test:
PsychoPunkSage marked this conversation as resolved.
Show resolved Hide resolved
@go test ./... -v

rpc-test:
@go test -v ./rpc -env [mainnet|devnet|testnet|mock]

devnet-test:
@go test ./... -env devnet -v

bench:
@go test -bench=.

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

GOPATH := $(shell go env GOPATH)
GOBIN := $(GOPATH)/bin

install-golangci-lint:
@go install github.com/golangci/golangci-lint/cmd/[email protected]
@echo "Adding $(GOBIN) to PATH"
@export PATH=$(GOBIN):$$PATH && golangci-lint --version
@echo $PATH | grep go/bin

lint: install-golangci-lint
@echo "Running golangci-lint"
@golangci-lint run

tidy:
go mod tidy

format:
gofumpt -l -w .

simple-call:
Comment on lines +39 to +40
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should run examples in the make file

Copy link
Contributor Author

@PsychoPunkSage PsychoPunkSage Jul 18, 2024

Choose a reason for hiding this comment

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

I think It would be a good option to have it.
I have made sure that if the developer haven't set the environment correctly, then the correct procedure to run the examples will be printed in the terminal
like this::>
image

@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 <make simple-call>"; \
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 <make deploy-account>"; \
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 <make simple-invoke>; \
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 <make deploy-contractUDC>"; \
echo "The transaction hash and status will be returned at the end of the execution."; \
else \
go run ./examples/deployContractUDC/main.go; \
fi
Loading