diff --git a/.gitignore b/.gitignore index 04a412db..6b20596a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ vendor .DS_Store .idea .vscode -build/ .out docs/.vuepress/dist/ node_modules/ diff --git a/Makefile b/Makefile index 53b07aa3..b041efe4 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,4 @@ include scripts/build/contract.mk include scripts/build/protobuf.mk include scripts/build/testing.mk -include scripts/build/linting.mk - - - +include scripts/build/linting.mk \ No newline at end of file diff --git a/scripts/build/contract.mk b/scripts/build/contract.mk new file mode 100644 index 00000000..7fdffabd --- /dev/null +++ b/scripts/build/contract.mk @@ -0,0 +1,22 @@ +CONTRACTS_DIR := $(shell pwd)/modules/token/contracts +COMPILED_DIR := $(CONTRACTS_DIR)/compiled_contracts +NODE_MODULES := $(CONTRACTS_DIR)/node_modules + +# Compile and format solidity contracts for the erc20 module. Also install +# openzeppeling as the contracts are build on top of openzeppelin templates. +contracts-compile: contracts-clean dep-install create-contracts-abi + +# Install openzeppelin solidity contracts +dep-install: + @echo "Importing openzeppelin contracts..." + @cd $(CONTRACTS_DIR) && npm install + +# Clean tmp files +contracts-clean: + @rm -rf $(NODE_MODULES) + +# Compile, filter out and format contracts into the following format. +create-contracts-abi: + solc --combined-json abi,bin --optimize --optimize-runs 200 --evm-version paris --include-path $(NODE_MODULES) --base-path $(CONTRACTS_DIR)/ $(CONTRACTS_DIR)/Token.sol | jq '.contracts["Token.sol:Token"]' > $(COMPILED_DIR)/Token.json \ + && solc --combined-json abi,bin --optimize --optimize-runs 200 --evm-version paris --include-path $(NODE_MODULES) --base-path $(CONTRACTS_DIR)/ $(CONTRACTS_DIR)/TokenProxy.sol | jq '.contracts["TokenProxy.sol:TokenProxy"]' > $(COMPILED_DIR)/TokenProxy.json \ + && solc --combined-json abi,bin --optimize --optimize-runs 200 --evm-version paris --include-path $(NODE_MODULES) --base-path $(CONTRACTS_DIR)/ $(CONTRACTS_DIR)/UpgradeableBeacon.sol | jq '.contracts["UpgradeableBeacon.sol:UpgradeableBeacon"]' > $(COMPILED_DIR)/UpgradeableBeacon.json \ \ No newline at end of file diff --git a/scripts/build/linting.mk b/scripts/build/linting.mk new file mode 100644 index 00000000..78651479 --- /dev/null +++ b/scripts/build/linting.mk @@ -0,0 +1,27 @@ +golangci_version=v1.59.0 + +#? setup-pre-commit: Set pre-commit git hook +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" + +#? lint-install: Install golangci-lint +lint-install: + @echo "--> Installing golangci-lint $(golangci_version)" + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version) + +#? lint: Run golangci-lint +lint: + @echo "--> Running linter" + $(MAKE) lint-install + @./scripts/go-lint-all.bash --timeout=15m + +#? lint: Run golangci-lint and fix +lint-fix: + @echo "--> Running linter" + $(MAKE) lint-install + @./scripts/go-lint-all.bash --fix + +.PHONY: lint lint-fix \ No newline at end of file diff --git a/scripts/build/protobuf.mk b/scripts/build/protobuf.mk new file mode 100644 index 00000000..969da184 --- /dev/null +++ b/scripts/build/protobuf.mk @@ -0,0 +1,19 @@ +protoVer=0.13.0 +protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer) +protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) + +proto-all: proto-format proto-lint proto-gen + +proto-gen: + @echo "Generating Protobuf files" + @$(protoImage) sh ./scripts/protocgen.sh + +proto-swagger-gen: + @echo "Generating Protobuf Swagger" + @$(protoImage) sh ./scripts/protoc-swagger-gen.sh + +proto-format: + @$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \; + +proto-lint: + @$(protoImage) buf lint --error-format=json \ No newline at end of file diff --git a/scripts/build/testing.mk b/scripts/build/testing.mk new file mode 100644 index 00000000..d25ab006 --- /dev/null +++ b/scripts/build/testing.mk @@ -0,0 +1,84 @@ + +# make init-simapp initializes a single local node network +# it is useful for testing and development +# Usage: make install && make init-simapp && simd start +# Warning: make init-simapp will remove all data in simapp home directory +#? init-simapp: Initializes a single local node network +# init-simapp: +# ./scripts/init-simapp.sh + +#? test: Run `make test-unit` +test: test-unit +#? test-e2e: Run `make -C tests test-e2e` +test-e2e: + $(MAKE) -C tests test-e2e +#? test-e2e-cov: Run `make -C tests test-e2e-cov` +test-e2e-cov: + $(MAKE) -C tests test-e2e-cov +#? test-integration: Run `make -C tests test-integration` +test-integration: + $(MAKE) -C tests test-integration +#? test-integration-cov: Run `make -C tests test-integration-cov` +test-integration-cov: + $(MAKE) -C tests test-integration-cov +#? test-all: Run all test +test-all: test-unit test-e2e test-integration test-ledger-mock test-race + +.PHONY: test-system +test-system: build + mkdir -p ./tests/systemtests/binaries/ + cp $(BUILDDIR)/simd ./tests/systemtests/binaries/ + $(MAKE) -C tests/systemtests test + + +TEST_PACKAGES=./... +TEST_TARGETS := test-unit test-unit-amino test-unit-proto test-ledger-mock test-race test-ledger test-race + +# Test runs-specific rules. To add a new test target, just add +# a new rule, customise ARGS or TEST_PACKAGES ad libitum, and +# append the new rule to the TEST_TARGETS list. +test-unit: test_tags += cgo ledger test_ledger_mock norace +test-ledger: test_tags += cgo ledger norace +test-ledger-mock: test_tags += ledger test_ledger_mock norace +test-race: test_tags += cgo ledger test_ledger_mock +test-race: ARGS=-race +test-race: TEST_PACKAGES=$(PACKAGES_NOSIMULATION) +$(TEST_TARGETS): run-tests + +# check-* compiles and collects tests without running them +# note: go test -c doesn't support multiple packages yet (https://github.com/golang/go/issues/15513) +CHECK_TEST_TARGETS := check-test-unit check-test-unit-amino +check-test-unit: test_tags += cgo ledger test_ledger_mock norace +$(CHECK_TEST_TARGETS): EXTRA_ARGS=-run=none +$(CHECK_TEST_TARGETS): run-tests + +ARGS += -tags "$(test_tags)" +SUB_MODULES = $(shell find . -type f -name 'go.mod' -print0 | xargs -0 -n1 dirname | sort) +CURRENT_DIR = $(shell pwd) +#? run-tests: Run every sub modules' tests +run-tests: +ifneq (,$(shell which tparse 2>/dev/null)) + @echo "Starting unit tests"; \ + finalec=0; \ + for module in $(SUB_MODULES); do \ + cd ${CURRENT_DIR}/$$module; \ + echo "Running unit tests for $$(grep '^module' go.mod)"; \ + go test -mod=readonly -json $(ARGS) $(TEST_PACKAGES) ./... | tparse; \ + ec=$$?; \ + if [ "$$ec" -ne '0' ]; then finalec=$$ec; fi; \ + done; \ + exit $$finalec +else + @echo "Starting unit tests"; \ + finalec=0; \ + for module in $(SUB_MODULES); do \ + cd ${CURRENT_DIR}/$$module; \ + echo "Running unit tests for $$(grep '^module' go.mod)"; \ + go test -mod=readonly $(ARGS) $(TEST_PACKAGES) ./... ; \ + ec=$$?; \ + if [ "$$ec" -ne '0' ]; then finalec=$$ec; fi; \ + done; \ + exit $$finalec +endif + +.PHONY: run-tests test test-all $(TEST_TARGETS) \ No newline at end of file