Skip to content

Commit

Permalink
feat: add e2e tests (#252)
Browse files Browse the repository at this point in the history
* added local e2e tests

* update docker file

* update build-and-run-single-node

* skip test on tools fo sdk
---------

Co-authored-by: allthatjazzleo <[email protected]>
  • Loading branch information
freeelancer and allthatjazzleo authored Jan 6, 2025
1 parent ff910d1 commit 47e46e7
Show file tree
Hide file tree
Showing 41 changed files with 5,046 additions and 80 deletions.
40 changes: 40 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Ignore the git related directory
.git
.github
.devcontainer

# Ignore local environment files
.env
*.local

# Ignore build artifacts
bin/
build/
obj/
dist/

# Ignore test files
/tests/

# Ignore any other unnecessary directories
/proto
/networks
/adr

# Ignore any other unnecessary files
*.log
*.tmp
*.bak
.golangci.yml
.goreleaser.yml
.lycheeignore
.markdownlint.yml
.markdownlintignore
buf.work.yaml
chains.yaml
coderabbit.yaml
config.yml
LICENSE
README.md
SECURITY.md
sonar-project.properties
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Gather dependencies
run: go mod download
- name: Run coverage
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
run: make test-cover
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/connect-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v4
- name: Install tparse
run: |
go install github.com/mfridman/tparse@latest
- run: make test-connect
5 changes: 2 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ jobs:
with:
chain: mantrachain
chains-spec-file: chains.yaml
clone-key: ${{ secrets.GIT_CLONE_KEY }}
heighliner-owner: ${{ github.repository_owner }}
heighliner-tag: v1.6.4
heighliner-owner: strangelove-ventures
heighliner-tag: v1.7.1
github-organization: ${{ github.repository_owner }}
github-repo: ${{ github.event.repository.name }}
git-ref: ${{ github.event.inputs.release_tag || github.ref_name }}
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/tests-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
push:
branches: main
pull_request:
branches: main
name: E2E Tests
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: 1.23
- uses: actions/checkout@v4
- name: Install tparse
run: |
go install github.com/mfridman/tparse@latest
- run: make test-e2e
40 changes: 40 additions & 0 deletions .github/workflows/tests-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
on:
push:
branches: main
pull_request:
branches: main
name: SDK Tests
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: 1.23
- uses: actions/checkout@v4
- name: Extract Tag or Commit
run: |
FULL_VERSION=$(go list -m github.com/cosmos/cosmos-sdk 2> /dev/null | sed 's:.* ::')
if [[ $FULL_VERSION == *"-0."* ]]; then
# This is a pseudo-version (commit-based)
SDK_VERSION=${FULL_VERSION##*-}
else
# This is a regular version tag
SDK_VERSION=$FULL_VERSION
fi
echo "SDK_VERSION=${SDK_VERSION}" | tee -a $GITHUB_ENV
- name: Checkout MANTRA-Chain/cosmos-sdk
uses: actions/checkout@v4
with:
repository: MANTRA-Chain/cosmos-sdk
path: cosmos-sdk
ref: ${{ env.SDK_VERSION }}
- name: Install tparse
run: |
go install github.com/mfridman/tparse@latest
- name: Run all tests
run: |
# skip test on tools
rm -rf tools
make test-all
working-directory: cosmos-sdk
13 changes: 8 additions & 5 deletions .github/workflows/tests-unit.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
on:
push:
branches: main
pull_request:
branches: main
push:
branches: main
pull_request:
branches: main
name: Unit Tests
jobs:
test:
Expand All @@ -12,4 +12,7 @@ jobs:
with:
go-version: 1.23
- uses: actions/checkout@v4
- run: go test ./...
- name: Install tparse
run: |
go install github.com/mfridman/tparse@latest
- run: make test-unit
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ release/
swagger-proto
tmp-swagger-gen
client/docs/node_modules
build
exclusive.lock
coverage.txt
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ linters:
- errname
- copyloopvar
- fatcontext
- forcetypeassert
- gci
- goconst
- gochecksumtype
Expand Down
43 changes: 16 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION="1.23"
ARG FINAL_IMAGE="alpine:latest"
ARG IMG_TAG="latest"
ARG BUILD_TAGS="netgo,ledger,muslc"

# --------------------------------------------------------
# Builder
# --------------------------------------------------------

FROM golang:${GO_VERSION}-alpine3.20 as builder

ARG GIT_VERSION
ARG GIT_COMMIT
ARG BUILD_TAGS
ARG CMT_VERSION

FROM golang:${GO_VERSION}-alpine3.20 AS mantra-builder
WORKDIR /src/app/
RUN apk add --no-cache \
ca-certificates \
build-base \
Expand All @@ -23,10 +18,9 @@ RUN apk add --no-cache \
git

# Download go dependencies
WORKDIR /mantrachain
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
RUN --mount=type=cache,target=/nonroot/.cache/go-build \
--mount=type=cache,target=/nonroot/go/pkg/mod \
go mod download

# Cosmwasm - Download correct libwasmvm version
Expand All @@ -42,26 +36,21 @@ COPY . .

# Build mantrachaind binary
# build tag info: https://github.com/cosmos/wasmd/blob/master/README.md#supported-systems
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
RUN --mount=type=cache,target=/nonroot/.cache/go-build \
--mount=type=cache,target=/nonroot/go/pkg/mod \
LEDGER_ENABLED=true BUILD_TAGS='muslc osusergo' LINK_STATICALLY=true make build

# --------------------------------------------------------
# Runner
# --------------------------------------------------------

FROM ${FINAL_IMAGE}

COPY --from=builder /mantrachain/build/mantrachaind /bin/mantrachaind

ENV HOME /mantrachain
WORKDIR $HOME

EXPOSE 26656
EXPOSE 26657
EXPOSE 1317
# Note: uncomment the line below if you need pprof in local mantrachain
# We disable it by default in out main Dockerfile for security reasons
# EXPOSE 6060
FROM alpine:$IMG_TAG
RUN apk add --no-cache build-base jq
RUN addgroup -g 1025 nonroot
RUN adduser -D nonroot -u 1025 -G nonroot
ARG IMG_TAG
COPY --from=mantra-builder /src/app/build/mantrachaind /usr/local/bin/
EXPOSE 26656 26657 1317 9090
USER nonroot

ENTRYPOINT ["mantrachaind"]
ENTRYPOINT ["mantrachaind", "start"]
50 changes: 33 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ LEDGER_ENABLED ?= true
BINDIR ?= $(GOPATH)/bin
BUILDDIR ?= $(CURDIR)/build
DOCKER := $(shell which docker)
PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation')

BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null)
BRANCH_PRETTY := $(subst /,-,$(BRANCH))
Expand Down Expand Up @@ -124,27 +123,43 @@ build-arm:
build-linux:
GOOS=linux GOARCH=$(if $(findstring aarch64,$(shell uname -m)) || $(findstring arm64,$(shell uname -m)),arm64,amd64) $(MAKE) build
build-image:
docker build -f Dockerfile -t mantra-chain/mantrachain:local .
docker build -f Dockerfile -t mantra-chain/mantrachain .

$(BUILD_TARGETS): go.sum $(BUILDDIR)/
go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) $(GO_MODULE)/cmd/mantrachaind
$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/

