Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# The Lifted Initiative
version: 2.1

GO_VERSION: &go_version '1.22'
GO_VERSION: &go_version '1.24.6'
GORELEASER_VERSION: &goreleaser_version 'v1.23.0'

orbs:
Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
tag: *go_version
steps:
- checkout
- run: make vet
# - run: make vet
- run: make govulncheck
release:
executor:
Expand Down
3 changes: 2 additions & 1 deletion .coverageignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.pb.go
*.pb.gw.go
*_simulation.go
*.pulsar.go
testnet.go
222 changes: 202 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,136 @@
COMMIT := $(shell git log -1 --format='%H')
DOCKER := $(shell which docker)
LEDGER_ENABLED ?= true
BINDIR ?= $(GOPATH)/bin
BUILD_DIR = ./build
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")

export GO111MODULE = on

# process build tags

# don't override user values
ifeq (,$(VERSION))
VERSION := $(shell git describe --tags --always)
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif

build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
endif

ifeq ($(WITH_CLEVELDB),yes)
build_tags += gcc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

whitespace :=
empty = $(whitespace) $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(empty),$(comma),$(build_tags))

ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=ghostcloud \
-X github.com/cosmos/cosmos-sdk/version.AppName=ghostcloudd \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X github.com/liftedinit/ghostcloud/app.Bech32Prefix=gc \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"

ifeq ($(WITH_CLEVELDB),yes)
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif
ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags "$(build_tags_comma_sep)" -ldflags '$(ldflags)' -trimpath

#### HELP ####

help: ## Display this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help

###########
# Install #
###########

all: install

install:
@echo "--> ensure dependencies have not been modified"
@go mod verify
@echo "--> installing ghostcloudd instrumented for coverage"
@go install $(BUILD_FLAGS) -cover -covermode=atomic -mod=readonly -coverpkg=github.com/liftedinit/ghostcloud/... ./cmd/ghostcloudd

init:
./scripts/init.sh

build:
ifeq ($(OS),Windows_NT)
$(error demo server not supported)
exit 1
else
go build -mod=readonly $(BUILD_FLAGS) -cover -covermode=atomic -coverpkg=github.com/liftedinit/ghostcloud/... -o $(BUILD_DIR)/ghostcloudd ./cmd/ghostcloudd
endif

build-vendored:
go build -mod=vendor $(BUILD_FLAGS) -o $(BUILD_DIR)/ghostcloudd ./cmd/ghostcloudd

.PHONY: all build build-linux install init lint build-vendored

##################
### Protobuf ###
##################

protoVer=0.14.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
@go mod tidy

proto-format:
@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;

proto-lint:
@$(protoImage) buf lint proto/ --error-format=json

.PHONY: proto-all proto-gen proto-format proto-lint

#### LINT ####

golangci_version=v1.55.1
golangci_version=v1.63.4

lint-install:
@echo "--> Installing golangci-lint $(golangci_version)"
Expand Down Expand Up @@ -41,18 +165,41 @@ format: ## Run formatter (goimports)

#### COVERAGE ####

COV_ROOT="/tmp/ghostcloud-coverage"
COV_UNIT_E2E="${COV_ROOT}/unit-e2e"
COV_SIMULATION="${COV_ROOT}/simulation"
COV_PKG="github.com/liftedinit/ghostcloud/..."
COV_SIM_CMD=${COV_SIMULATION}/simulation.test
COV_SIM_COMMON=-Enabled=True -NumBlocks=100 -Commit=true -Period=5 -Params=$(shell pwd)/simulation/sim_params.json -Verbose=false -test.v -test.gocoverdir=${COV_SIMULATION}

