Skip to content

Commit

Permalink
update .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-zq committed Jun 25, 2024
1 parent e10f23c commit c40b520
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 5 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ vendor
.DS_Store
.idea
.vscode
build/
.out
docs/.vuepress/dist/
node_modules/
Expand Down
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions scripts/build/contract.mk
Original file line number Diff line number Diff line change
@@ -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 \
27 changes: 27 additions & 0 deletions scripts/build/linting.mk
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions scripts/build/protobuf.mk
Original file line number Diff line number Diff line change
@@ -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
84 changes: 84 additions & 0 deletions scripts/build/testing.mk
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c40b520

Please sign in to comment.