###############################################################################
### Tests ###
### Tests ###
###############################################################################

test: test-unit

test-unit:
@VERSION=$(VERSION) go test ./x/... -mod=readonly -vet=all -tags='norace' $(PACKAGES_NOSIMULATION)

test-cover:
@VERSION=$(VERSION) go test ./x/... -mod=readonly -timeout 30m -coverprofile=coverage.txt -covermode=atomic -tags='norace' $(PACKAGES_NOSIMULATION)

PACKAGES_UNIT=$(shell go list ./... | grep -v -e '/tests/e2e' | grep -v '/simulation')
PACKAGES_E2E=$(shell cd tests/e2e && go list ./... | grep '/e2e')
TEST_PACKAGES=./...
TEST_TARGETS := test-unit test-e2e test-cover test-connect

DIR=$(CURDIR)
test-unit: ARGS=-timeout=5m -tags='norace'
test-unit: TEST_PACKAGES=$(PACKAGES_UNIT)
test-e2e: ARGS=-timeout=35m -v
test-e2e: TEST_PACKAGES=$(PACKAGES_E2E)
test-e2e: build-image
test-cover: ARGS=-timeout=30m -coverprofile=coverage.txt -covermode=atomic -tags='norace'
test-cover: TEST_PACKAGES=$(PACKAGES_UNIT)
test-connect: ARGS=-v -race
test-connect: DIR=$(CURDIR)/tests/connect
test-connect: build-image
@VERSION=$(VERSION) cd tests/connect && go test -v -race .
$(TEST_TARGETS): run-tests

