diff --git a/Makefile b/Makefile index 744505942..1e88c025e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,29 @@ #!/usr/bin/make -f +include scripts/makefiles/build.mk +include scripts/makefiles/docker.mk +include scripts/makefiles/lint.mk +include scripts/makefiles/proto.mk +include scripts/makefiles/test.mk +include tests/e2e/Makefile + +.DEFAULT_GOAL := help +help: + @echo "Available top-level commands:" + @echo "" + @echo "Usage:" + @echo " make [command]" + @echo "" + @echo " make build Build quasarnoded binary" + @echo " make build-help Show available build commands" + @echo " make docker Show available docker commands" + @echo " make e2e Show available e2e commands" + @echo " make install Install quasarnoded binary" + @echo " make lint Show available lint commands" + @echo " make test Show available test commands" + @echo "" + @echo "Run 'make [subcommand]' to see the available commands for each subcommand." + VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//') COMMIT := $(shell git log -1 --format='%H') LEDGER_ENABLED ?= true @@ -7,27 +31,18 @@ SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g') GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2) DOCKER := $(shell which docker) GOMOD := $(shell go list -m) +GO_MODULE := $(shell cat go.mod | grep "module " | cut -d ' ' -f 2) +GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1) +GO_MINOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) +# minimum supported Go version +GO_MINIMUM_MAJOR_VERSION = $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f2 | cut -d'.' -f1) +GO_MINIMUM_MINOR_VERSION = $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f2 | cut -d'.' -f2) + BUILDDIR ?= $(CURDIR)/build MOCKSDIR = $(CURDIR)/testutil/mock export GO111MODULE = on -## Helper function to show help with `make` or `make help` - -.DEFAULT_GOAL := help - -HELP_FUN = \ - %help; while(<>){push@{$$help{$$2//'targets'}},[$$1,$$3] \ - if/^([\w-_]+)\s*:.*\#\#(?:@(\w+))?\s(.*)$$/}; \ - print"$$_:\n", map" $$_->[0]".(" "x(40-length($$_->[0])))."$$_->[1]\n",\ - @{$$help{$$_}},"\n" for keys %help; \ - -help: ##@misc Show this help - @echo "Usage: make [target] ...\n" - @perl -e '$(HELP_FUN)' $(MAKEFILE_LIST) - - - # process build tags build_tags = netgo @@ -106,97 +121,48 @@ ifeq (,$(findstring nostrip,$(QUASAR_BUILD_OPTIONS))) endif ############################################################################### -### Build ### +### Build & Install ### ############################################################################### -all: install lint test - -BUILD_TARGETS := build install -#BUILD_TARGETS_DEBUG := build install -build: BUILD_ARGS=-o $(BUILDDIR)/ +update-deps: + @go mod tidy; -$(BUILD_TARGETS): go.sum $(BUILDDIR)/ - go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./cmd/quasarnoded +build: build-check-version go.sum + # back up before build + @cp go.mod go.mod.backup + @cp go.sum go.sum.backup + @go mod tidy -$(BUILD_TARGETS_DEBUG): go.sum $(BUILDDIR)/ - go $@ -mod=readonly $(BUILD_FLAGS_DEBUG) -gcflags='all=-N -l' $(BUILD_ARGS) ./cmd/quasarnoded - -$(BUILDDIR)/: mkdir -p $(BUILDDIR)/ + GOWORK=off go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ $(GO_MODULE)/cmd/quasarnoded -# Cross-building for arm64 from amd64 (or viceversa) takes -# a lot of time due to QEMU virtualization but it's the only way (afaik) -# to get a statically linked binary with CosmWasm - -build-reproducible: build-reproducible-amd64 build-reproducible-arm64 + # clean up before install + @mv go.mod.backup go.mod + @mv go.sum.backup go.sum + @rm -f go.mod.bak + @go mod tidy -build-reproducible-amd64: $(BUILDDIR)/ - $(DOCKER) buildx create --name quasarbuilder || true - $(DOCKER) buildx use quasarbuilder - $(DOCKER) buildx build \ - --build-arg GO_VERSION=$(GO_VERSION) \ - --build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_DISTROLESS) \ - --build-arg GIT_VERSION=$(VERSION) \ - --build-arg GIT_COMMIT=$(COMMIT) \ - --platform linux/amd64 \ - -t quasar-amd64 \ - --load \ - -f Dockerfile . - $(DOCKER) rm -f quasarbinary || true - $(DOCKER) create -ti --name quasarbinary quasar-amd64 - $(DOCKER) cp quasarbinary:/bin/quasarnoded $(BUILDDIR)/quasarnoded-linux-amd64 - $(DOCKER) rm -f quasarbinary +install: build-check-version go.sum + # back up before build + @cp go.mod go.mod.backup + @cp go.sum go.sum.backup + @go mod tidy -build-reproducible-arm64: $(BUILDDIR)/ - $(DOCKER) buildx create --name quasarbuilder || true - $(DOCKER) buildx use quasarbuilder - $(DOCKER) buildx build \ - --build-arg GO_VERSION=$(GO_VERSION) \ - --build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_DISTROLESS) \ - --build-arg GIT_VERSION=$(VERSION) \ - --build-arg GIT_COMMIT=$(COMMIT) \ - --platform linux/arm64 \ - -t quasar-arm64 \ - --load \ - -f Dockerfile . - $(DOCKER) rm -f quasarbinary || true - $(DOCKER) create -ti --name quasarbinary quasar-arm64 - $(DOCKER) cp quasarbinary:/bin/quasarnoded $(BUILDDIR)/quasarnoded-linux-arm64 - $(DOCKER) rm -f quasarbinary + GOWORK=off go install -mod=readonly $(BUILD_FLAGS) $(GO_MODULE)/cmd/quasarnoded -build-linux: go.sum - LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build - -go.sum: go.mod - @echo "--> Ensure dependencies have not been modified" - @go mod verify + # clean up before install + @mv go.mod.backup go.mod + @mv go.sum.backup go.sum + @rm -f go.mod.bak + @go mod tidy ############################################################################### -### Proto & Mock Generation ### +### Go Mock ### ############################################################################### -proto-all: proto-format proto-gen -BUF_VERSION=1.26.1 -BUILDER_VERSION=0.13.5 -proto-gen: - @echo "Generating Protobuf files" - @sh ./scripts/protocgen.sh - -proto-gen-1: - @echo "🤖 Generating code from protobuf..." - @echo "PWD is $(PWD)" - - @docker run --rm --volume "$(PWD)":/workspace --workdir /workspace \ - ghcr.io/cosmos/proto-builder:$(BUILDER_VERSION) sh ./scripts/protocgen.sh - @echo "✅ Completed code generation!" - -proto-doc: - @echo "Generating Protoc docs" - @sh ./scripts/generate-docs.sh - -.PHONY: proto-gen proto-doc - -mocks: $(MOCKSDIR)/ +# todo : need ideas on external libraries +# example : mockgen -source=/path/to/go/pkg/mod/github.com/cosmos/ibc-go/v7@v7.4.0/modules/core/05-port/types/module.go -destination=/path/to/quasar/mock/ics4_wrapper_mocks.go -package=mock -mock_names=MockICS4Wrapper +mocks: $(MOCKSDIR)/ mockgen -package=mock -destination=$(MOCKSDIR)/ibc_channel_mocks.go $(GOMOD)/x/qoracle/types ChannelKeeper # mockgen -package=mock -destination=$(MOCKSDIR)/ica_mocks.go $(GOMOD)/x/intergamm/types ICAControllerKeeper # mockgen -package=mock -destination=$(MOCKSDIR)/ibc_mocks.go $(GOMOD)/x/intergamm/types IBCTransferKeeper @@ -208,157 +174,6 @@ mocks: $(MOCKSDIR)/ $(MOCKSDIR)/: mkdir -p $(MOCKSDIR)/ -############################################################################### -### Tests & Simulation ### -############################################################################### - -PACKAGES_UNIT=$(shell go list ./x/epochs/... ./x/qoracle/... ./x/tokenfactory/... | grep -E -v "simapp|e2e" | grep -E -v "x/qoracle/client/cli") -PACKAGES_E2E=$(shell go list ./... | grep '/tests/e2e') -PACKAGES_SIM=$(shell go list ./... | grep '/tests/simulator') -TEST_PACKAGES=./... - -include tests/e2e/Makefile - -test: test-unit test-build - -test-all: check test-race test-cover - -test-unit: - @VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock norace' $(PACKAGES_UNIT) - -test-race: - @VERSION=$(VERSION) go test -mod=readonly -race -tags='ledger test_ledger_mock' $(PACKAGES_UNIT) - -test-cover: - @VERSION=$(VERSION) go test -mod=readonly -timeout 30m -coverprofile=coverage.txt -tags='norace' -covermode=atomic $(PACKAGES_UNIT) - -test-sim-suite: - @VERSION=$(VERSION) go test -mod=readonly $(PACKAGES_SIM) - -test-sim-app: - @VERSION=$(VERSION) go test -mod=readonly -run ^TestFullAppSimulation -v $(PACKAGES_SIM) - -test-sim-determinism: - @VERSION=$(VERSION) go test -mod=readonly -run ^TestAppStateDeterminism -v $(PACKAGES_SIM) - -test-sim-bench: - @VERSION=$(VERSION) go test -benchmem -run ^BenchmarkFullAppSimulation -bench ^BenchmarkFullAppSimulation -cpuprofile cpu.out $(PACKAGES_SIM) - -benchmark: - @go test -mod=readonly -bench=. $(PACKAGES_UNIT) - -############################################################################### -### Docker ### -############################################################################### - -RUNNER_BASE_IMAGE_DISTROLESS := gcr.io/distroless/static-debian11 -RUNNER_BASE_IMAGE_ALPINE := alpine:3.17 -RUNNER_BASE_IMAGE_NONROOT := gcr.io/distroless/static-debian11:nonroot - -docker-build: - @DOCKER_BUILDKIT=1 docker build \ - -t quasar:local \ - -t quasar:local-distroless \ - --build-arg GO_VERSION=$(GO_VERSION) \ - --build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_DISTROLESS) \ - --build-arg GIT_VERSION=$(VERSION) \ - --build-arg GIT_COMMIT=$(COMMIT) \ - -f Dockerfile . - -docker-build-distroless: docker-build - -docker-build-alpine: - @DOCKER_BUILDKIT=1 docker build \ - -t quasar:local-alpine \ - --build-arg GO_VERSION=$(GO_VERSION) \ - --build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_ALPINE) \ - --build-arg GIT_VERSION=$(VERSION) \ - --build-arg GIT_COMMIT=$(COMMIT) \ - -f Dockerfile . - -docker-build-nonroot: - @DOCKER_BUILDKIT=1 docker build \ - -t quasar:local-nonroot \ - --build-arg GO_VERSION=$(GO_VERSION) \ - --build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_NONROOT) \ - --build-arg GIT_VERSION=$(VERSION) \ - --build-arg GIT_COMMIT=$(COMMIT) \ - -f Dockerfile . - - -# This is not available to avoid missbehavior since it seems to be a bug in docker compose -p localenv: -# https://github.com/docker/compose/issues/10068 -# docker-compose-up-attached: ##@docker Run (and build if needed) env in docker compose. Attach if running in background. -# @echo "Launching local env with docker-compose" -# DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose -p localenv -f tests/docker/docker-compose.yml up - -docker-compose-up: ##@docker Run local env, build only if no images available - @echo "Launching local env, building images if not available" - DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose -p localenv -f tests/docker/docker-compose.yml up -d - -docker-compose-up-recreate: ##@docker DESTROY env containers and respawn them - @echo "Recreate local env (will destroy application state)" - DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose -p localenv -f tests/docker/docker-compose.yml up -d --force-recreate - -docker-compose-build: ##@docker Build new image if there are code changes, won't recreate containers. - @echo "Rebuilding image for local env" - DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose -p localenv -f tests/docker/docker-compose.yml build - -docker-compose-rebuild: docker-compose-build docker-compose-up-recreate ##@docker Recreate containers building new code if needed - @echo "Rebuilding images and restarting containers" - -docker-compose-stop: ##@docker Stop containers without deleting them - @echo "Stop docker containers without removing them" - DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose -p localenv -f tests/docker/docker-compose.yml stop - -docker-compose-down: ##@docker Stop AND DELETE delete the containers - @echo "Stopping docker containers and REMOVING THEM" - DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose -p localenv -f tests/docker/docker-compose.yml down - -docker-attach-quasar: ##@docker Connect to a terminal prompt in QUASAR node container - @echo "Connecting to quasar docker container" - docker exec -it localenv-quasar-1 /bin/bash - -docker-attach-osmosis: ##@docker Connect to a terminal prompt in OSMOSIS node container - @echo "Connecting to osmosis docker container" - docker exec -it localenv-osmosis-1 /bin/ash - -docker-attach-relayer: ##@docker Connect to a terminal prompt in RLY node container - @echo "Connecting to relayer docker container" - docker exec -it localenv-relayer-1 /bin/bash - -docker-test-e2e: docker-compose-up - @echo "Running e2e tests" - cd ./tests/shell/ && ./create_and_execute_contract.sh - -############################################################################### -### Docker E2E InterchainTest ### -############################################################################### - -docker-e2e-build: - $(eval CHAINS=$(filter-out $@,$(MAKECMDGOALS))) - @for chain in $(CHAINS); do \ - echo "Building $$chain"; \ - DOCKER_BUILDKIT=1 docker build \ - -t $$chain:local \ - -t $$chain:local-distroless \ - --build-arg GO_VERSION=$(GO_VERSION) \ - --build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_DISTROLESS) \ - --build-arg GIT_VERSION=$(VERSION) \ - --build-arg GIT_COMMIT=$(COMMIT) \ - -f ./tests/e2e/dockerfiles/$$chain.Dockerfile . ;\ - done - -%: - @: - -############################################################################### -### Linting ### -############################################################################### - -lint: - @echo "--> Running linter" - @go run github.com/golangci/golangci-lint/cmd/golangci-lint run --timeout=10m .PHONY: all build-linux install format lint build \ test test-all test-build test-cover test-unit test-race benchmark diff --git a/scripts/makefiles/build.mk b/scripts/makefiles/build.mk new file mode 100644 index 000000000..1607aef0a --- /dev/null +++ b/scripts/makefiles/build.mk @@ -0,0 +1,98 @@ +############################################################################### +### Build ### +############################################################################### + +build-help: + @echo "build subcommands" + @echo "" + @echo "Usage:" + @echo " make build-[command]" + @echo "" + @echo "Available Commands:" + @echo " all Build all targets" + @echo " check-version Check Go version" + @echo " dev-build Build development version" + @echo " dev-install Install development build" + @echo " linux Build for Linux" + @echo " reproducible Build reproducible binaries" + @echo " reproducible-amd64 Build reproducible amd64 binary" + @echo " reproducible-arm64 Build reproducible arm64 binary" + +build-check-version: + @echo "Go version: $(GO_MAJOR_VERSION).$(GO_MINOR_VERSION)" + @if [ $(GO_MAJOR_VERSION) -gt $(GO_MINIMUM_MAJOR_VERSION) ]; then \ + echo "Go version is sufficient"; \ + exit 0; \ + elif [ $(GO_MAJOR_VERSION) -lt $(GO_MINIMUM_MAJOR_VERSION) ]; then \ + echo '$(GO_VERSION_ERR_MSG)'; \ + exit 1; \ + elif [ $(GO_MINOR_VERSION) -lt $(GO_MINIMUM_MINOR_VERSION) ]; then \ + echo '$(GO_VERSION_ERR_MSG)'; \ + exit 1; \ + fi + +build-all: build-check-version go.sum + mkdir -p $(BUILDDIR)/ + GOWORK=off go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./... + +build-linux: go.sum + LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build + +# disables optimization, inlining and symbol removal +GC_FLAGS := -gcflags="all=-N -l" +REMOVE_STRING := -w -s +DEBUG_BUILD_FLAGS:= $(subst $(REMOVE_STRING),,$(BUILD_FLAGS)) +DEBUG_LDFLAGS = $(subst $(REMOVE_STRING),,$(ldflags)) + +build-dev-install: go.sum + GOWORK=off go install $(DEBUG_BUILD_FLAGS) $(GC_FLAGS) $(GO_MODULE)/cmd/quasarnoded + +build-dev-build: + mkdir -p $(BUILDDIR)/ + GOWORK=off go build $(GC_FLAGS) -mod=readonly -ldflags '$(DEBUG_LDFLAGS)' -gcflags "all=-N -l" -trimpath -o $(BUILDDIR) ./...; + +############################################################################### +### Build reproducible ### +############################################################################### + +build-reproducible: build-reproducible-amd64 build-reproducible-arm64 + +build-reproducible-amd64: go.sum + mkdir -p $(BUILDDIR) + $(DOCKER) buildx create --name quasarbuilder || true + $(DOCKER) buildx use quasarbuilder + $(DOCKER) buildx build \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_DISTROLESS) \ + --build-arg GIT_VERSION=$(VERSION) \ + --build-arg GIT_COMMIT=$(COMMIT) \ + --platform linux/amd64 \ + -t quasar:local-amd64 \ + --load \ + -f Dockerfile . + $(DOCKER) rm -f quasarbinary || true + $(DOCKER) create -ti --name quasarbinary quasar:local-amd64 + $(DOCKER) cp quasarbinary:/bin/quasarnoded $(BUILDDIR)/quasarnoded-linux-amd64 + $(DOCKER) rm -f quasarbinary + +build-reproducible-arm64: go.sum + mkdir -p $(BUILDDIR) + $(DOCKER) buildx create --name quasarbuilder || true + $(DOCKER) buildx use quasarbuilder + $(DOCKER) buildx build \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_DISTROLESS) \ + --build-arg GIT_VERSION=$(VERSION) \ + --build-arg GIT_COMMIT=$(COMMIT) \ + --platform linux/arm64 \ + -t quasar-arm64 \ + --load \ + -f Dockerfile . + $(DOCKER) rm -f quasarbinary || true + $(DOCKER) create -ti --name quasarbinary quasar-arm64 + $(DOCKER) cp quasarbinary:/bin/quasarnoded $(BUILDDIR)/quasarnoded-linux-arm64 + $(DOCKER) rm -f quasarbinary + +go.sum: go.mod + @echo "--> Ensure dependencies have not been modified" + @go mod verify diff --git a/scripts/makefiles/docker.mk b/scripts/makefiles/docker.mk new file mode 100644 index 000000000..39684e9d9 --- /dev/null +++ b/scripts/makefiles/docker.mk @@ -0,0 +1,123 @@ +############################################################################### +### Docker ### +############################################################################### + +RUNNER_BASE_IMAGE_DISTROLESS := gcr.io/distroless/static-debian11 +RUNNER_BASE_IMAGE_ALPINE := alpine:3.17 +RUNNER_BASE_IMAGE_NONROOT := gcr.io/distroless/static-debian11:nonroot + +docker-help: + @echo "docker subcommands" + @echo "" + @echo "Usage:" + @echo " make docker-[command]" + @echo "" + @echo "Available Commands:" + @echo " build Build Docker image (distroless)" + @echo " build-alpine Build alpine Docker image" + @echo " build-nonroot Build nonroot Docker image" + @echo " compose-up Launching local env, building images if not available" + @echo " compose-up-recreate Recreate local env (will destroy application state)" + @echo " compose-build Rebuilding image for local env" + @echo " compose-rebuild Rebuilding images and restarting containers" + @echo " compose-stop Stop docker containers without removing them" + @echo " compose-down Stopping docker containers and REMOVING THEM" + @echo " attach-quasar Connecting to quasar docker container" + @echo " attach-osmosis Connecting to osmosis docker container" + @echo " attach-relayer Connecting to relayer docker container" + @echo " test-e2e Running e2e tests" + @echo " e2e-build Build e2e docker images of the chain needed for interchaintest" + +docker: docker-help + +docker-build: + @DOCKER_BUILDKIT=1 docker build \ + -t quasar:local \ + -t quasar:local-distroless \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_DISTROLESS) \ + --build-arg GIT_VERSION=$(VERSION) \ + --build-arg GIT_COMMIT=$(COMMIT) \ + -f Dockerfile . + +docker-build-alpine: + @DOCKER_BUILDKIT=1 docker build \ + -t quasar:local-alpine \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_ALPINE) \ + --build-arg GIT_VERSION=$(VERSION) \ + --build-arg GIT_COMMIT=$(COMMIT) \ + -f Dockerfile . + +docker-build-nonroot: + @DOCKER_BUILDKIT=1 docker build \ + -t quasar:local-nonroot \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_NONROOT) \ + --build-arg GIT_VERSION=$(VERSION) \ + --build-arg GIT_COMMIT=$(COMMIT) \ + -f Dockerfile . + + +# This is not available to avoid missbehavior since it seems to be a bug in docker compose -p localenv: +# https://github.com/docker/compose/issues/10068 +# docker-compose-up-attached: ##@docker Run (and build if needed) env in docker compose. Attach if running in background. +# @echo "Launching local env with docker-compose" +# DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose -p localenv -f tests/docker/docker-compose.yml up + +docker-compose-up: ##@docker Run local env, build only if no images available + @echo "Launching local env, building images if not available" + DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose -p localenv -f tests/docker/docker-compose.yml up -d + +docker-compose-up-recreate: ##@docker DESTROY env containers and respawn them + @echo "Recreate local env (will destroy application state)" + DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose -p localenv -f tests/docker/docker-compose.yml up -d --force-recreate + +docker-compose-build: ##@docker Build new image if there are code changes, won't recreate containers. + @echo "Rebuilding image for local env" + DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose -p localenv -f tests/docker/docker-compose.yml build + +docker-compose-rebuild: docker-compose-build docker-compose-up-recreate ##@docker Recreate containers building new code if needed + @echo "Rebuilding images and restarting containers" + +docker-compose-stop: ##@docker Stop containers without deleting them + @echo "Stop docker containers without removing them" + DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose -p localenv -f tests/docker/docker-compose.yml stop + +docker-compose-down: ##@docker Stop AND DELETE delete the containers + @echo "Stopping docker containers and REMOVING THEM" + DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker compose -p localenv -f tests/docker/docker-compose.yml down + +docker-attach-quasar: ##@docker Connect to a terminal prompt in QUASAR node container + @echo "Connecting to quasar docker container" + docker exec -it localenv-quasar-1 /bin/bash + +docker-attach-osmosis: ##@docker Connect to a terminal prompt in OSMOSIS node container + @echo "Connecting to osmosis docker container" + docker exec -it localenv-osmosis-1 /bin/ash + +docker-attach-relayer: ##@docker Connect to a terminal prompt in RLY node container + @echo "Connecting to relayer docker container" + docker exec -it localenv-relayer-1 /bin/bash + +docker-test-e2e: docker-compose-up + @echo "Running e2e tests" + cd ./tests/shell/ && ./create_and_execute_contract.sh + +############################################################################### +### Docker E2E InterchainTest ### +############################################################################### + +docker-e2e-build: + $(eval CHAINS=$(filter-out $@,$(MAKECMDGOALS))) + @for chain in $(CHAINS); do + echo "Building $$chain" + DOCKER_BUILDKIT=1 docker build \ + -t $$chain:local \ + -t $$chain:local-distroless \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg RUNNER_IMAGE=$(RUNNER_BASE_IMAGE_DISTROLESS) \ + --build-arg GIT_VERSION=$(VERSION) \ + --build-arg GIT_COMMIT=$(COMMIT) \ + -f ./tests/e2e/dockerfiles/$$chain.Dockerfile . + done diff --git a/scripts/makefiles/lint.mk b/scripts/makefiles/lint.mk new file mode 100644 index 000000000..17455699f --- /dev/null +++ b/scripts/makefiles/lint.mk @@ -0,0 +1,47 @@ +############################################################################### +### Linting ### +############################################################################### +lint-help: + @echo "lint subcommands" + @echo "" + @echo "Usage:" + @echo " make lint-[command]" + @echo "" + @echo "Available Commands:" + @echo " all Run all linters" + @echo " fix-typo Run codespell to fix typos" + @echo " format Run linters with auto-fix" + @echo " markdown Run markdown linter with auto-fix" + @echo " mdlint Run markdown linter" + @echo " setup-pre-commit Set pre-commit git hook" + @echo " typo Run codespell to check typos" +lint: lint-help + +lint-all: + @echo "--> Running linter" + @go run github.com/golangci/golangci-lint/cmd/golangci-lint run --timeout=10m + @docker run -v $(PWD):/workdir ghcr.io/igorshubovych/markdownlint-cli:latest "**/*.md" + +lint-format: + @go run github.com/golangci/golangci-lint/cmd/golangci-lint run ./... --fix + @go run mvdan.cc/gofumpt -l -w x/ app/ ante/ tests/ + @docker run -v $(PWD):/workdir ghcr.io/igorshubovych/markdownlint-cli:latest "**/*.md" --fix + +lint-mdlint: + @echo "--> Running markdown linter" + @docker run -v $(PWD):/workdir ghcr.io/igorshubovych/markdownlint-cli:latest "**/*.md" + +lint-markdown: + @docker run -v $(PWD):/workdir ghcr.io/igorshubovych/markdownlint-cli:latest "**/*.md" --fix + +lint-typo: + @codespell + +lint-fix-typo: + @codespell -w + +lint-setup-pre-commit: + @cp .git/hooks/pre-commit .git/hooks/pre-commit.bak 2>/dev/null || true + @echo "Installing pre-commit hook..." + @ln -sf ../../scripts/hooks/pre-commit.sh .git/hooks/pre-commit + @echo "Pre-commit hook installed successfully" \ No newline at end of file diff --git a/scripts/makefiles/proto.mk b/scripts/makefiles/proto.mk new file mode 100644 index 000000000..30b7607b1 --- /dev/null +++ b/scripts/makefiles/proto.mk @@ -0,0 +1,40 @@ +############################################################################### +### Proto & Mock Generation ### +############################################################################### +protoVer=0.13.0 +protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer) +protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) + +proto-help: + @echo "proto subcommands" + @echo "" + @echo "Usage:" + @echo " make proto-[command]" + @echo "" + @echo "Available Commands:" + @echo " all Run proto-format and proto-gen" + @echo " gen Generate Protobuf files" + @echo " gen-1 Generate Protobuf files (old relic)" + @echo " doc Generate proto docs" + +proto: proto-help +proto-all: proto-format proto-lint proto-gen + +# todo : @AJ needs to address this after removing third_party. Refer this for removal https://github.com/osmosis-labs/osmosis/blob/188abfcd15544ca07d468c0dc0169876ffde6079/scripts/makefiles/proto.mk#L39 +proto-gen: + @echo "Generating Protobuf files" + @$(protoImage) sh ./scripts/protocgen.sh + +proto-format: + @$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \; + +proto-lint: + @$(protoImage) buf lint --error-format=json + +proto-update-deps: + @echo "Updating Protobuf dependencies" + $(DOCKER) run --rm -v $(CURDIR)/proto:/workspace --workdir /workspace $(protoImageName) buf mod update + +proto-doc: + @echo "Generating Protoc docs" + @sh ./scripts/generate-docs.sh \ No newline at end of file diff --git a/scripts/makefiles/test.mk b/scripts/makefiles/test.mk new file mode 100644 index 000000000..4ec899d21 --- /dev/null +++ b/scripts/makefiles/test.mk @@ -0,0 +1,53 @@ +############################################################################### +### Tests ### +############################################################################### + +PACKAGES_UNIT=$(shell go list ./x/epochs/... ./x/qoracle/... ./x/tokenfactory/... ./x/qtransfer/... ./x/qvesting/... ./app/... | grep -E -v "simapp|e2e" | grep -E -v "x/qoracle/client/cli") +PACKAGES_E2E=$(shell go list ./... | grep '/tests/e2e') +PACKAGES_SIM=$(shell go list ./... | grep '/tests/simulator') +TEST_PACKAGES=./... + +test-help: + @echo "test subcommands" + @echo "" + @echo "Usage:" + @echo " make test-[command]" + @echo "" + @echo "Available Commands:" + @echo " all Run all tests" + @echo " benchmark Run benchmark tests" + @echo " cover Run coverage tests" + @echo " race Run race tests" + @echo " sim-app Run sim app tests" + @echo " sim-bench Run sim benchmark tests" + @echo " sim-determinism Run sim determinism tests" + @echo " sim-suite Run sim suite tests" + @echo " unit Run unit tests" + +test: test-help + +test-all: test-unit test-race test-sim-app + +test-unit: + @VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock norace' $(PACKAGES_UNIT) + +test-race: + @VERSION=$(VERSION) go test -mod=readonly -race -tags='ledger test_ledger_mock' $(PACKAGES_UNIT) + +test-cover: + @VERSION=$(VERSION) go test -mod=readonly -timeout 30m -coverprofile=coverage.txt -tags='norace' -covermode=atomic $(PACKAGES_UNIT) + +test-sim-suite: + @VERSION=$(VERSION) go test -mod=readonly $(PACKAGES_SIM) + +test-sim-app: + @VERSION=$(VERSION) go test -mod=readonly -run ^TestFullAppSimulation -v $(PACKAGES_SIM) + +test-sim-determinism: + @VERSION=$(VERSION) go test -mod=readonly -run ^TestAppStateDeterminism -v $(PACKAGES_SIM) + +test-sim-bench: + @VERSION=$(VERSION) go test -benchmem -run ^BenchmarkFullAppSimulation -bench ^BenchmarkFullAppSimulation -cpuprofile cpu.out $(PACKAGES_SIM) + +test-benchmark: + @go test -mod=readonly -bench=. $(PACKAGES_UNIT) \ No newline at end of file diff --git a/tests/e2e/Makefile b/tests/e2e/Makefile index 3c7347b18..fed8947b6 100644 --- a/tests/e2e/Makefile +++ b/tests/e2e/Makefile @@ -1,8 +1,20 @@ +e2e-help: + @echo "e2e subcommands" + @echo "" + @echo "Usage:" + @echo " make e2e-[command]" + @echo "" + @echo "Available Commands:" + @echo " test Run tests in the specified folders serially, if CASES is defined; otherwise, run all." + @echo " test-parallel Run tests in the specified folders in parallel, if CASES is defined; otherwise, run all." + +e2e: e2e-help + # Find all folders inside ./cases, excluding ones that start with an underscore -TEST_FOLDERS=$(shell find ./cases -mindepth 1 -maxdepth 1 -type d \( -name "[!_]*" \)) +TEST_FOLDERS=$(shell find ./tests/e2e/cases -mindepth 1 -maxdepth 1 -type d \( -name "[!_]*" \)) # Run tests in the specified folders serially, if CASES is defined; otherwise, run all. -test-e2e: +e2e-test: ifdef CASES # Loop through each folder specified in CASES and run the tests @for folder in $(filter $(CASES), $(TEST_FOLDERS)); do \ @@ -18,7 +30,7 @@ else endif # Run tests in the specified folders in parallel, if CASES is defined; otherwise, run all. -test-e2e-parallel: +e2e-test-parallel: ifdef CASES @for folder in $(filter $(CASES), $(TEST_FOLDERS)); do \ echo "\nRunning tests in directory: $$folder"; \