Skip to content

Commit

Permalink
test: interchain accounts via interchaintest (celestiaorg#3308)
Browse files Browse the repository at this point in the history
Closes celestiaorg#3207. 

For posterity, [this
branch](https://github.com/rootulp/celestia-app/tree/rp/ica-tests)
contains a messy commit history that describes issues encountered when
setting up these tests.
  • Loading branch information
rootulp authored and ninabarbakadze committed Apr 25, 2024
1 parent a2372a3 commit 5ba1b83
Show file tree
Hide file tree
Showing 10 changed files with 2,140 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ mod:
@go mod tidy
@echo "--> Updating go.mod in ./test/testground"
@(cd ./test/testground && go mod tidy)
@echo "--> Updating go.mod in ./test/interchain"
@(cd ./test/interchain && go mod tidy)
.PHONY: mod

## mod-verify: Verify dependencies have expected content.
Expand Down Expand Up @@ -83,14 +85,14 @@ build-docker:
## build-ghcr-docker: Build the celestia-appd docker image from the last commit. Requires docker.
build-ghcr-docker:
@echo "--> Building Docker image"
$(DOCKER) build -t ghcr.io/celestiaorg/celestia-app:$(GH_COMMIT) -f Dockerfile .
$(DOCKER) build -t ghcr.io/celestiaorg/celestia-app:$(COMMIT) -f Dockerfile .
.PHONY: build-ghcr-docker

## publish-ghcr-docker: Publish the celestia-appd docker image. Requires docker.
publish-ghcr-docker:
# Make sure you are logged in and authenticated to the ghcr.io registry.
@echo "--> Publishing Docker image"
$(DOCKER) push ghcr.io/celestiaorg/celestia-app:$(GH_COMMIT)
$(DOCKER) push ghcr.io/celestiaorg/celestia-app:$(COMMIT)
.PHONY: publish-ghcr-docker

## lint: Run all linters; golangci-lint, markdownlint, hadolint, yamllint.
Expand Down Expand Up @@ -158,10 +160,17 @@ test-coverage:
@export VERSION=$(VERSION); bash -x scripts/test_cover.sh
.PHONY: test-coverage

## test-fuzz: Run all fuzz tests.
test-fuzz:
bash -x scripts/test_fuzz.sh
.PHONY: test-fuzz

## test-interchain: Run interchain tests in verbose mode. Requires Docker.
test-interchain:
@echo "--> Running interchain tests"
@go test ./test/interchain -v
.PHONY: test-interchain

## txsim-install: Install the tx simulator.
txsim-install:
@echo "--> Installing tx simulator"
Expand Down
1 change: 1 addition & 0 deletions go.work.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ go 1.22.2
use (
.
./test/testground
./test/interchain
)
50 changes: 50 additions & 0 deletions test/interchain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Interchain

This folder contains tests that use [interchaintest](https://github.com/strangelove-ventures/interchaintest) to assert IBC features work as expected. Candidates for testing include:

1. Interchain Accounts (ICA)
1. Packet Forward Middleware (PFM)

## Usage

Run the tests via

```bash
make test-interchain
```

## Contributing

If you have local modifications that you would like to test via interchaintest, you'll need to create a new Celestia Docker image with your modifications. CI should automatically create a Docker image and publish it to GHCR if you create a PR against celestia-app. If that doesn't work, you can manually create an image via:

```shell
# make local modifications and commit them
make build-ghcr-docker
make publish-ghcr-docker
```

After you have a new Docker image with your modifications, you must update the test to reference the new image (see `chainspec/celestia.go`).

## Troubleshooting

`interchaintest` issues can be difficult to debug. Here are a few tips that may help:

1. You can stop `interchaintest` from cleaning up the Docker containers it created by setting an environment variable:

```shell
export KEEP_CONTAINERS=true
```

See [this PR](https://github.com/strangelove-ventures/interchaintest/pull/725). It wasn't backported to the `v6` branch so if you want to use it, cherry-pick the commit locally and apply it to your local `interchaintest` fork and use Go mod replace to point interchaintest to your local fork. After you have that change, you can run commands on the docker containers to debug them. For example:
```shell
docker exec -it gaia-val-0-TestICA gaiad tx interchain-accounts controller register connection-0 \
--chain-id gaia \
--node http://gaia-val-0-TestICA:26657 \
--home /var/cosmos-chain/gaia-2 \
--from TestICA-gaia-pez \
--keyring-backend test \
--fees 300000uatom \
--gas 300000 \
--yes
```
72 changes: 72 additions & 0 deletions test/interchain/chainspec/celestia.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package chainspec

import (
"testing"

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

const (
celestiaDockerRepository = "ghcr.io/celestiaorg/celestia-app"
celestiaDockerTag = "pr-3182"
celestiaUidGid = "10001:10001"
)

// GetCelestia returns a CosmosChain for Celestia.
func GetCelestia(t *testing.T) *cosmos.CosmosChain {
factory := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{celestia})
chains, err := factory.Chains(t.Name())
require.NoError(t, err)
return chains[0].(*cosmos.CosmosChain)
}

var celestia = &interchaintest.ChainSpec{
Name: "celestia",
ChainConfig: ibc.ChainConfig{
Type: "cosmos",
Name: "celestia-app",
ChainID: "celestia",
Bin: "celestia-appd",
Bech32Prefix: "celestia",
Denom: "utia",
GasPrices: "0.002utia",
GasAdjustment: *gasAdjustment(),
TrustingPeriod: "336hours",
Images: celestiaDockerImages(),
ConfigFileOverrides: celestiaConfigFileOverrides(),
},
NumValidators: numValidators(),
NumFullNodes: numFullNodes(),
GasAdjustment: gasAdjustment(),
}

func celestiaDockerImages() []ibc.DockerImage {
return []ibc.DockerImage{
{
Repository: celestiaDockerRepository,
Version: celestiaDockerTag,
UidGid: celestiaUidGid,
},
}
}

func celestiaConfigFileOverrides() map[string]any {
txIndex := make(testutil.Toml)
txIndex["indexer"] = "kv"

storage := make(testutil.Toml)
storage["discard_abci_responses"] = false

configToml := make(testutil.Toml)
configToml["tx_index"] = txIndex
configToml["storage"] = storage

result := make(map[string]any)
result["config/config.toml"] = configToml
return result
}
16 changes: 16 additions & 0 deletions test/interchain/chainspec/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package chainspec

func numValidators() *int {
nodes := 1
return &nodes
}

func numFullNodes() *int {
nodes := 0
return &nodes
}

func gasAdjustment() *float64 {
gasAdjustment := 2.0
return &gasAdjustment
}
60 changes: 60 additions & 0 deletions test/interchain/chainspec/cosmosHub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package chainspec

import (
"testing"

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

const (
// TODO: As of this writing, gaia has no official releases with the ICA
// controller enabled. However, they do have it enabled on `main` so the
// Docker image below is a custom build from `main`. Replace this with an
// official release when available (likely >= 16.0.0).
cosmosDockerRepository = "docker.io/rootulp/gaia"
cosmosDockerVersion = "ica-controller"
cosmosUidGid = "1025:1025"
)

// GetCosmosHub returns a CosmosChain for the CosmosHub.
func GetCosmosHub(t *testing.T) *cosmos.CosmosChain {
factory := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{cosmosHub})
chains, err := factory.Chains(t.Name())
require.NoError(t, err)
return chains[0].(*cosmos.CosmosChain)
}

var cosmosHub = &interchaintest.ChainSpec{
Name: "gaia",
ChainConfig: ibc.ChainConfig{
Name: "gaia",
Type: "cosmos",
ChainID: "gaia",
Bin: "gaiad",
Bech32Prefix: "cosmos",
Denom: "uatom",
GasPrices: "0.01uatom",
GasAdjustment: *gasAdjustment(),
TrustingPeriod: "504hours",
NoHostMount: false,
Images: cosmosDockerImages(),
UsingNewGenesisCommand: true,
},
NumValidators: numValidators(),
NumFullNodes: numFullNodes(),
GasAdjustment: gasAdjustment(), // the default gas estimation fails to create a client on Cosmos Hub so we need to bump it up.
}

func cosmosDockerImages() []ibc.DockerImage {
return []ibc.DockerImage{
{
Repository: cosmosDockerRepository,
Version: cosmosDockerVersion,
UidGid: cosmosUidGid,
},
}
}
Loading

0 comments on commit 5ba1b83

Please sign in to comment.