Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ibc-hooks e2e #126

Closed
wants to merge 7 commits into from
Closed
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
68 changes: 67 additions & 1 deletion .github/workflows/ibc-hooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ env:
GO_VERSION: 1.21.0
WORKING_DIRECTORY: modules/ibc-hooks/

TAR_PATH: /tmp/ibchooks.tar
IMAGE_NAME: ibchooks
DOCKER_TAG: ibchooks:local

jobs:
golangci:
name: Linter
Expand Down Expand Up @@ -37,4 +41,66 @@ jobs:

- name: Test
run: go test ./...
working-directory: ${{ env.WORKING_DIRECTORY }}
working-directory: ${{ env.WORKING_DIRECTORY }}

build-docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and export
uses: docker/build-push-action@v5
with:
context: ${{ env.WORKING_DIRECTORY }}
tags: ${{ env.DOCKER_TAG }}
outputs: type=docker,dest=${{ env.TAR_PATH }}

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.IMAGE_NAME }}
path: ${{ env.TAR_PATH }}

e2e-tests:
needs: build-docker
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.WORKING_DIRECTORY }}
strategy:
matrix:
test:
- "ictest-ibchooks"
fail-fast: false

steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: checkout chain
uses: actions/checkout@v4

- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.IMAGE_NAME }}
path: /tmp

- name: Load Docker Image
run: |
docker image load -i ${{ env.TAR_PATH }}
docker image ls -a

- name: Run Test
run: make ${{ matrix.test }}
31 changes: 31 additions & 0 deletions modules/ibc-hooks/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# host
# make local-image
# docker run --rm -it ibchooks:local q

FROM golang:1.21-alpine3.18 as builder

RUN set -eux; apk add --no-cache ca-certificates git build-base libusb-dev linux-headers gcc musl-dev make go;

ENV GOPATH=""

COPY go.mod .
COPY go.sum .

RUN set -eux; \
export ARCH=$(uname -m); \
WASM_VERSION=$(go list -m all | grep github.com/CosmWasm/wasmvm | awk '{print $2}'); \
if [ ! -z "${WASM_VERSION}" ]; then \
wget -O /lib/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${WASM_VERSION}/libwasmvm_muslc.${ARCH}.a; \
fi; \
go mod download;


COPY . .

RUN LINK_STATICALLY=true BUILD_TAGS=muslc make build

FROM alpine:3.18

COPY --from=builder /go/build/simd /bin/simd

ENTRYPOINT ["/bin/simd"]
167 changes: 166 additions & 1 deletion modules/ibc-hooks/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#!/usr/bin/make -f

PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation')
PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
VERSION := $(shell echo $(shell git describe --always) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
GOMOD := $(shell go list -m)
LEDGER_ENABLED ?= true
BINDIR ?= $(GOPATH)/bin
BUILDDIR ?= $(CURDIR)/build
SIMAPP = ./simapp
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf

# Eveyrhing related to tests
simulate:
@go test -v -run=TestFullAppSimulation ./simapp -NumBlocks 200 -BlockSize 50 -Commit -Enabled -Period 1
Expand All @@ -16,4 +28,157 @@ optimize-workspace:
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.12.13

.PHONY: optimize-workspace
.PHONY: optimize-workspace

###############################################################################
### binary builder ###
###############################################################################

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 (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS)))
build_tags += gcc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

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

# process linker flags

ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=sim \
-X github.com/cosmos/cosmos-sdk/version.AppName=simd \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"

# DB backend selection
ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif
ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif
ifeq (badgerdb,$(findstring badgerdb,$(COSMOS_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=badgerdb
endif
# handle rocksdb
ifeq (rocksdb,$(findstring rocksdb,$(COSMOS_BUILD_OPTIONS)))
CGO_ENABLED=1
BUILD_TAGS += rocksdb
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=rocksdb
endif
# handle boltdb
ifeq (boltdb,$(findstring boltdb,$(COSMOS_BUILD_OPTIONS)))
BUILD_TAGS += boltdb
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=boltdb
endif

ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
ldflags += -w -s
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
# check for nostrip option
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif

all: tools build lint test

# The below include contains the tools and runsim targets.
#include contrib/devtools/Makefile

###############################################################################
### Build ###
###############################################################################

BUILD_TARGETS := build install

build: BUILD_ARGS=-o $(BUILDDIR)/
build-linux:
GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build -o bin/simd ./cmd/simd

$(BUILD_TARGETS): go.sum $(BUILDDIR)/
go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...

$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/

build-simd-all: go.sum
$(DOCKER) rm latest-build || true
$(DOCKER) run --volume=$(CURDIR):/sources:ro \
--env TARGET_PLATFORMS='linux/amd64 darwin/amd64 linux/arm64 windows/amd64' \
--env APP=simd \
--env VERSION=$(VERSION) \
--env COMMIT=$(COMMIT) \
--env LEDGER_ENABLED=$(LEDGER_ENABLED) \
--name latest-build cosmossdk/rbuilder:latest
$(DOCKER) cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/

build-simd-linux: go.sum $(BUILDDIR)/
$(DOCKER) rm latest-build || true
$(DOCKER) run --volume=$(CURDIR):/sources:ro \
--env TARGET_PLATFORMS='linux/amd64' \
--env APP=simd \
--env VERSION=$(VERSION) \
--env COMMIT=$(COMMIT) \
--env LEDGER_ENABLED=false \
--name latest-build cosmossdk/rbuilder:latest
$(DOCKER) cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/
cp artifacts/simd-*-linux-amd64 $(BUILDDIR)/simd

cosmovisor:
$(MAKE) -C cosmovisor cosmovisor

.PHONY: build build-linux build-simd-all build-simd-linux cosmovisor

$(MOCKS_DIR):
mkdir -p $(MOCKS_DIR)

distclean: clean tools-clean
clean:
rm -rf \
$(BUILDDIR)/ \
artifacts/ \
tmp-swagger-gen/

.PHONY: distclean clean


###############################################################################
### e2e interchain test ###
###############################################################################

local-image:
docker build . -f Dockerfile -t ibchooks:local

ictest-ibchooks:
cd e2e && go test -race -v -timeout 15m -run TestIBCHooks .
3 changes: 3 additions & 0 deletions modules/ibc-hooks/e2e/contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Contracts

> ibchooks_counter.wasm -> <https://github.com/osmosis-labs/osmosis/blob/64393a14e18b2562d72a3892eec716197a3716c7/tests/ibc-hooks/bytecode/counter.wasm>
Binary file not shown.
Loading
Loading