Skip to content

Commit

Permalink
Merge pull request CosmWasm#42 from oraichain/cherry-pick-interchaintest
Browse files Browse the repository at this point in the history
Feat: Set up interchaintest (CosmWasm#35)
  • Loading branch information
ducphamle2 authored Dec 11, 2024
2 parents 4b7347e + 7ff4f73 commit a1c744c
Show file tree
Hide file tree
Showing 6 changed files with 2,344 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ endif
build-windows-client: go.sum
GOOS=windows GOARCH=amd64 go build -mod=readonly $(BUILD_FLAGS) -o build/oraid.exe ./cmd/wasmd

docker-build-debug:
@DOCKER_BUILDKIT=1 docker build -t orai:debug -f ict.Dockerfile --no-cache .

install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/wasmd

Expand Down Expand Up @@ -147,6 +150,14 @@ test-sim-deterministic: runsim
test-system: install
$(MAKE) -C tests/system/ test

###############################################################################
### Interchain test ###
###############################################################################

# Executes basic chain tests via interchaintest
ictest-basic:
cd tests/interchaintest && go test -race -v -run TestStartOrai .

###############################################################################
### Linting ###
###############################################################################
Expand Down
78 changes: 78 additions & 0 deletions ict.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION="1.22.6"
# --------------------------------------------------------
# Builder
# --------------------------------------------------------

FROM golang:${GO_VERSION}-alpine as builder

ARG GIT_VERSION
ARG GIT_COMMIT

RUN apk add --no-cache \
ca-certificates \
build-base \
linux-headers

# Download go dependencies
WORKDIR /orai
COPY go.mod go.sum ./

ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go mod download

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 /usr/local/lib/libwasmvm_muslc.${ARCH}.a https://github.com/CosmWasm/wasmvm/releases/download/${WASM_VERSION}/libwasmvm_muslc.${ARCH}.a; \
fi; \
go mod download;

# Copy the remaining files
COPY . .

# Build oraid binary
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
GOWORK=off go build \
-mod=readonly \
-tags "netgo,ledger,muslc" \
-ldflags \
"-X github.com/cosmos/cosmos-sdk/version.Name="orai" \
-X github.com/cosmos/cosmos-sdk/version.AppName="oraid" \
-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,ledger,muslc \
-w -s -linkmode=external -extldflags '-Wl,-z,muldefs -static'" \
-trimpath \
-o /orai/bin/oraid \
/orai/cmd/wasmd

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

FROM alpine:3.16

COPY --from=builder /orai/bin/oraid /usr/bin/oraid

ENV PATH=/usr/bin:$PATH

ENV HOME=/.oraid
WORKDIR $HOME

# rest server
EXPOSE 1317
# tendermint p2p
EXPOSE 26656
# tendermint rpc
EXPOSE 26657
# grpc
EXPOSE 9090

ENTRYPOINT ["oraid"]
54 changes: 54 additions & 0 deletions tests/interchaintest/chain_start_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package interchaintest

import (
"context"
"testing"

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

// TestStartOrai is a basic test to assert that spinning up a Orai network with 1 validator works properly.
func TestStartOrai(t *testing.T) {
if testing.Short() {
t.Skip()
}

t.Parallel()

numVals := 1
numFullNodes := 1

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

chains, err := cf.Chains(t.Name())
require.NoError(t, err)

orai := chains[0].(*cosmos.CosmosChain)
ic := interchaintest.NewInterchain().AddChain(orai)
ctx := context.Background()
client, network := interchaintest.DockerSetup(t)

require.NoError(t, ic.Build(ctx, nil, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: true,
}))
t.Cleanup(func() {
_ = ic.Close()
})

a, err := orai.AuthQueryModuleAccounts(ctx)
require.NoError(t, err)
t.Log("module accounts", a)
}
Loading

0 comments on commit a1c744c

Please sign in to comment.