Skip to content

Commit

Permalink
chore: adding MsgChannelUpgradeTimeout fields and sdk.Msg interfa…
Browse files Browse the repository at this point in the history
…ce impl (#1830)

* adding fields to MsgChannelUpgradeCancel and gen protos

* impl sdk.Msg interface for MsgChannelUpgradeCancel. adding tests

* renaming proof arg

* adding upgrade timeout sdk.Msg impl
  • Loading branch information
damiannolan committed Aug 5, 2022
1 parent 690feee commit 0fed3d0
Show file tree
Hide file tree
Showing 5 changed files with 648 additions and 121 deletions.
12 changes: 12 additions & 0 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3174,6 +3174,18 @@ MsgChannelUpgradeInitResponse defines the MsgChannelUpgradeInit response type
MsgChannelUpgradeTimeout defines the request type for the ChannelUpgradeTimeout rpc


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `port_id` | [string](#string) | | |
| `channel_id` | [string](#string) | | |
| `counterparty_channel` | [Channel](#ibc.core.channel.v1.Channel) | | |
| `previous_error_receipt` | [ErrorReceipt](#ibc.core.channel.v1.ErrorReceipt) | | |
| `proof_channel` | [bytes](#bytes) | | |
| `proof_error_receipt` | [bytes](#bytes) | | |
| `proof_height` | [ibc.core.client.v1.Height](#ibc.core.client.v1.Height) | | |
| `signer` | [string](#string) | | |





Expand Down
55 changes: 50 additions & 5 deletions modules/core/04-channel/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

import (
"encoding/base64"
"errors"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -764,18 +763,64 @@ var _ sdk.Msg = &MsgChannelUpgradeTimeout{}

// NewMsgChannelUpgradeTimeout constructs a new MsgChannelUpgradeTimeout
// nolint:interfacer
func NewMsgChannelUpgradeTimeout() *MsgChannelUpgradeTimeout {
return &MsgChannelUpgradeTimeout{}
func NewMsgChannelUpgradeTimeout(
portID, channelID string,
counterpartyChannel Channel,
errorReceipt ErrorReceipt,
proofChannel, proofErrorReceipt []byte,
proofHeight clienttypes.Height,
signer string,
) *MsgChannelUpgradeTimeout {
return &MsgChannelUpgradeTimeout{
PortId: portID,
ChannelId: channelID,
CounterpartyChannel: counterpartyChannel,
PreviousErrorReceipt: errorReceipt,
ProofChannel: proofChannel,
ProofErrorReceipt: proofErrorReceipt,
ProofHeight: proofHeight,
Signer: signer,
}
}

// ValidateBasic implements sdk.Msg
func (msg MsgChannelUpgradeTimeout) ValidateBasic() error {
return errors.New("error method not implemented")
if err := host.PortIdentifierValidator(msg.PortId); err != nil {
return sdkerrors.Wrap(err, "invalid port ID")
}

if !IsValidChannelID(msg.ChannelId) {
return ErrInvalidChannelIdentifier
}

if len(msg.ProofChannel) == 0 {
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
}

if msg.ProofHeight.IsZero() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidHeight, "proof height must be non-zero")
}

if msg.CounterpartyChannel.State != OPEN {
return sdkerrors.Wrapf(ErrInvalidChannelState, "expected: %s, got: %s", OPEN, msg.CounterpartyChannel.State)
}

_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
}

return nil
}

// GetSigners implements sdk.Msg
func (msg MsgChannelUpgradeTimeout) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{}
signer, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
panic(err)
}

return []sdk.AccAddress{signer}
}

var _ sdk.Msg = &MsgChannelUpgradeCancel{}
Expand Down
93 changes: 93 additions & 0 deletions modules/core/04-channel/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,99 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() {
}
}

func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutValidateBasic() {
var msg *types.MsgChannelUpgradeTimeout

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"success",
func() {},
true,
},
{
"invalid port identifier",
func() {
msg.PortId = invalidPort
},
false,
},
{
"invalid channel identifier",
func() {
msg.ChannelId = invalidChannel
},
false,
},
{
"cannot submit an empty proof",
func() {
msg.ProofChannel = emptyProof
},
false,
},
{
"proof height must be > 0",
func() {
msg.ProofHeight = clienttypes.ZeroHeight()
},
false,
},
{
"invalid counterparty channel state",
func() {
msg.CounterpartyChannel.State = types.TRYUPGRADE
},
false,
},
{
"missing signer address",
func() {
msg.Signer = emptyAddr
},
false,
},
}

for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
msg = types.NewMsgChannelUpgradeTimeout(
ibctesting.MockPort, ibctesting.FirstChannelID,
types.Channel{State: types.OPEN}, types.ErrorReceipt{},
suite.proof, suite.proof,
height, addr,
)

tc.malleate()
err := msg.ValidateBasic()

if tc.expPass {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
}
})
}
}

func (suite *TypesTestSuite) TestMsgChannelUpgradeTimeoutGetSigners() {
expSigner, err := sdk.AccAddressFromBech32(addr)
suite.Require().NoError(err)

msg := types.NewMsgChannelUpgradeTimeout(
ibctesting.MockPort, ibctesting.FirstChannelID,
types.Channel{}, types.ErrorReceipt{},
suite.proof, suite.proof,
height, addr,
)

suite.Require().Equal([]sdk.AccAddress{expSigner}, msg.GetSigners())
}

func (suite *TypesTestSuite) TestMsgChannelUpgradeCancelValidateBasic() {
var msg *types.MsgChannelUpgradeCancel

Expand Down
Loading

0 comments on commit 0fed3d0

Please sign in to comment.