diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 00000000..ab28524c --- /dev/null +++ b/.golangci.yaml @@ -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 \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..d14b1f8f --- /dev/null +++ b/Makefile @@ -0,0 +1,95 @@ +test: + @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/golangci-lint@v1.59.1 + @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: + @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