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

Feat/interchaintest #402

Merged
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d4fb5bc
initial setup for interchain test
phamminh0811 Jan 3, 2024
46bc8ae
add basic ictest
phamminh0811 Jan 5, 2024
771cb21
add Dockerfile for ictest-build
phamminh0811 Jan 5, 2024
29997e1
fix Dockerfile outdated
phamminh0811 Jan 6, 2024
94b8454
change make file as renamed
phamminh0811 Jan 6, 2024
1f4d127
fix pfm subspace
phamminh0811 Jan 8, 2024
57a6589
add TestValidator for interchain test
phamminh0811 Jan 8, 2024
e3ffe35
add IBC transfer test for interchaintest
phamminh0811 Jan 10, 2024
e19420b
remove redundant code
phamminh0811 Jan 11, 2024
2ee7599
add github action for ictest
phamminh0811 Jan 11, 2024
7d006bd
add workflow dispatch
phamminh0811 Jan 11, 2024
75aeb3b
fix typo
phamminh0811 Jan 11, 2024
5aafbef
lowercase ghcr
phamminh0811 Jan 11, 2024
ba7aab5
try with gh action v4
phamminh0811 Jan 11, 2024
647a2a7
minor fix
phamminh0811 Jan 11, 2024
709c9d0
try install go env
phamminh0811 Jan 11, 2024
968efc2
change go 1.2 to 1.20
phamminh0811 Jan 11, 2024
cafb787
minor fix
phamminh0811 Jan 11, 2024
eddeb51
ready for merge
phamminh0811 Jan 11, 2024
0882f18
Merge pull request #1 from Genuine-labs/ictest/test-ghaction
phamminh0811 Jan 11, 2024
6e544cd
change go-schnorrkel to ensure cometbft fork can be built successfully
phamminh0811 Jan 11, 2024
0557d1a
try fix pfm by adding missing config
phamminh0811 Jan 14, 2024
69eb575
revert goschnorkel version
phamminh0811 Jan 14, 2024
ef761b4
Revert "revert goschnorkel version"
phamminh0811 Jan 14, 2024
746da02
revert goschnorkel version
phamminh0811 Jan 14, 2024
6fb4d7b
change pfm test so that it use terra's pfm
phamminh0811 Jan 14, 2024
bb177db
add ictest-ibc-pfm-terra
phamminh0811 Jan 14, 2024
6a1e16b
use Genuine-labs interchaintest to remove go-schnorrkel/1
phamminh0811 Jan 18, 2024
f52d121
update ci interchai
phamminh0811 Jan 29, 2024
2742e91
update ci interchain
phamminh0811 Jan 29, 2024
5b29083
Merge remote-tracking branch 'origin/frag/foundation' into feat/inter…
phamminh0811 Jan 29, 2024
cfdb6b2
update ci for interchain
phamminh0811 Jan 29, 2024
5f9eb9e
try fix interchain ci
phamminh0811 Jan 29, 2024
b09a8de
use new version of interchaintest
phamminh0811 Jan 29, 2024
68b1ce6
try fix interchaintest
phamminh0811 Jan 29, 2024
59f396d
fix interchaintest by using go-substrate-rpc-client fork
phamminh0811 Jan 29, 2024
d3d13d9
use go1.20
phamminh0811 Jan 29, 2024
eb2b429
use ibc go v6
phamminh0811 Jan 29, 2024
1f8b954
use go1.20
phamminh0811 Jan 29, 2024
103bbf1
add ictest-build to every ictests
phamminh0811 Jan 29, 2024
2954d48
copy both libwasmvm.aarch64.so and libwasmvm.x86_64.so
phamminh0811 Jan 29, 2024
e615c65
use alpine for Dockerfile
phamminh0811 Jan 30, 2024
447b0cb
Merge branch 'frag/foundation' into feat/interchaintest
expertdicer Jan 31, 2024
88cdf87
check if the ibcDenom is correct
phamminh0811 Feb 1, 2024
cef49f9
store only on chainNode
phamminh0811 Feb 1, 2024
2eb2edd
remove flush
phamminh0811 Feb 1, 2024
91f84c7
revert go v1.20
phamminh0811 Feb 1, 2024
8539d57
đeuplicate pfm code
phamminh0811 Feb 3, 2024
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
108 changes: 108 additions & 0 deletions .github/workflows/interchain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Interchain Tests

on:
workflow_dispatch:
pull_request:
push:
branches:
- frag/foundation
permissions:
contents: read
packages: write

