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

test: interchain accounts via interchaintest #3308

Merged
merged 10 commits into from
Apr 22, 2024
Merged
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
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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 @@ -84,14 +86,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 @@ -159,10 +161,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
Comment on lines +169 to +173
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add this to the CI then

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant to add it to CI now because this test currently uses a static docker image https://github.com/rootulp/celestia-app/blob/08ca4d2fe7971d69b71a39a1e2c91dbdb50e72ce/test/interchain/chainspec/celestia.go#L16

so even if a PR breaks ICA, we wouldn't get signal by running it in CI unless we update that static docker image to use a Docker image that is created on a per PR basis. Will create a follow up issue to add it to CI

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #3358


## 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(),
rootulp marked this conversation as resolved.
Show resolved Hide resolved
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
Loading