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

chore: adding sdk.Msg impl for ics27 MsgSubmitTx #2135

Merged
merged 42 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d20f2d2
add protos/rpcs, boilerplate
charleenfei Aug 23, 2022
48e44b6
typo
charleenfei Aug 23, 2022
3cacc48
typo
charleenfei Aug 23, 2022
ab10570
Merge branch 'main' into charly/2052_sendtx_rpc_msgs
charleenfei Aug 24, 2022
5eb8eb2
update re comments
charleenfei Aug 24, 2022
1748c3a
update msg
charleenfei Aug 24, 2022
c0a5259
Merge branch 'main' into charly/2052_sendtx_rpc_msgs
charleenfei Aug 24, 2022
aa6ce16
merge main
charleenfei Aug 24, 2022
a4a7708
initial commit, adding all types
damiannolan Aug 26, 2022
81d74fd
finish up correcting compile errors
charleenfei Aug 26, 2022
bd25b55
goformat
charleenfei Aug 26, 2022
6e6fe62
Merge branch 'refactor_genesis_types' into charly/2052_sendtx_rpc_msgs
charleenfei Aug 26, 2022
fee8080
update to new proto
charleenfei Aug 26, 2022
6dc32f8
wip
charleenfei Aug 26, 2022
d59e0a9
msg tests
charleenfei Aug 26, 2022
a605ba6
update proto
charleenfei Aug 29, 2022
a0a21ff
register interfaces update
charleenfei Aug 29, 2022
6c508cb
Merge branch 'main' into ics27/refactor-genesis-types
charleenfei Aug 29, 2022
a9e44a1
format
charleenfei Aug 29, 2022
a8bb9ca
Merge branch 'main' into charly/2052_sendtx_rpc_msgs
charleenfei Aug 29, 2022
c897d0b
update changelog
charleenfei Aug 29, 2022
ab6a796
Merge branch 'ics27/refactor-genesis-types' of github.com:cosmos/ibc-…
charleenfei Aug 29, 2022
656ca38
update changelog
charleenfei Aug 29, 2022
7f4274e
Merge branch 'ics27/refactor-genesis-types' into charly/2052_sendtx_r…
charleenfei Aug 29, 2022
4eec1dc
update msgSubmitTxResp
charleenfei Aug 29, 2022
ba01304
Merge branch 'main' into charly/submittx_sdkMsg
charleenfei Aug 29, 2022
e26f181
Merge branch 'main' into charly/2052_sendtx_rpc_msgs
charleenfei Aug 30, 2022
864cbfb
merge
charleenfei Aug 30, 2022
c48a179
Merge branch 'main' into charly/submittx_sdkMsg
charleenfei Aug 30, 2022
a4c1c2f
update docs
charleenfei Aug 30, 2022
1f0828a
update proto
charleenfei Aug 30, 2022
679d47c
update proto
charleenfei Aug 30, 2022
26b6d6f
update ordering
charleenfei Aug 30, 2022
f7e5b6f
Merge branch 'charly/2052_sendtx_rpc_msgs' into charly/submittx_sdkMsg
charleenfei Aug 30, 2022
5c44166
update docs
charleenfei Aug 30, 2022
f8bcdd7
update msg
charleenfei Aug 30, 2022
0bb39cb
update re:commments
charleenfei Aug 30, 2022
230bc60
update failing test
charleenfei Aug 30, 2022
7d176e2
Merge branch 'main' into charly/submittx_sdkMsg
charleenfei Aug 30, 2022
3e4c596
update re: commments
charleenfei Aug 30, 2022
5bbf39e
Merge branch 'charly/submittx_sdkMsg' of github.com:cosmos/ibc-go int…
charleenfei Aug 30, 2022
c84f677
Merge branch 'main' into charly/submittx_sdkMsg
charleenfei Aug 30, 2022
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
264 changes: 148 additions & 116 deletions docs/ibc/proto-docs.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
genesistypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/genesis/types"
host "github.com/cosmos/ibc-go/v5/modules/core/24-host"
)