run-tests:
ifneq (,$(shell which tparse 2>/dev/null))
@echo "--> Running tests"
@cd $(DIR) && go test -mod=readonly -json $(ARGS) $(TEST_PACKAGES) | tparse
else
@echo "--> Running tests"
cd $(DIR) && go test -mod=readonly $(ARGS) $(TEST_PACKAGES)
endif

###############################################################################
### Release ###
Expand Down Expand Up @@ -220,13 +235,14 @@ mocks:
build-and-run-single-node: build
@echo "Building and running a single node for testing..."
@mkdir -p .mantrasinglenodetest
@if [ ! -f .mantrasinglenodetest/config.toml ]; then \
./build/mantrachaind init single-node-test --chain-id test-chain --home .mantrasinglenodetest; \
@if [ ! -f .mantrasinglenodetest/config/config.toml ]; then \
./build/mantrachaind init single-node-test --chain-id test-chain --home .mantrasinglenodetest --default-denom uom; \
./build/mantrachaind keys add validator --keyring-backend test --home .mantrasinglenodetest; \
./build/mantrachaind genesis add-genesis-account $$(./build/mantrachaind keys show validator -a --keyring-backend test --home .mantrasinglenodetest) 100000000stake --home .mantrasinglenodetest; \
./build/mantrachaind genesis gentx validator 100000000stake --chain-id test-chain --keyring-backend test --home .mantrasinglenodetest; \
./build/mantrachaind genesis add-genesis-account $$(./build/mantrachaind keys show validator -a --keyring-backend test --home .mantrasinglenodetest) 100000000000000uom --home .mantrasinglenodetest; \
./build/mantrachaind genesis gentx validator 100000000uom --chain-id test-chain --keyring-backend test --home .mantrasinglenodetest; \
./build/mantrachaind genesis collect-gentxs --home .mantrasinglenodetest; \
sed -i'' -e 's/"fee_denom": "stake"/"fee_denom": "uom"/' .mantrasinglenodetest/config/genesis.json; \
fi
./build/mantrachaind start --home .mantrasinglenodetest --minimum-gas-prices 0stake
./build/mantrachaind start --home .mantrasinglenodetest --minimum-gas-prices 0uom

.PHONY: build-and-run-single-node
2 changes: 1 addition & 1 deletion app/params/doc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Package params defines the simulation parameters in the gaia.
Package params defines the simulation parameters in the mantra.
It contains the default weights used for each transaction used on the module's
simulation. These weights define the chance for a transaction to be simulated at
Expand Down
26 changes: 26 additions & 0 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,29 @@ func GenesisStateWithValSet(
println(string(genesisState[banktypes.ModuleName]))
return genesisState, nil
}

// EmptyAppOptions is a stub implementing AppOptions
type EmptyAppOptions struct{}

// Get implements AppOptions
func (ao EmptyAppOptions) Get(o string) interface{} {
return nil
}

// AppOptionsMap is a stub implementing AppOptions which can get data from a map
type AppOptionsMap map[string]interface{}

func (m AppOptionsMap) Get(key string) interface{} {
v, ok := m[key]
if !ok {
return interface{}(nil)
}

return v
}

func NewAppOptionsWithFlagHome(homePath string) servertypes.AppOptions {
return AppOptionsMap{
flags.FlagHome: homePath,
}
}
Loading

0 comments on commit 47e46e7

Please sign in to comment.