Skip to content

Commit

Permalink
feat: support ibc
Browse files Browse the repository at this point in the history
  • Loading branch information
johnletey committed May 18, 2024
1 parent d7af506 commit ad3ef0a
Show file tree
Hide file tree
Showing 16 changed files with 379 additions and 38 deletions.
26 changes: 26 additions & 0 deletions e2e/clients.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"body": {
"messages": [
{
"@type": "/ibc.core.client.v1.MsgRecoverClient",
"signer": "noble13am065qmk680w86wya4u9refhnssqwcvgs0sfk",
"subject_client_id": "07-tendermint-0",
"substitute_client_id": "07-tendermint-1"
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
74 changes: 74 additions & 0 deletions e2e/clients_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package e2e

import (
_ "embed"
"path"
"testing"

"cosmossdk.io/math"

"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
"github.com/stretchr/testify/require"
)

//go:embed clients.json
var Clients []byte

// TestClientSubstitution tests the module's ability to substitute IBC clients.
func TestClientSubstitution(t *testing.T) {
t.Parallel()

var wrapper Wrapper
ctx, reporter, rly := Suite(t, &wrapper, true)
validator := wrapper.chain.Validators[0]

nobleChainID, gaiaChainID := wrapper.chain.Config().ChainID, wrapper.gaia.Config().ChainID
pathName := "transfer"

err := rly.GeneratePath(ctx, reporter, nobleChainID, gaiaChainID, pathName)
require.NoError(t, err)

err = rly.CreateClient(ctx, reporter, nobleChainID, gaiaChainID, pathName, ibc.CreateClientOptions{
TrustingPeriod: "30s",
})
require.NoError(t, err)
err = rly.CreateClient(ctx, reporter, gaiaChainID, nobleChainID, pathName, ibc.CreateClientOptions{})
require.NoError(t, err)
require.NoError(t, testutil.WaitForBlocks(ctx, 1, wrapper.chain, wrapper.gaia))

err = rly.CreateConnections(ctx, reporter, pathName)
require.NoError(t, err)
require.NoError(t, testutil.WaitForBlocks(ctx, 1, wrapper.chain, wrapper.gaia))

err = rly.CreateChannel(ctx, reporter, pathName, ibc.DefaultChannelOpts())
require.NoError(t, err)

users := interchaintest.GetAndFundTestUsers(t, ctx, "user", math.NewInt(5_000_000), wrapper.chain, wrapper.gaia)
require.NoError(t, testutil.WaitForBlocks(ctx, 10, wrapper.chain, wrapper.gaia))

_, err = validator.SendIBCTransfer(ctx, "channel-0", users[0].KeyName(), ibc.WalletAmount{
Address: users[1].FormattedAddress(),
Denom: "uusdc",
Amount: math.NewInt(1_000_000),
}, ibc.TransferOptions{})
require.ErrorContains(t, err, "client state is not active")

res := rly.Exec(ctx, reporter, []string{"rly", "tx", "client", nobleChainID, gaiaChainID, pathName, "--override", "--home", rly.HomeDir()}, nil)
require.NoError(t, res.Err)

require.NoError(t, validator.WriteFile(ctx, Clients, "clients.json"))
_, err = validator.ExecTx(
ctx, wrapper.owner.KeyName(),
"authority", "execute", path.Join(validator.HomeDir(), "clients.json"),
)
require.NoError(t, err)

_, err = validator.SendIBCTransfer(ctx, "channel-0", users[0].KeyName(), ibc.WalletAmount{
Address: users[1].FormattedAddress(),
Denom: "uusdc",
Amount: math.NewInt(1_000_000),
}, ibc.TransferOptions{})
require.NoError(t, err)
}
2 changes: 1 addition & 1 deletion e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ require (
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.1.2 // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.0 // indirect
github.com/cosmos/ibc-go/v8 v8.2.0 // indirect
github.com/cosmos/ibc-go/v8 v8.3.0 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1.0.20240424193412-7cd900ad2a74 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
Expand Down
3 changes: 1 addition & 2 deletions e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ github.com/cosmos/iavl v1.1.2 h1:zL9FK7C4L/P4IF1Dm5fIwz0WXCnn7Bp1M2FxH0ayM7Y=
github.com/cosmos/iavl v1.1.2/go.mod h1:jLeUvm6bGT1YutCaL2fIar/8vGUE8cPZvh/gXEWDaDM=
github.com/cosmos/ibc-go/modules/capability v1.0.0 h1:r/l++byFtn7jHYa09zlAdSeevo8ci1mVZNO9+V0xsLE=
github.com/cosmos/ibc-go/modules/capability v1.0.0/go.mod h1:D81ZxzjZAe0ZO5ambnvn1qedsFQ8lOwtqicG6liLBco=
github.com/cosmos/ibc-go/v8 v8.2.0 h1:7oCzyy1sZCcgpeQLnHxC56brsSz3KWwQGKXalXwXFzE=
github.com/cosmos/ibc-go/v8 v8.2.0/go.mod h1:wj3qx75iC/XNnsMqbPDCIGs0G6Y3E/lo3bdqCyoCy+8=
github.com/cosmos/ibc-go/v8 v8.3.0 h1:fdW2S7NjZYFhSwmCaFjjyDv80kI1ePOJDQmco4qrnD0=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1.0.20240424193412-7cd900ad2a74 h1:6atU/xizTL10q6EprP7oRuvfgUP2F6puvutnVoE+FRc=
Expand Down
11 changes: 0 additions & 11 deletions e2e/ibc_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion e2e/ownership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestOwnershipTransfer(t *testing.T) {
t.Parallel()

var wrapper Wrapper
ctx := Suite(t, &wrapper)
ctx, _, _ := Suite(t, &wrapper, false)
validator := wrapper.chain.Validators[0]

EnsureOwner(t, wrapper, ctx, wrapper.owner.FormattedAddress())
Expand Down
2 changes: 1 addition & 1 deletion e2e/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestParameterUpdate(t *testing.T) {
t.Parallel()

var wrapper Wrapper
ctx := Suite(t, &wrapper)
ctx, _, _ := Suite(t, &wrapper, false)
validator := wrapper.chain.Validators[0]

EnsureParams(t, wrapper, ctx, 0)
Expand Down
2 changes: 1 addition & 1 deletion e2e/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestScheduleUpgrade(t *testing.T) {
t.Parallel()

var wrapper Wrapper
ctx := Suite(t, &wrapper)
ctx, _, _ := Suite(t, &wrapper, false)
validator := wrapper.chain.Validators[0]

EnsureUpgrade(t, wrapper, ctx, "", 0)
Expand Down
48 changes: 41 additions & 7 deletions e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,30 @@ import (
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/relayer/rly"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)

type Wrapper struct {
chain *cosmos.CosmosChain
gaia *cosmos.CosmosChain

owner ibc.Wallet
pendingOwner ibc.Wallet
}

func Suite(t *testing.T, wrapper *Wrapper) (ctx context.Context) {
func Suite(t *testing.T, wrapper *Wrapper, ibcEnabled bool) (ctx context.Context, execReporter *testreporter.RelayerExecReporter, relayer *rly.CosmosRelayer) {
ctx = context.Background()
logger := zaptest.NewLogger(t)
reporter := testreporter.NewNopReporter()
execReporter := reporter.RelayerExecReporter(t)
execReporter = reporter.RelayerExecReporter(t)
client, network := interchaintest.DockerSetup(t)

numValidators, numFullNodes := 1, 0

factory := interchaintest.NewBuiltinChainFactory(logger, []*interchaintest.ChainSpec{
specs := []*interchaintest.ChainSpec{
{
Name: "authority",
Version: "local",
Expand Down Expand Up @@ -92,7 +94,19 @@ func Suite(t *testing.T, wrapper *Wrapper) (ctx context.Context) {
},
},
},
})
}
if ibcEnabled {
specs = append(specs, &interchaintest.ChainSpec{
Name: "gaia",
Version: "latest",
NumValidators: &numValidators,
NumFullNodes: &numFullNodes,
ChainConfig: ibc.ChainConfig{
ChainID: "cosmoshub-4",
},
})
}
factory := interchaintest.NewBuiltinChainFactory(logger, specs)

chains, err := factory.Chains(t.Name())
require.NoError(t, err)
Expand All @@ -101,10 +115,30 @@ func Suite(t *testing.T, wrapper *Wrapper) (ctx context.Context) {
wrapper.chain = noble

interchain := interchaintest.NewInterchain().AddChain(noble)
if ibcEnabled {
relayer = interchaintest.NewBuiltinRelayerFactory(
ibc.CosmosRly,
logger,
).Build(t, client, network).(*rly.CosmosRelayer)

gaia := chains[1].(*cosmos.CosmosChain)
wrapper.gaia = gaia

interchain = interchain.
AddChain(gaia).
AddRelayer(relayer, "relayer").
AddLink(interchaintest.InterchainLink{
Chain1: noble,
Chain2: gaia,
Relayer: relayer,
Path: "transfer",
})
}
require.NoError(t, interchain.Build(ctx, execReporter, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: true,
}))

t.Cleanup(func() {
Expand Down
Loading

0 comments on commit ad3ef0a

Please sign in to comment.