-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Pham Anh Minh <[email protected]> Co-authored-by: Pham Anh Minh <[email protected]>
- Loading branch information
1 parent
6ce9005
commit c125209
Showing
21 changed files
with
3,183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
go 1.20 | ||
|
||
use ( | ||
./ | ||
./tests/interchaintest | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{ | ||
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() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.