coverage: ## Run coverage report
@echo "--> Running coverage"
@go test -race -cpu=$$(nproc) -covermode=atomic -coverprofile=coverage.out $$(go list ./x/...) > /dev/null 2>&1
@echo "--> Running coverage filter"
@./scripts/filter-coverage.sh
@echo "--> Running coverage report"
@go tool cover -func=coverage-filtered.out
@echo "--> Running coverage html"
@go tool cover -html=coverage-filtered.out -o coverage.html
@echo "--> Creating GOCOVERDIR"
@mkdir -p ${COV_UNIT_E2E} ${COV_SIMULATION}
@echo "--> Cleaning up coverage files, if any"
@rm -rf ${COV_UNIT_E2E}/* ${COV_SIMULATION}/*
@echo "--> Building instrumented simulation test binary"
@go test -c ./app -mod=readonly -covermode=atomic -coverpkg=${COV_PKG} -cover -o ${COV_SIM_CMD}
@echo " --> Running Full App Simulation"
@${COV_SIM_CMD} -test.run TestFullAppSimulation ${COV_SIM_COMMON} > /dev/null 2>&1
@echo " --> Running App Simulation After Import"
@${COV_SIM_CMD} -test.run TestAppSimulationAfterImport ${COV_SIM_COMMON} > /dev/null 2>&1
@echo " --> Running App State Determinism Simulation"
@${COV_SIM_CMD} -test.run TestAppStateDeterminism ${COV_SIM_COMMON} > /dev/null 2>&1
@echo "--> Running unit & e2e tests coverage"
@go test -p 1 -timeout 30m -race -covermode=atomic -v -cpu=$$(nproc) -cover $$(go list ./...) -coverpkg=${COV_PKG} -args -test.gocoverdir="${COV_UNIT_E2E}"
@echo "--> Merging coverage reports"
@go tool covdata merge -i=${COV_UNIT_E2E},${COV_SIMULATION} -o ${COV_ROOT}
@echo "--> Converting binary coverage report to text format"
@go tool covdata textfmt -i=${COV_ROOT} -o ${COV_ROOT}/coverage-merged.out
@echo "--> Filtering coverage reports"
@./scripts/filter-coverage.sh ${COV_ROOT}/coverage-merged.out ${COV_ROOT}/coverage-merged-filtered.out
@echo "--> Generating coverage report"
@go tool cover -func=${COV_ROOT}/coverage-merged-filtered.out
@echo "--> Generating HTML coverage report"
@go tool cover -html=${COV_ROOT}/coverage-merged-filtered.out -o coverage.html
@echo "--> Coverage report available at coverage.html"
@echo "--> Cleaning up coverage files"
@rm coverage.out
@rm -rf ${COV_UNIT_E2E}/* ${COV_SIMULATION}/*
@echo "--> Running coverage complete"

.PHONY: coverage
Expand All @@ -73,16 +220,6 @@ vet: ## Run go vet

.PHONY: vet

#### NANCY ###

nancy: ## Run nancy
@echo "--> Running nancy (requires docker)"
@command -v docker >/dev/null 2>&1 || { echo >&2 "nancy requires docker but it's not installed. Aborting."; exit 1; }
go list -json -deps ./... | docker run --rm -i sonatypecommunity/nancy:latest sleuth

.PHONY: nancy


#### GOVULNCHECK ####
govulncheck_version=latest

Expand All @@ -95,3 +232,48 @@ govulncheck: ## Run govulncheck
@echo "--> Running govulncheck"
$(MAKE) govulncheck-install
@govulncheck ./...


#### Simulation ####

SIM_PARAMS ?= $(shell pwd)/simulation/sim_params.json
SIM_NUM_BLOCKS ?= 100
SIM_PERIOD ?= 5
SIM_COMMIT ?= true
SIM_ENABLED ?= true
SIM_VERBOSE ?= false
SIM_TIMEOUT ?= 24h
SIM_SEED ?= 42
SIM_COMMON_ARGS = -NumBlocks=${SIM_NUM_BLOCKS} -Enabled=${SIM_ENABLED} -Commit=${SIM_COMMIT} -Period=${SIM_PERIOD} -Params=${SIM_PARAMS} -Verbose=${SIM_VERBOSE} -Seed=${SIM_SEED} -v -timeout ${SIM_TIMEOUT}

sim-full-app:
@echo "--> Running full app simulation (blocks: ${SIM_NUM_BLOCKS}, commit: ${SIM_COMMIT}, period: ${SIM_PERIOD}, seed: ${SIM_SEED}, params: ${SIM_PARAMS}"
@go test ./app -run TestFullAppSimulation ${SIM_COMMON_ARGS}

sim-full-app-random:
$(MAKE) sim-full-app SIM_SEED=$$RANDOM

# Note: known to fail when using app wiring v1
sim-import-export:
@echo "--> Running app import/export simulation (blocks: ${SIM_NUM_BLOCKS}, commit: ${SIM_COMMIT}, period: ${SIM_PERIOD}, seed: ${SIM_SEED}, params: ${SIM_PARAMS}"
@go test ./app -run TestAppImportExport ${SIM_COMMON_ARGS}

# Note: known to fail when using app wiring v1
sim-import-export-random:
$(MAKE) sim-import-export SIM_SEED=$$RANDOM

sim-after-import:
@echo "--> Running app after import simulation (blocks: ${SIM_NUM_BLOCKS}, commit: ${SIM_COMMIT}, period: ${SIM_PERIOD}, seed: ${SIM_SEED}, params: ${SIM_PARAMS}"
@go test ./app -run TestAppSimulationAfterImport ${SIM_COMMON_ARGS}

sim-after-import-random:
$(MAKE) sim-after-import SIM_SEED=$$RANDOM

sim-app-determinism:
@echo "--> Running app determinism simulation (blocks: ${SIM_NUM_BLOCKS}, commit: ${SIM_COMMIT}, period: ${SIM_PERIOD}, seed: ${SIM_SEED}, params: ${SIM_PARAMS}"
@go test ./app -run TestAppStateDeterminism ${SIM_COMMON_ARGS}

sim-app-determinism-random:
$(MAKE) sim-app-determinism SIM_SEED=$$RANDOM

.PHONY: sim-full-app sim-full-app-random sim-import-export sim-after-import sim-app-determinism sim-import-export-random sim-after-import-random sim-app-determinism-random
Loading