jobs:
build-image:
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v4
expertdicer marked this conversation as resolved.
Show resolved Hide resolved
with:
go-version: '1.20'
- name: Check out repository code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build interchain image
id: build_image
uses: docker/build-push-action@v3
with:
file: ./ictest.Dockerfile
context: .
platforms: linux/amd64
tags: |
core:local

test-terra-start:
runs-on: ubuntu-latest
needs: build-image
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true

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

- run: make ictest-start

test-ibc-transfer:
runs-on: ubuntu-latest
needs: build-image
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true

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

- run: make ictest-ibc

test-ibc-hooks:
runs-on: ubuntu-latest
needs: build-image
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true

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

- run: make ictest-ibc-hooks

test-ibc-pfm:
runs-on: ubuntu-latest
needs: build-image
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true

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

- run: make ictest-ibc-pfm

test-validator:
runs-on: ubuntu-latest
needs: build-image
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true

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

- run: make ictest-validator
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,31 @@ benchmark:

.PHONY: test test-all test-cover test-unit test-race

###############################################################################
### Interchain test ###
###############################################################################
# Executes basic chain tests via interchaintest
ictest-start: ictest-build
@cd tests/interchaintest && go test -race -v -run TestTerraStart .

ictest-validator: ictest-build
@cd tests/interchaintest && go test -timeout=25m -race -v -run TestValidator .

ictest-ibc: ictest-build
@cd tests/interchaintest && go test -race -v -run TestTerraGaiaIBCTranfer .

ictest-ibc-hooks: ictest-build
@cd tests/interchaintest && go test -race -v -run TestTerraIBCHooks .

ictest-ibc-pfm: ictest-build
@cd tests/interchaintest && go test -race -v -run TestTerraGaiaOsmoPFM .

ictest-ibc-pfm-terra: ictest-build
@cd tests/interchaintest && go test -race -v -run TestTerraPFM .

ictest-build:
@DOCKER_BUILDKIT=1 docker build -t core:local -f ictest.Dockerfile .

###############################################################################
### Linting ###
###############################################################################
Expand Down
6 changes: 6 additions & 0 deletions go.work.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.20

use (
./
./tests/interchaintest
)
121 changes: 121 additions & 0 deletions ictest.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# syntax=docker/dockerfile:1

ARG source=./
ARG GO_VERSION="1.20"
ARG BUILDPLATFORM=linux/amd64
ARG BASE_IMAGE="golang:${GO_VERSION}-alpine3.18"
FROM --platform=${BUILDPLATFORM} ${BASE_IMAGE} as base

###############################################################################
# Builder
###############################################################################

FROM base as builder-stage-1

ARG source
ARG GIT_COMMIT
ARG GIT_VERSION
ARG BUILDPLATFORM
ARG GOOS=linux \
GOARCH=amd64

ENV GOOS=$GOOS \
GOARCH=$GOARCH

# NOTE: add libusb-dev to run with LEDGER_ENABLED=true
RUN set -eux &&\
apk update &&\
apk add --no-cache \
ca-certificates \
linux-headers \
build-base \
cmake \
git

# install mimalloc for musl
WORKDIR ${GOPATH}/src/mimalloc
RUN set -eux &&\
git clone --depth 1 --branch v2.1.2 \
https://github.com/microsoft/mimalloc . &&\
mkdir -p build &&\
cd build &&\
cmake .. &&\
make -j$(nproc) &&\
make install

# download dependencies to cache as layer
WORKDIR ${GOPATH}/src/app
COPY ${source}go.mod ${source}go.sum ./
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go mod download -x

# Cosmwasm - Download correct libwasmvm version and verify checksum
RUN set -eux &&\
WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 5) && \
WASMVM_DOWNLOADS="https://github.com/classic-terra/wasmvm/releases/download/${WASMVM_VERSION}"; \
wget ${WASMVM_DOWNLOADS}/checksums.txt -O /tmp/checksums.txt; \
if [ ${BUILDPLATFORM} = "linux/amd64" ]; then \
WASMVM_URL="${WASMVM_DOWNLOADS}/libwasmvm_muslc.x86_64.a"; \
elif [ ${BUILDPLATFORM} = "linux/arm64" ]; then \
WASMVM_URL="${WASMVM_DOWNLOADS}/libwasmvm_muslc.aarch64.a"; \
else \
echo "Unsupported Build Platfrom ${BUILDPLATFORM}"; \
exit 1; \
fi; \
wget ${WASMVM_URL} -O /lib/libwasmvm_muslc.a; \
CHECKSUM=`sha256sum /lib/libwasmvm_muslc.a | cut -d" " -f1`; \
grep ${CHECKSUM} /tmp/checksums.txt; \
rm /tmp/checksums.txt

