Skip to content

Commit

Permalink
wip wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Sep 7, 2023
1 parent b0cb9f1 commit 528caac
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 194 deletions.
3 changes: 2 additions & 1 deletion e2e/tests/interchain_accounts/localhost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ func (s *LocalhostInterchainAccountsTestSuite) TestInterchainAccounts_ReopenChan
})

t.Run("close interchain accounts host channel end", func(t *testing.T) {
msgCloseConfirm := channeltypes.NewMsgChannelCloseConfirm(icatypes.HostPortID, msgChanOpenTryRes.ChannelId, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress())
// Pass in zero for counterpartyUpgradeSequence given that channel has not undergone any upgrades.
msgCloseConfirm := channeltypes.NewMsgChannelCloseConfirm(icatypes.HostPortID, msgChanOpenTryRes.ChannelId, localhost.SentinelProof, clienttypes.ZeroHeight(), rlyWallet.FormattedAddress(), 0)

txResp := s.BroadcastMessages(ctx, chainA, rlyWallet, msgCloseConfirm)
s.AssertTxSuccess(txResp)
Expand Down
13 changes: 9 additions & 4 deletions modules/core/04-channel/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ func (k Keeper) ChanCloseConfirm(
chanCap *capabilitytypes.Capability,
proofInit []byte,
proofHeight exported.Height,
counterpartyUpgradeSequence uint64,
) error {
if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) {
return errorsmod.Wrap(types.ErrChannelCapabilityNotFound, "caller does not own capability for channel, port ID (%s) channel ID (%s)")
Expand Down Expand Up @@ -460,10 +461,14 @@ func (k Keeper) ChanCloseConfirm(
counterpartyHops := []string{connectionEnd.GetCounterparty().GetConnectionID()}

counterparty := types.NewCounterparty(portID, channelID)
expectedChannel := types.NewChannel(
types.CLOSED, channel.Ordering, counterparty,
counterpartyHops, channel.Version,
)
expectedChannel := types.Channel{
State: types.CLOSED,
Ordering: channel.Ordering,
Counterparty: counterparty,
ConnectionHops: counterpartyHops,
Version: channel.Version,
UpgradeSequence: counterpartyUpgradeSequence,
}

if err := k.connectionKeeper.VerifyChannelState(
ctx, connectionEnd, proofHeight, proofInit,
Expand Down
14 changes: 8 additions & 6 deletions modules/core/04-channel/keeper/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,10 @@ func (suite *KeeperTestSuite) TestChanCloseInit() {
// bypassed on chainA by setting the channel state in the ChannelKeeper.
func (suite *KeeperTestSuite) TestChanCloseConfirm() {
var (
path *ibctesting.Path
channelCap *capabilitytypes.Capability
heightDiff uint64
path *ibctesting.Path
channelCap *capabilitytypes.Capability
heightDiff uint64
counterpartyUpgradeSequence uint64
)

testCases := []testCase{
Expand Down Expand Up @@ -799,8 +800,9 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
for _, tc := range testCases {
tc := tc
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
suite.SetupTest() // reset
heightDiff = 0 // must explicitly be changed
suite.SetupTest() // reset
heightDiff = 0 // must explicitly be changed
counterpartyUpgradeSequence = 0 // must explicitly be changed
path = ibctesting.NewPath(suite.chainA, suite.chainB)

tc.malleate()
Expand All @@ -810,7 +812,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {

err := suite.chainB.App.GetIBCKeeper().ChannelKeeper.ChanCloseConfirm(
suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, ibctesting.FirstChannelID, channelCap,
proof, malleateHeight(proofHeight, heightDiff),
proof, malleateHeight(proofHeight, heightDiff), counterpartyUpgradeSequence,
)

if tc.expPass {
Expand Down
12 changes: 9 additions & 3 deletions modules/core/04-channel/keeper/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func (k Keeper) TimeoutOnClose(
proofClosed []byte,
proofHeight exported.Height,
nextSequenceRecv uint64,
counterpartyUpgradeSequence uint64,
) error {
channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel())
if !found {
Expand Down Expand Up @@ -270,9 +271,14 @@ func (k Keeper) TimeoutOnClose(
counterpartyHops := []string{connectionEnd.GetCounterparty().GetConnectionID()}

counterparty := types.NewCounterparty(packet.GetSourcePort(), packet.GetSourceChannel())
expectedChannel := types.NewChannel(
types.CLOSED, channel.Ordering, counterparty, counterpartyHops, channel.Version,
)
expectedChannel := types.Channel{
State: types.CLOSED,
Ordering: channel.Ordering,
Counterparty: counterparty,
ConnectionHops: counterpartyHops,
Version: channel.Version,
UpgradeSequence: counterpartyUpgradeSequence,
}

// check that the opposing channel end has closed
if err := k.connectionKeeper.VerifyChannelState(
Expand Down
27 changes: 19 additions & 8 deletions modules/core/04-channel/keeper/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,12 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() {
// channel on chainB after the packet commitment has been created.
func (suite *KeeperTestSuite) TestTimeoutOnClose() {
var (
path *ibctesting.Path
packet types.Packet
chanCap *capabilitytypes.Capability
nextSeqRecv uint64
ordered bool
path *ibctesting.Path
packet types.Packet
chanCap *capabilitytypes.Capability
nextSeqRecv uint64
counterpartyUpgradeSequence uint64
ordered bool
)

testCases := []testCase{
Expand Down Expand Up @@ -687,8 +688,9 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {
suite.Run(fmt.Sprintf("Case %s, %d/%d tests", tc.msg, i, len(testCases)), func() {
var proof []byte

suite.SetupTest() // reset
nextSeqRecv = 1 // must be explicitly changed
suite.SetupTest() // reset
nextSeqRecv = 1 // must be explicitly changed
counterpartyUpgradeSequence = 0 // must be explicitly changed
path = ibctesting.NewPath(suite.chainA, suite.chainB)

tc.malleate()
Expand All @@ -705,7 +707,16 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {
proof, _ = suite.chainB.QueryProof(unorderedPacketKey)
}

err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.TimeoutOnClose(suite.chainA.GetContext(), chanCap, packet, proof, proofClosed, proofHeight, nextSeqRecv)
err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.TimeoutOnClose(
suite.chainA.GetContext(),
chanCap,
packet,
proof,
proofClosed,
proofHeight,
nextSeqRecv,
counterpartyUpgradeSequence,
)

if tc.expPass {
suite.Require().NoError(err)
Expand Down
27 changes: 15 additions & 12 deletions modules/core/04-channel/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,15 @@ func (msg MsgChannelCloseInit) GetSigners() []sdk.AccAddress {
// NewMsgChannelCloseConfirm creates a new MsgChannelCloseConfirm instance
func NewMsgChannelCloseConfirm(
portID, channelID string, proofInit []byte, proofHeight clienttypes.Height,
signer string,
signer string, counterpartyUpgradeSequence uint64,
) *MsgChannelCloseConfirm {
return &MsgChannelCloseConfirm{
PortId: portID,
ChannelId: channelID,
ProofInit: proofInit,
ProofHeight: proofHeight,
Signer: signer,
PortId: portID,
ChannelId: channelID,
ProofInit: proofInit,
ProofHeight: proofHeight,
Signer: signer,
CounterpartyUpgradeSequence: counterpartyUpgradeSequence,
}
}

Expand Down Expand Up @@ -377,14 +378,16 @@ func NewMsgTimeoutOnClose(
packet Packet, nextSequenceRecv uint64,
proofUnreceived, proofClose []byte,
proofHeight clienttypes.Height, signer string,
counterpartyUpgradeSequence uint64,
) *MsgTimeoutOnClose {
return &MsgTimeoutOnClose{
Packet: packet,
NextSequenceRecv: nextSequenceRecv,
ProofUnreceived: proofUnreceived,
ProofClose: proofClose,
ProofHeight: proofHeight,
Signer: signer,
Packet: packet,
NextSequenceRecv: nextSequenceRecv,
ProofUnreceived: proofUnreceived,
ProofClose: proofClose,
ProofHeight: proofHeight,
Signer: signer,
CounterpartyUpgradeSequence: counterpartyUpgradeSequence,
}
}

Expand Down
28 changes: 14 additions & 14 deletions modules/core/04-channel/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,14 @@ func (suite *TypesTestSuite) TestMsgChannelCloseConfirmValidateBasic() {
msg *types.MsgChannelCloseConfirm
expPass bool
}{
{"", types.NewMsgChannelCloseConfirm(portid, chanid, suite.proof, height, addr), true},
{"too short port id", types.NewMsgChannelCloseConfirm(invalidShortPort, chanid, suite.proof, height, addr), false},
{"too long port id", types.NewMsgChannelCloseConfirm(invalidLongPort, chanid, suite.proof, height, addr), false},
{"port id contains non-alpha", types.NewMsgChannelCloseConfirm(invalidPort, chanid, suite.proof, height, addr), false},
{"too short channel id", types.NewMsgChannelCloseConfirm(portid, invalidShortChannel, suite.proof, height, addr), false},
{"too long channel id", types.NewMsgChannelCloseConfirm(portid, invalidLongChannel, suite.proof, height, addr), false},
{"channel id contains non-alpha", types.NewMsgChannelCloseConfirm(portid, invalidChannel, suite.proof, height, addr), false},
{"empty proof", types.NewMsgChannelCloseConfirm(portid, chanid, emptyProof, height, addr), false},
{"", types.NewMsgChannelCloseConfirm(portid, chanid, suite.proof, height, addr, 1), true},
{"too short port id", types.NewMsgChannelCloseConfirm(invalidShortPort, chanid, suite.proof, height, addr, 1), false},
{"too long port id", types.NewMsgChannelCloseConfirm(invalidLongPort, chanid, suite.proof, height, addr, 1), false},
{"port id contains non-alpha", types.NewMsgChannelCloseConfirm(invalidPort, chanid, suite.proof, height, addr, 1), false},
{"too short channel id", types.NewMsgChannelCloseConfirm(portid, invalidShortChannel, suite.proof, height, addr, 1), false},
{"too long channel id", types.NewMsgChannelCloseConfirm(portid, invalidLongChannel, suite.proof, height, addr, 1), false},
{"channel id contains non-alpha", types.NewMsgChannelCloseConfirm(portid, invalidChannel, suite.proof, height, addr, 1), false},
{"empty proof", types.NewMsgChannelCloseConfirm(portid, chanid, emptyProof, height, addr, 1), false},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -382,12 +382,12 @@ func (suite *TypesTestSuite) TestMsgTimeoutOnCloseValidateBasic() {
msg *types.MsgTimeoutOnClose
expPass bool
}{
{"success", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr), true},
{"seq 0", types.NewMsgTimeoutOnClose(packet, 0, suite.proof, suite.proof, height, addr), false},
{"signer address is empty", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, emptyAddr), false},
{"empty proof", types.NewMsgTimeoutOnClose(packet, 1, emptyProof, suite.proof, height, addr), false},
{"empty proof close", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, emptyProof, height, addr), false},
{"invalid packet", types.NewMsgTimeoutOnClose(invalidPacket, 1, suite.proof, suite.proof, height, addr), false},
{"success", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, addr, 1), true},
{"seq 0", types.NewMsgTimeoutOnClose(packet, 0, suite.proof, suite.proof, height, addr, 1), false},
{"signer address is empty", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, suite.proof, height, emptyAddr, 1), false},
{"empty proof", types.NewMsgTimeoutOnClose(packet, 1, emptyProof, suite.proof, height, addr, 1), false},
{"empty proof close", types.NewMsgTimeoutOnClose(packet, 1, suite.proof, emptyProof, height, addr, 1), false},
{"invalid packet", types.NewMsgTimeoutOnClose(invalidPacket, 1, suite.proof, suite.proof, height, addr, 1), false},
}

for _, tc := range testCases {
Expand Down
Loading

0 comments on commit 528caac

Please sign in to comment.