// InitGenesis initializes the interchain accounts controller application state from a provided genesis state
func InitGenesis(ctx sdk.Context, keeper Keeper, state icatypes.ControllerGenesisState) {
func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.ControllerGenesisState) {
for _, portID := range state.Ports {
if !keeper.IsBound(ctx, portID) {
cap := keeper.BindPort(ctx, portID)
Expand All @@ -32,8 +32,8 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state icatypes.ControllerGenesi
}

// ExportGenesis returns the interchain accounts controller exported genesis
func ExportGenesis(ctx sdk.Context, keeper Keeper) icatypes.ControllerGenesisState {
return icatypes.NewControllerGenesisState(
func ExportGenesis(ctx sdk.Context, keeper Keeper) genesistypes.ControllerGenesisState {
return genesistypes.NewControllerGenesisState(
keeper.GetAllActiveChannels(ctx),
keeper.GetAllInterchainAccounts(ctx),
keeper.GetAllPorts(ctx),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ package keeper_test
import (
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/keeper"
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
genesistypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/genesis/types"
ibctesting "github.com/cosmos/ibc-go/v5/testing"
)

func (suite *KeeperTestSuite) TestInitGenesis() {
suite.SetupTest()

genesisState := icatypes.ControllerGenesisState{
ActiveChannels: []icatypes.ActiveChannel{
genesisState := genesistypes.ControllerGenesisState{
ActiveChannels: []genesistypes.ActiveChannel{
{
ConnectionId: ibctesting.FirstConnectionID,
PortId: TestPortID,
ChannelId: ibctesting.FirstChannelID,
},
},
InterchainAccounts: []icatypes.RegisteredInterchainAccount{
InterchainAccounts: []genesistypes.RegisteredInterchainAccount{
{
ConnectionId: ibctesting.FirstConnectionID,
PortId: TestPortID,
Expand Down
13 changes: 7 additions & 6 deletions modules/apps/27-interchain-accounts/controller/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
genesistypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/genesis/types"
icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v5/modules/core/24-host"
Expand Down Expand Up @@ -134,16 +135,16 @@ func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, connectionID, portID strin
}

// GetAllActiveChannels returns a list of all active interchain accounts controller channels and their associated connection and port identifiers
func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel {
func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []genesistypes.ActiveChannel {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.ActiveChannelKeyPrefix))
defer iterator.Close()

var activeChannels []icatypes.ActiveChannel
var activeChannels []genesistypes.ActiveChannel
for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")

ch := icatypes.ActiveChannel{
ch := genesistypes.ActiveChannel{
ConnectionId: keySplit[2],
PortId: keySplit[1],
ChannelId: string(iterator.Value()),
Expand Down Expand Up @@ -180,15 +181,15 @@ func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, connectionID, portI
}

// GetAllInterchainAccounts returns a list of all registered interchain account addresses and their associated connection and controller port identifiers
func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []icatypes.RegisteredInterchainAccount {
func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []genesistypes.RegisteredInterchainAccount {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.OwnerKeyPrefix))

var interchainAccounts []icatypes.RegisteredInterchainAccount
var interchainAccounts []genesistypes.RegisteredInterchainAccount
for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")

acc := icatypes.RegisteredInterchainAccount{
acc := genesistypes.RegisteredInterchainAccount{
ConnectionId: keySplit[2],
PortId: keySplit[1],
AccountAddress: string(iterator.Value()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto"

genesistypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/genesis/types"
icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v5/testing"
Expand Down Expand Up @@ -179,7 +180,7 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() {

suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, expectedPortID, expectedChannelID)

expectedChannels := []icatypes.ActiveChannel{
expectedChannels := []genesistypes.ActiveChannel{
{
ConnectionId: ibctesting.FirstConnectionID,
PortId: TestPortID,
Expand Down Expand Up @@ -213,7 +214,7 @@ func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() {

suite.chainA.GetSimApp().ICAControllerKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, expectedPortID, expectedAccAddr)

expectedAccounts := []icatypes.RegisteredInterchainAccount{
expectedAccounts := []genesistypes.RegisteredInterchainAccount{
{
ConnectionId: ibctesting.FirstConnectionID,
PortId: TestPortID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ func (k Keeper) RegisterAccount(goCtx context.Context, msg *types.MsgRegisterAcc
ChannelId: channelID,
}, nil
}

// SubmitTx defines a rpc handler for MsgSubmitTx
func (k Keeper) SubmitTx(goCtx context.Context, msg *types.MsgSubmitTx) (*types.MsgSubmitTxResponse, error) {
return &types.MsgSubmitTxResponse{}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import (
// RegisterInterfaces registers the interchain accounts controller message types using the provided InterfaceRegistry
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil), &MsgRegisterAccount{})
registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSubmitTx{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ import (

// ICA Controller sentinel errors
var (
ErrControllerSubModuleDisabled = sdkerrors.Register(SubModuleName, 2, "controller submodule is disabled")
ErrControllerSubModuleDisabled = sdkerrors.Register(SubModuleName, 1, "controller submodule is disabled")
ErrInvalidTimeout = sdkerrors.Register(SubModuleName, 2, "timeout height and timestamp cannot both be zero")
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
ErrEmptyMsgs = sdkerrors.Register(SubModuleName, 3, "interchain accounts data packets array cannot be empty")
)
48 changes: 48 additions & 0 deletions modules/apps/27-interchain-accounts/controller/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types"
host "github.com/cosmos/ibc-go/v5/modules/core/24-host"
)

Expand Down Expand Up @@ -46,3 +48,49 @@ func (msg MsgRegisterAccount) GetSigners() []sdk.AccAddress {

return []sdk.AccAddress{accAddr}
}

// NewMsgSubmitTx creates a new instance of MsgSubmitTx
func NewMsgSubmitTx(connectionID, owner string, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, msgs []*icatypes.InterchainAccountPacketData) *MsgSubmitTx {
return &MsgSubmitTx{
ConnectionId: connectionID,
Owner: owner,
TimeoutHeight: timeoutHeight,
TimeoutTimestamp: timeoutTimestamp,
Msgs: msgs,
}
}

// ValidateBasic implements sdk.Msg
func (msg MsgSubmitTx) ValidateBasic() error {
if err := host.ConnectionIdentifierValidator(msg.ConnectionId); err != nil {
return sdkerrors.Wrap(err, "invalid connection ID")
}

if strings.TrimSpace(msg.Owner) == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "owner address cannot be empty")
}

if _, err := sdk.AccAddressFromBech32(msg.Owner); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "failed to parse owner address: %s", msg.Owner)
}

if msg.TimeoutHeight.IsZero() && msg.TimeoutTimestamp == 0 {
return sdkerrors.Wrap(ErrInvalidTimeout, "msg timeout height and msg timeout timestamp cannot both be 0")
}

if len(msg.Msgs) == 0 {
return sdkerrors.Wrap(ErrEmptyMsgs, "interchain accounts data packets array cannot be empty")
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
}

return nil
}

// GetSigners implements sdk.Msg
func (msg MsgSubmitTx) GetSigners() []sdk.AccAddress {
accAddr, err := sdk.AccAddressFromBech32(msg.Owner)
if err != nil {
panic(err)
}

return []sdk.AccAddress{accAddr}
}
120 changes: 120 additions & 0 deletions modules/apps/27-interchain-accounts/controller/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/stretchr/testify/require"

"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
feetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types"
clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types"
ibctesting "github.com/cosmos/ibc-go/v5/testing"
"github.com/cosmos/ibc-go/v5/testing/simapp"
)

func TestMsgRegisterAccountValidateBasic(t *testing.T) {
Expand Down Expand Up @@ -94,3 +97,120 @@ func TestMsgRegisterAccountGetSigners(t *testing.T) {
msg := types.NewMsgRegisterAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "")
require.Equal(t, []sdk.AccAddress{expSigner}, msg.GetSigners())
}

func TestMsgSubmitTxValidateBasic(t *testing.T) {
var msg *types.MsgSubmitTx

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"success",
func() {},
true,
},
{
"connection id is invalid",
func() {
msg.ConnectionId = ""
},
false,
},
{
"owner address is empty",
func() {
msg.Owner = ""
},
false,
},
{
"owner address is invalid",
func() {
msg.Owner = "invalid_address"
},
false,
},
{
"timeout height and timestamp are both not set",
func() {
msg.TimeoutTimestamp = 0
},
false,
},
{
"messages array is empty",
func() {
msg.Msgs = []*icatypes.InterchainAccountPacketData{}
},
false,
},
}

for i, tc := range testCases {

msgBankSend := &banktypes.MsgSend{
FromAddress: ibctesting.TestAccAddress,
ToAddress: ibctesting.TestAccAddress,
Amount: ibctesting.TestCoins,
}

data, err := icatypes.SerializeCosmosTx(simapp.MakeTestEncodingConfig().Marshaler, []sdk.Msg{msgBankSend})
require.NoError(t, err)

packetData := &icatypes.InterchainAccountPacketData{
Type: icatypes.EXECUTE_TX,
Data: data,
}

msg = types.NewMsgSubmitTx(
ibctesting.FirstConnectionID,
ibctesting.TestAccAddress,
clienttypes.ZeroHeight(),
100000,
[]*icatypes.InterchainAccountPacketData{
packetData,
},
)

tc.malleate()

err = msg.ValidateBasic()
if tc.expPass {
require.NoError(t, err, "valid test case %d failed: %s", i, tc.name)
} else {
require.Error(t, err, "invalid test case %d passed: %s", i, tc.name)
}
}
}

func TestMsgSubmitTxGetSigners(t *testing.T) {
expSigner, err := sdk.AccAddressFromBech32(ibctesting.TestAccAddress)
require.NoError(t, err)

msgBankSend := &banktypes.MsgSend{
FromAddress: ibctesting.TestAccAddress,
ToAddress: ibctesting.TestAccAddress,
Amount: ibctesting.TestCoins,
}

data, err := icatypes.SerializeCosmosTx(simapp.MakeTestEncodingConfig().Marshaler, []sdk.Msg{msgBankSend})
require.NoError(t, err)

packetData := &icatypes.InterchainAccountPacketData{
Type: icatypes.EXECUTE_TX,
Data: data,
}

msg := types.NewMsgSubmitTx(
ibctesting.FirstConnectionID,
ibctesting.TestAccAddress,
clienttypes.ZeroHeight(),
100000,
[]*icatypes.InterchainAccountPacketData{
packetData,
},
)
require.Equal(t, []sdk.AccAddress{expSigner}, msg.GetSigners())
}
Loading