###############################################################################

FROM builder-stage-1 as builder-stage-2

ARG source
ARG GOOS=linux \
GOARCH=amd64

ENV GOOS=$GOOS \
GOARCH=$GOARCH

# Copy the remaining files
COPY ${source} .

# Build app binary
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go install \
-mod=readonly \
-tags "netgo,muslc" \
-ldflags " \
-w -s -linkmode=external -extldflags \
'-L/go/src/mimalloc/build -lmimalloc -Wl,-z,muldefs -static' \
-X github.com/cosmos/cosmos-sdk/version.Name='terra' \
-X github.com/cosmos/cosmos-sdk/version.AppName='terrad' \
-X github.com/cosmos/cosmos-sdk/version.Version=${GIT_VERSION} \
-X github.com/cosmos/cosmos-sdk/version.Commit=${GIT_COMMIT} \
-X github.com/cosmos/cosmos-sdk/version.BuildTags='netgo,muslc' \
" \
-trimpath \
./...

################################################################################

FROM alpine as terra-core

RUN apk update && apk add wget lz4 aria2 curl jq gawk coreutils "zlib>1.2.12-r2" libssl3

COPY --from=builder-stage-2 /go/bin/terrad /usr/local/bin/terrad

ENV HOME /terra
WORKDIR $HOME

# rest server
EXPOSE 1317
# grpc
EXPOSE 9090
# tendermint p2p
EXPOSE 26656
# tendermint rpc
EXPOSE 26657
24 changes: 24 additions & 0 deletions tests/interchaintest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Interchaintest

`Interchaintest` orchestrates Go tests that utilize Docker containers for multiple IBC-compatible blockchains.

It allows users to quickly spin up custom testnets and dev environments to test IBC, chain infrastructures, smart contracts, etc.

- Built-in suite of conformance tests to test high-level IBC compatibility between chain sets
- Easily construct customized tests in highly configurable environments
- Deployable as CI tests in production workflows

## Test Case


## Quick Start
Make sure you have Docker installed. For testing in local machine you need 2 steps:

1. Build a debug image with your code change
```bash
make docker-build-debug
```
2. Run Test-case you want to test. Example:
```bash
make ictest-start
```
Binary file added tests/interchaintest/bytecode/counter.wasm
Binary file not shown.
67 changes: 67 additions & 0 deletions tests/interchaintest/chain_start_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package interchaintest

import (
"context"
"testing"

"github.com/strangelove-ventures/interchaintest/v6"
"github.com/strangelove-ventures/interchaintest/v6/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v6/testreporter"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)

// TestTerraStart is a test to assert that spinning up a Terra Classic network with one validator works properly.
func TestTerraStart(t *testing.T) {
if testing.Short() {
t.Skip()
}

t.Parallel()

// Create chain factory with Terra Classic
numVals := 1
numFullNodes := 3

config, err := createConfig()
require.NoError(t, err)

cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{
{
Name: "terra",
ChainConfig: config,
NumValidators: &numVals,
NumFullNodes: &numFullNodes,
},
})

// Get chains from the chain factory
chains, err := cf.Chains(t.Name())
require.NoError(t, err)

terra := chains[0].(*cosmos.CosmosChain)

// Create a new Interchain object which describes the chains, relayers, and IBC connections we want to use
ic := interchaintest.NewInterchain().AddChain(terra)

rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)

ctx := context.Background()
client, network := interchaintest.DockerSetup(t)

err = ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
fragwuerdig marked this conversation as resolved.
Show resolved Hide resolved
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: true,

// This can be used to write to the block database which will index all block data e.g. txs, msgs, events, etc.
// BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(),
})
require.NoError(t, err)

t.Cleanup(func() {
_ = ic.Close()
})
}
23 changes: 23 additions & 0 deletions tests/interchaintest/ci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package interchaintest

import (
"os"
"strings"
)

// GetDockerImageInfo returns the appropriate repo and branch version string for integration with the CI pipeline.
// The remote runner sets the BRANCH_CI env var. If present, interchaintest will use the docker image pushed up to the repo.
// If testing locally, user should run `make ictest-build` and interchaintest will use the local image.
func GetDockerImageInfo() (repo, version string) {
branchVersion, found := os.LookupEnv("BRANCH_CI")
repo = TerraClassicMainRepo
if !found {
// make ictest-build
repo = "core"
branchVersion = "local"
}

// github converts / to - for pushed docker images
branchVersion = strings.ReplaceAll(branchVersion, "/", "-")
return repo, branchVersion
}
Loading
Loading