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

feat: adding ChannelUpgradeConfirm rpc and msgs #4302

Merged
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
1 change: 1 addition & 0 deletions modules/core/04-channel/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
&MsgChannelUpgradeInit{},
&MsgChannelUpgradeTry{},
&MsgChannelUpgradeAck{},
&MsgChannelUpgradeConfirm{},
&MsgChannelUpgradeOpen{},
&MsgChannelUpgradeTimeout{},
&MsgChannelUpgradeCancel{},
Expand Down
65 changes: 65 additions & 0 deletions modules/core/04-channel/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,71 @@ func (msg MsgChannelUpgradeAck) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{signer}
}

var _ sdk.Msg = &MsgChannelUpgradeConfirm{}

// NewMsgChannelUpgradeConfirm constructs a new MsgChannelUpgradeConfirm
func NewMsgChannelUpgradeConfirm(
portID,
channelID string,
counterpartyChannelState State,
counterpartyUpgrade Upgrade,
proofChannel,
proofUpgrade []byte,
proofHeight clienttypes.Height,
signer string,
) *MsgChannelUpgradeConfirm {
return &MsgChannelUpgradeConfirm{
PortId: portID,
ChannelId: channelID,
CounterpartyChannelState: counterpartyChannelState,
CounterpartyUpgrade: counterpartyUpgrade,
ProofChannel: proofChannel,
ProofUpgrade: proofUpgrade,
ProofHeight: proofHeight,
Signer: signer,
}
}

// ValidateBasic implements sdk.Msg
func (msg MsgChannelUpgradeConfirm) ValidateBasic() error {
if err := host.PortIdentifierValidator(msg.PortId); err != nil {
return errorsmod.Wrap(err, "invalid port ID")
}

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

if !collections.Contains(msg.CounterpartyChannelState, []State{STATE_FLUSHING, STATE_FLUSHCOMPLETE}) {
return errorsmod.Wrapf(ErrInvalidChannelState, "expected channel state to be one of: %s or %s, got: %s", STATE_FLUSHING, STATE_FLUSHCOMPLETE, msg.CounterpartyChannelState)
}

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

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

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

return msg.CounterpartyUpgrade.ValidateBasic()
}

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

return []sdk.AccAddress{signer}
}

var _ sdk.Msg = &MsgChannelUpgradeOpen{}

// NewMsgChannelUpgradeOpen constructs a new MsgChannelUpgradeOpen
Expand Down
99 changes: 99 additions & 0 deletions modules/core/04-channel/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,105 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeAckValidateBasic() {
}
}

func (suite *TypesTestSuite) TestMsgChannelUpgradeConfirmValidateBasic() {
var msg *types.MsgChannelUpgradeConfirm

testCases := []struct {
name string
malleate func()
expPass bool
Copy link
Contributor

Choose a reason for hiding this comment

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

noting that we should switch these to check for errors. given that all current tests don't do this, I'll open an issue to keep track of it and punt it for later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed! Just kept the existing format to conform for now 👍

}{
{
"success",
func() {},
true,
},
{
"success: counterparty state set to FLUSHCOMPLETE",
func() {
msg.CounterpartyChannelState = types.STATE_FLUSHCOMPLETE
},
true,
},
{
"invalid port identifier",
func() {
msg.PortId = invalidPort
},
false,
},
{
"invalid channel identifier",
func() {
msg.ChannelId = invalidChannel
},
false,
},
{
"invalid counterparty channel state",
func() {
msg.CounterpartyChannelState = types.CLOSED
},
false,
},
{
"cannot submit an empty channel proof",
func() {
msg.ProofChannel = emptyProof
},
false,
},
{
"cannot submit an empty upgrade proof",
func() {
msg.ProofUpgrade = emptyProof
},
false,
},
{
"missing signer address",
func() {
msg.Signer = emptyAddr
},
false,
},
}

for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
counterpartyUpgrade := types.NewUpgrade(
types.NewUpgradeFields(types.UNORDERED, []string{ibctesting.FirstConnectionID}, mock.Version),
types.NewTimeout(clienttypes.NewHeight(0, 10000), timeoutTimestamp),
1,
)

msg = types.NewMsgChannelUpgradeConfirm(
ibctesting.MockPort, ibctesting.FirstChannelID,
types.STATE_FLUSHING, counterpartyUpgrade, 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) TestMsgChannelUpgradeConfirmGetSigners() {
expSigner, err := sdk.AccAddressFromBech32(addr)
suite.Require().NoError(err)

msg := &types.MsgChannelUpgradeConfirm{Signer: addr}
suite.Require().Equal([]sdk.AccAddress{expSigner}, msg.GetSigners())
}

func (suite *TypesTestSuite) TestMsgChannelUpgradeOpenValidateBasic() {
var msg *types.MsgChannelUpgradeOpen

Expand Down
Loading
Loading