From 46cab5a31f37a572fc75a997ce5f600483628033 Mon Sep 17 00:00:00 2001 From: leovct Date: Mon, 3 Jul 2023 12:12:53 +0200 Subject: [PATCH 1/3] chore: move client-related targets to another makefile --- Makefile | 32 ++------------------------------ scripts/clients.mk | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 30 deletions(-) create mode 100644 scripts/clients.mk diff --git a/Makefile b/Makefile index 22ec848f..7c4c42ee 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ +include scripts/clients.mk +.DEFAULT_GOAL := help INSTALL_DIR:=~/go/bin -BIN_DIR=./bin BIN_NAME:=polycli BUILD_DIR:=./out @@ -86,38 +87,9 @@ golangci-lint: ## Run golangci-lint against code. .PHONY: lint lint: tidy vet golangci-lint ## Run all the linter tools against code. -##@ Clients -PORT?=8545 - -.PHONY: $(BIN_DIR) -$(BIN_DIR): ## Create the binary folder. - mkdir -p $(BIN_DIR) - -.PHONY: geth -geth: $(BIN_DIR) ## Start a local geth node. - geth --dev --dev.period 2 --http --http.addr localhost --http.port $(PORT) --http.api admin,debug,web3,eth,txpool,personal,miner,net --verbosity 5 --rpc.gascap 50000000 --rpc.txfeecap 0 --miner.gaslimit 10 --miner.gasprice 1 --gpo.blocks 1 --gpo.percentile 1 --gpo.maxprice 10 --gpo.ignoreprice 2 --dev.gaslimit 50000000 - -.PHONY: avail -avail: $(BIN_DIR) ## Start a local avail node. - avail --dev --rpc-port $(PORT) - ##@ Test .PHONY: test test: ## Run tests. go test ./... -coverprofile=coverage.out go tool cover -func coverage.out - -LOADTEST_ACCOUNT=0x85da99c8a7c2c95964c8efd687e95e632fc533d6 -LOADTEST_FUNDING_AMOUNT_ETH=5000 -eth_coinbase := $(shell curl -s -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "id": 2, "method": "eth_coinbase", "params": []}' http://127.0.0.1:${PORT} | jq -r ".result") -hex_funding_amount := $(shell echo "obase=16; ${LOADTEST_FUNDING_AMOUNT_ETH}*10^18" | bc) -.PHONY: geth-loadtest -geth-loadtest: build ## Fund test account with 5k ETH and run loadtest against an EVM/Geth chain. - curl -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "method":"eth_sendTransaction", "params":[{"from": "${eth_coinbase}","to": "${LOADTEST_ACCOUNT}","value": "0x${hex_funding_amount}"}], "id":1}' http://127.0.0.1:${PORT} - sleep 5 - $(BUILD_DIR)/$(BIN_NAME) loadtest --verbosity 700 --chain-id 1337 --concurrency 1 --requests 1000 --rate-limit 5 --mode c http://127.0.0.1:$(PORT) - -.PHONY: avail-loadtest -avail-loadtest: build ## Run loadtest against an Avail chain. - $(BUILD_DIR)/$(BIN_NAME) loadtest --verbosity 700 --chain-id 1256 --concurrency 1 --requests 1000 --rate-limit 5 --mode t --data-avail http://127.0.0.1:$(PORT) diff --git a/scripts/clients.mk b/scripts/clients.mk new file mode 100644 index 00000000..5235c415 --- /dev/null +++ b/scripts/clients.mk @@ -0,0 +1,24 @@ +##@ Clients +PORT?=8545 + +.PHONY: geth +geth: ## Start a local geth node. + geth --dev --dev.period 2 --http --http.addr localhost --http.port $(PORT) --http.api admin,debug,web3,eth,txpool,personal,miner,net --verbosity 5 --rpc.gascap 50000000 --rpc.txfeecap 0 --miner.gaslimit 10 --miner.gasprice 1 --gpo.blocks 1 --gpo.percentile 1 --gpo.maxprice 10 --gpo.ignoreprice 2 --dev.gaslimit 50000000 + +.PHONY: avail +avail: ## Start a local avail node. + avail --dev --rpc-port $(PORT) + +LOADTEST_ACCOUNT=0x85da99c8a7c2c95964c8efd687e95e632fc533d6 +LOADTEST_FUNDING_AMOUNT_ETH=5000 +eth_coinbase := $(shell curl -s -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "id": 2, "method": "eth_coinbase", "params": []}' http://127.0.0.1:${PORT} | jq -r ".result") +hex_funding_amount := $(shell echo "obase=16; ${LOADTEST_FUNDING_AMOUNT_ETH}*10^18" | bc) +.PHONY: geth-loadtest +geth-loadtest: build ## Fund test account with 5k ETH and run loadtest against an EVM/Geth chain. + curl -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "method":"eth_sendTransaction", "params":[{"from": "${eth_coinbase}","to": "${LOADTEST_ACCOUNT}","value": "0x${hex_funding_amount}"}], "id":1}' http://127.0.0.1:${PORT} + sleep 5 + $(BUILD_DIR)/$(BIN_NAME) loadtest --verbosity 700 --chain-id 1337 --concurrency 1 --requests 1000 --rate-limit 5 --mode c http://127.0.0.1:$(PORT) + +.PHONY: avail-loadtest +avail-loadtest: build ## Run loadtest against an Avail chain. + $(BUILD_DIR)/$(BIN_NAME) loadtest --verbosity 700 --chain-id 1256 --concurrency 1 --requests 1000 --rate-limit 5 --mode t --data-avail http://127.0.0.1:$(PORT) From 8407aa529d298f7427ccbf6060b6fde8d995ba0e Mon Sep 17 00:00:00 2001 From: leovct Date: Mon, 3 Jul 2023 12:15:48 +0200 Subject: [PATCH 2/3] chore: simplify `Makefile` and hide some test targets from the help --- Makefile | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 7c4c42ee..eeba4ff5 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ include scripts/clients.mk .DEFAULT_GOAL := help -INSTALL_DIR:=~/go/bin -BIN_NAME:=polycli -BUILD_DIR:=./out +INSTALL_DIR := ~/go/bin +BIN_NAME := polycli +BUILD_DIR := ./out -GIT_SHA:=$(shell git rev-parse HEAD | cut -c 1-8) -GIT_TAG:=$(shell git describe --tags) -CUR_DATE:=$(shell date +%s) +GIT_SHA := $(shell git rev-parse HEAD | cut -c 1-8) +GIT_TAG := $(shell git describe --tags) +CUR_DATE := $(shell date +%s) -# strip debug and suppress warnings +# Strip debug and supress warnings. LD_FLAGS=-s -w LD_FLAGS += -X \"github.com/maticnetwork/polygon-cli/cmd/version.Version=$(GIT_TAG)\" LD_FLAGS += -X \"github.com/maticnetwork/polygon-cli/cmd/version.Commit=$(GIT_SHA)\" @@ -45,7 +45,7 @@ install: build ## Install the go binary. cross: $(BUILD_DIR) ## Cross-compile go binaries using CGO. env CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -ldflags "$(STATIC_LD_FLAGS)" -tags netgo -o $(BUILD_DIR)/linux-arm64-$(BIN_NAME) main.go env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags "$(STATIC_LD_FLAGS)" -tags netgo -o $(BUILD_DIR)/linux-amd64-$(BIN_NAME) main.go - # mac builds - this will be functional but will still have secp issues + # MAC builds - this will be functional but will still have secp issues. env GOOS=darwin GOARCH=arm64 go build -ldflags "$(LD_FLAGS)" -tags netgo -o $(BUILD_DIR)/darwin-arm64-$(BIN_NAME) main.go env GOOS=darwin GOARCH=amd64 go build -ldflags "$(LD_FLAGS)" -tags netgo -o $(BUILD_DIR)/darwin-amd64-$(BIN_NAME) main.go @@ -62,30 +62,33 @@ clean: ## Clean the binary folder. ##@ Lint +# Add missing and remove unused modules. .PHONY: tidy -tidy: ## Add missing and remove unused modules. +tidy: go mod tidy +# Run `go fmt` against code. .PHONY: fmt -fmt: ## Run go fmt against code. +fmt: go fmt ./... -# shadow reports shadowed variables +# Run `go vet` and `shadow` (which reports shadowed variables) against code. # https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/shadow -# go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest +# `go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest` .PHONY: vet -vet: ## Run go vet and shadow against code. +vet: go vet ./... shadow ./... -# golangci-lint runs gofmt, govet, staticcheck and other linters +# Run `golangci-lint` against code. +# `golangci-lint` runs `gofmt`, `govet`, `staticcheck` and other linters. # https://golangci-lint.run/usage/install/#local-installation .PHONY: golangci-lint -golangci-lint: ## Run golangci-lint against code. +golangci-lint: golangci-lint run --fix --timeout 5m .PHONY: lint -lint: tidy vet golangci-lint ## Run all the linter tools against code. +lint: tidy vet golangci-lint ## Run linters. ##@ Test From cfe1a4312c6bce28d5e100be1f7bcffec1c6992e Mon Sep 17 00:00:00 2001 From: leovct Date: Mon, 3 Jul 2023 12:20:31 +0200 Subject: [PATCH 3/3] chore: move lint targets to a sub Makefile --- Makefile | 31 +------------------------------ scripts/lint.mk | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 30 deletions(-) create mode 100644 scripts/lint.mk diff --git a/Makefile b/Makefile index eeba4ff5..1e286588 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +include scripts/lint.mk include scripts/clients.mk .DEFAULT_GOAL := help @@ -60,36 +61,6 @@ simplecross: $(BUILD_DIR) ## Cross-compile go binaries without using CGO. clean: ## Clean the binary folder. $(RM) -r $(BUILD_DIR) -##@ Lint - -# Add missing and remove unused modules. -.PHONY: tidy -tidy: - go mod tidy - -# Run `go fmt` against code. -.PHONY: fmt -fmt: - go fmt ./... - -# Run `go vet` and `shadow` (which reports shadowed variables) against code. -# https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/shadow -# `go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest` -.PHONY: vet -vet: - go vet ./... - shadow ./... - -# Run `golangci-lint` against code. -# `golangci-lint` runs `gofmt`, `govet`, `staticcheck` and other linters. -# https://golangci-lint.run/usage/install/#local-installation -.PHONY: golangci-lint -golangci-lint: - golangci-lint run --fix --timeout 5m - -.PHONY: lint -lint: tidy vet golangci-lint ## Run linters. - ##@ Test .PHONY: test diff --git a/scripts/lint.mk b/scripts/lint.mk new file mode 100644 index 00000000..e34e9ae0 --- /dev/null +++ b/scripts/lint.mk @@ -0,0 +1,29 @@ +##@ Lint + +# Add missing and remove unused modules. +.PHONY: tidy +tidy: + go mod tidy + +# Run `go fmt` against code. +.PHONY: fmt +fmt: + go fmt ./... + +# Run `go vet` and `shadow` (which reports shadowed variables) against code. +# https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/shadow +# `go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest` +.PHONY: vet +vet: + go vet ./... + shadow ./... + +# Run `golangci-lint` against code. +# `golangci-lint` runs `gofmt`, `govet`, `staticcheck` and other linters. +# https://golangci-lint.run/usage/install/#local-installation +.PHONY: golangci-lint +golangci-lint: + golangci-lint run --fix --timeout 5m + +.PHONY: lint +lint: tidy vet golangci-lint ## Run linters.