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

Remove intertx for vanilla ICA #1159

Merged
merged 1 commit into from
Jan 23, 2023
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
50 changes: 11 additions & 39 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,15 @@ import (
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"

// Note: please do your research before using this in production app, this is a demo and not an officially
// supported IBC team implementation. It has no known issues, but do your own research before using it.
// intertx "github.com/cosmos/interchain-accounts/x/inter-tx"
// intertxkeeper "github.com/cosmos/interchain-accounts/x/inter-tx/keeper"
// intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types"
tmos "github.com/tendermint/tendermint/libs/os"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
)
Expand Down Expand Up @@ -230,7 +224,6 @@ var (
ibctm.AppModuleBasic{},
transfer.AppModuleBasic{},
ica.AppModuleBasic{},
// intertx.AppModuleBasic{},
ibcfee.AppModuleBasic{},
)

Expand Down Expand Up @@ -291,17 +284,15 @@ type WasmApp struct {
IBCFeeKeeper ibcfeekeeper.Keeper
ICAControllerKeeper icacontrollerkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
// InterTxKeeper intertxkeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
WasmKeeper wasm.Keeper
TransferKeeper ibctransferkeeper.Keeper
WasmKeeper wasm.Keeper

ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
// ScopedInterTxKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedIBCFeeKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedIBCFeeKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper

// the module manager
ModuleManager *module.Manager
Expand Down Expand Up @@ -346,7 +337,6 @@ func NewWasmApp(
ibchost.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey,
wasm.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey,
// intertxtypes.StoreKey,
)

tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -390,7 +380,6 @@ func NewWasmApp(
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
// scopedInterTxKeeper := app.CapabilityKeeper.ScopeToModule(intertxtypes.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
app.CapabilityKeeper.Seal()
Expand Down Expand Up @@ -593,14 +582,6 @@ func NewWasmApp(
app.MsgServiceRouter(),
)

// For wasmd we use the demo controller from https://github.com/cosmos/interchain-accounts but see notes below
// app.InterTxKeeper = intertxkeeper.NewKeeper(
// appCodec,
// keys[intertxtypes.StoreKey],
// app.ICAControllerKeeper,
// scopedInterTxKeeper,
// )

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
Expand Down Expand Up @@ -644,13 +625,11 @@ func NewWasmApp(
// Create Interchain Accounts Stack
// SendPacket, since it is originating from the application to core IBC:
// icaAuthModuleKeeper.SendTx -> icaController.SendPacket -> fee.SendPacket -> channel.SendPacket

// Note: please do your research before using this in production app, this is a demo and not an officially
// supported IBC team implementation. Do your own research before using it.
var icaControllerStack porttypes.IBCModule
// You will likely want to use your own reviewed and maintained ica auth module
// icaControllerStack = intertx.NewIBCModule(app.InterTxKeeper) // TODO: enable again
icaControllerStack = icacontroller.NewIBCMiddleware(icaControllerStack, app.ICAControllerKeeper)
// integration point for custom authentication modules
// see https://medium.com/the-interchain-foundation/ibc-go-v6-changes-to-interchain-accounts-and-how-it-impacts-your-chain-806c185300d7
var noAuthzModule porttypes.IBCModule
icaControllerStack = icacontroller.NewIBCMiddleware(noAuthzModule, app.ICAControllerKeeper)
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)

// RecvPacket, message that originates from core IBC and goes down to app, the flow is:
Expand All @@ -668,7 +647,6 @@ func NewWasmApp(
ibcRouter := porttypes.NewRouter().
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(wasm.ModuleName, wasmStack).
// AddRoute(intertxtypes.ModuleName, icaControllerStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack)
app.IBCKeeper.SetRouter(ibcRouter)
Expand Down Expand Up @@ -710,8 +688,6 @@ func NewWasmApp(
transfer.NewAppModule(app.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
// intertx.NewAppModule(appCodec, app.InterTxKeeper),
//
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
)

Expand All @@ -731,7 +707,6 @@ func NewWasmApp(
ibchost.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
// intertxtypes.ModuleName,
wasm.ModuleName,
)

Expand All @@ -747,7 +722,6 @@ func NewWasmApp(
ibchost.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
// intertxtypes.ModuleName,
wasm.ModuleName,
)

Expand All @@ -770,7 +744,6 @@ func NewWasmApp(
ibchost.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
// intertxtypes.ModuleName,
// wasm after ibc transfer
wasm.ModuleName,
}
Expand Down Expand Up @@ -834,7 +807,6 @@ func NewWasmApp(
app.ScopedWasmKeeper = scopedWasmKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper
app.ScopedICAControllerKeeper = scopedICAControllerKeeper
// app.ScopedInterTxKeeper = scopedInterTxKeeper

// In v0.46, the SDK introduces _postHandlers_. PostHandlers are like
// antehandlers, but are run _after_ the `runMsgs` execution. They are also
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ go 1.19
require (
github.com/CosmWasm/wasmvm v1.1.1
github.com/cosmos/cosmos-proto v1.0.0-beta.1
github.com/cosmos/cosmos-sdk v0.47.0-alpha2.0.20230109100323-89f5dd8df14d
github.com/cosmos/cosmos-sdk v0.47.0-rc1.0.20230116204658-efb7acbf244f
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.3
github.com/cosmos/iavl v0.19.4
github.com/cosmos/ibc-go/v6 v6.0.0-20221220115712-10d17379d669
github.com/cosmos/ics23/go v0.9.1-0.20221207100636-b1abd8678aab // indirect

//github.com/cosmos/interchain-accounts v0.2.4
github.com/docker/distribution v2.8.1+incompatible
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/golang/protobuf v1.5.2
Expand Down Expand Up @@ -59,7 +57,7 @@ require (
github.com/aws/aws-sdk-go v1.40.45 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s=
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U=
github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/btcutil v1.1.2 h1:XLMbX8JQEiwMcYft2EGi8zPUkoa0abKIU6/BJSRsjzQ=
Expand Down Expand Up @@ -165,8 +166,8 @@ github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk=
github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis=
github.com/cosmos/cosmos-proto v1.0.0-beta.1 h1:iDL5qh++NoXxG8hSy93FdYJut4XfgbShIocllGaXx/0=
github.com/cosmos/cosmos-proto v1.0.0-beta.1/go.mod h1:8k2GNZghi5sDRFw/scPL8gMSowT1vDA+5ouxL8GjaUE=
github.com/cosmos/cosmos-sdk v0.47.0-alpha2.0.20230109100323-89f5dd8df14d h1:+14Bju6eJ2GEcBfhUJKcv9rFJ2XvYL4TAkKzQ5imJuc=
github.com/cosmos/cosmos-sdk v0.47.0-alpha2.0.20230109100323-89f5dd8df14d/go.mod h1:yWd503ULBJ71Zuv7GD0/dYJuyeg4LGWAvjeI4wK/dfY=
github.com/cosmos/cosmos-sdk v0.47.0-rc1.0.20230116204658-efb7acbf244f h1:9vi9gj6qXCNOnnbXbnVvXhTWx9tMR53/yvee8x7VCaE=
github.com/cosmos/cosmos-sdk v0.47.0-rc1.0.20230116204658-efb7acbf244f/go.mod h1:8Xoer+iUxiZMhFsvHzkz5O6DvYI9qWND1cgmX0ZWSOI=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
Expand Down
116 changes: 62 additions & 54 deletions tests/e2e/ica_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package e2e

import (
//"bytes"
"bytes"
"testing"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
//"github.com/cosmos/cosmos-sdk/types/address"
"github.com/cosmos/cosmos-sdk/types/address"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/gogoproto/proto"
icacontrollertypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller/types"
hosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types"

// icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types"
// channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v6/testing"
//intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types"
//"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

wasmibctesting "github.com/CosmWasm/wasmd/x/wasm/ibctesting"
)

func TestICA(t *testing.T) {
t.Skip("deactivated due to sdk verion incompatibility")
// scenario:
// given a host and controller chain
// when an ica is registered on the controller chain
Expand All @@ -32,53 +32,61 @@ func TestICA(t *testing.T) {
hostParams := hosttypes.NewParams(true, []string{sdk.MsgTypeURL(&banktypes.MsgSend{})})
hostChain.App.ICAHostKeeper.SetParams(hostChain.GetContext(), hostParams)

// controllerChain := coord.GetChain(ibctesting.GetChainID(2))
controllerChain := coord.GetChain(ibctesting.GetChainID(2))

path := wasmibctesting.NewPath(controllerChain, hostChain)
coord.SetupConnections(path)

ownerAddr := sdk.AccAddress(controllerChain.SenderPrivKey.PubKey().Address())
msg := icacontrollertypes.NewMsgRegisterInterchainAccount(path.EndpointA.ConnectionID, ownerAddr.String(), "")
res, err := controllerChain.SendMsgs(msg)
require.NoError(t, err)
chanID, portID, version := parseIBCChannelEvents(t, res)

// next open channels on both sides
path.EndpointA.ChannelID = chanID
path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
PortID: portID,
Version: version,
Order: channeltypes.ORDERED,
}
path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{
PortID: icatypes.HostPortID,
Version: icatypes.Version,
Order: channeltypes.ORDERED,
}
coord.CreateChannels(path)

// assert ICA exists on controller
icaRsp, err := controllerChain.App.ICAControllerKeeper.InterchainAccount(sdk.WrapSDKContext(controllerChain.GetContext()), &icacontrollertypes.QueryInterchainAccountRequest{
Owner: ownerAddr.String(),
ConnectionId: path.EndpointA.ConnectionID,
})
require.NoError(t, err)
icaAddr := sdk.MustAccAddressFromBech32(icaRsp.GetAddress())
hostChain.Fund(icaAddr, sdk.NewInt(1_000))

// submit a tx
targetAddr := sdk.AccAddress(bytes.Repeat([]byte{1}, address.Len))
sendCoin := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))
payloadMsg := banktypes.NewMsgSend(icaAddr, targetAddr, sdk.NewCoins(sendCoin))
rawPayloadData, err := icatypes.SerializeCosmosTx(controllerChain.Codec, []proto.Message{payloadMsg})
require.NoError(t, err)
payloadPacket := icatypes.InterchainAccountPacketData{
Type: icatypes.EXECUTE_TX,
Data: rawPayloadData,
Memo: "testing",
}
relativeTimeout := uint64(time.Minute.Nanoseconds()) // note this is in nanoseconds
msgSendTx := icacontrollertypes.NewMsgSendTx(ownerAddr.String(), path.EndpointA.ConnectionID, relativeTimeout, payloadPacket)
res, err = controllerChain.SendMsgs(msgSendTx)
require.NoError(t, err)

assert.Equal(t, 1, len(controllerChain.PendingSendPackets))
require.NoError(t, coord.RelayAndAckPendingPackets(path))

//path := wasmibctesting.NewPath(controllerChain, hostChain)
//coord.SetupConnections(path)
//
//ownerAddr := sdk.AccAddress(controllerChain.SenderPrivKey.PubKey().Address())
//msg := intertxtypes.NewMsgRegisterAccount(ownerAddr.String(), path.EndpointA.ConnectionID, "")
//res, err := controllerChain.SendMsgs(msg)
//chanID, portID, version := parseIBCChannelEvents(t, res)
//
//// next open channels on both sides
//path.EndpointA.ChannelID = chanID
//path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
// PortID: portID,
// Version: version,
// Order: channeltypes.ORDERED,
//}
//path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{
// PortID: icatypes.PortID,
// Version: icatypes.Version,
// Order: channeltypes.ORDERED,
//}
//coord.CreateChannels(path)
//
//// assert ICA exists on controller
//icaRsp, err := controllerChain.App.InterTxKeeper.InterchainAccount(sdk.WrapSDKContext(controllerChain.GetContext()), &intertxtypes.QueryInterchainAccountRequest{
// Owner: ownerAddr.String(),
// ConnectionId: path.EndpointA.ConnectionID,
//})
//require.NoError(t, err)
//icaAddr := sdk.MustAccAddressFromBech32(icaRsp.InterchainAccountAddress)
//hostChain.Fund(icaAddr, sdk.NewInt(1_000))
//
//// submit a tx
//targetAddr := sdk.AccAddress(bytes.Repeat([]byte{1}, address.Len))
//sendCoin := sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))
//payloadMsg := banktypes.NewMsgSend(icaAddr, targetAddr, sdk.NewCoins(sendCoin))
//msg2, err := intertxtypes.NewMsgSubmitTx(payloadMsg, path.EndpointA.ConnectionID, ownerAddr.String())
//require.NoError(t, err)
//res, err = controllerChain.SendMsgs(msg2)
//require.NoError(t, err)
//
//assert.Equal(t, 1, len(controllerChain.PendingSendPackets))
//require.NoError(t, coord.RelayAndAckPendingPackets(path))
//
//gotBalance := hostChain.Balance(targetAddr, sdk.DefaultBondDenom)
//assert.Equal(t, sendCoin.String(), gotBalance.String())
gotBalance := hostChain.Balance(targetAddr, sdk.DefaultBondDenom)
assert.Equal(t, sendCoin.String(), gotBalance.String())
}

func parseIBCChannelEvents(t *testing.T, res *sdk.Result) (string, string, string) {
Expand Down