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

add UpdateChannel method to Endpoint #5725

Merged
merged 16 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
move error checking to update channel function
  • Loading branch information
crodriguezvega committed Feb 7, 2024
commit cf9a25ffe02ba27639abbb2644b232797bf9acc2
Original file line number Diff line number Diff line change
Expand Up @@ -1196,10 +1196,8 @@ func (suite *InterchainAccountsTestSuite) TestClosedChannelReopensWithMsgServer(
suite.Require().NoError(err)

// set the channel state to closed
err = path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })
suite.Require().NoError(err)
err = path.EndpointB.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })
path.EndpointB.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })

// reset endpoint channel ids
path.EndpointA.ChannelID = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ func (suite *KeeperTestSuite) TestOnChanOpenInit() {
err := SetupICAPath(path, TestOwnerAddress)
suite.Require().NoError(err)

err = path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })
suite.Require().NoError(err)

err = path.EndpointB.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })
path.EndpointB.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })

path.EndpointA.ChannelID = ""
path.EndpointB.ChannelID = ""
Expand Down Expand Up @@ -579,7 +576,7 @@ func (suite *KeeperTestSuite) TestOnChanUpgradeInit() {
{
name: "failure: cannot decode self version string",
malleate: func() {
suite.Require().NoError(path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.Version = invalidVersion }))
path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.Version = invalidVersion })
},
expError: icatypes.ErrUnknownDataType,
},
Expand Down Expand Up @@ -737,7 +734,7 @@ func (suite *KeeperTestSuite) TestOnChanUpgradeAck() {
{
name: "failure: cannot decode self version string",
malleate: func() {
suite.Require().NoError(path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.Version = invalidVersion }))
path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.Version = invalidVersion })
},
expError: icatypes.ErrUnknownDataType,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ func (suite *KeeperTestSuite) TestSendTx() {
{
"channel in INIT state - optimistic packet sends fail",
func() {
suite.Require().NoError(path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.INIT }))
path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.INIT })
},
false,
},
{
"sendPacket fails - channel closed",
func() {
suite.Require().NoError(path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED }))
path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })
},
false,
},
Expand Down
6 changes: 2 additions & 4 deletions modules/apps/27-interchain-accounts/host/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,8 @@ func (suite *InterchainAccountsTestSuite) TestControlAccountAfterChannelClose()
suite.assertBalance(icaAddr, expBalAfterFirstSend)

// close the channel
err = path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })
suite.Require().NoError(err)
err = path.EndpointB.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })
path.EndpointB.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })

// open a new channel on the same port
path.EndpointA.ChannelID = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ func (suite *KeeperTestSuite) openAndCloseChannel(path *ibctesting.Path) {
err = path.EndpointB.ChanOpenConfirm()
suite.Require().NoError(err)

err = path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })
suite.Require().NoError(err)

err = path.EndpointB.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })
path.EndpointB.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED })

path.EndpointA.ChannelID = ""
err = RegisterInterchainAccount(path.EndpointA, TestOwnerAddress)
Expand Down Expand Up @@ -503,8 +500,7 @@ func (suite *KeeperTestSuite) TestOnChanUpgradeTry() {
{
name: "failure: cannot decode version string from channel",
malleate: func() {
err := path.EndpointB.UpdateChannel(func(channel *channeltypes.Channel) { channel.Version = "invalid-metadata-string" })
suite.Require().NoError(err)
path.EndpointB.UpdateChannel(func(channel *channeltypes.Channel) { channel.Version = "invalid-metadata-string" })
},
expError: icatypes.ErrUnknownDataType,
},
Expand Down
3 changes: 1 addition & 2 deletions modules/core/03-connection/keeper/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ func (suite *KeeperTestSuite) TestVerifyChannelState() {
heightDiff = 5
}, false},
{"verification failed - changed channel state", func() {
err := path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.TRYOPEN })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.TRYOPEN })
}, false},
{"client status is not active - client is expired", func() {
clientState := path.EndpointA.GetClientState().(*ibctm.ClientState)
Expand Down
18 changes: 6 additions & 12 deletions modules/core/04-channel/keeper/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,7 @@ func (suite *KeeperTestSuite) TestChanCloseInit() {
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

// close channel
err := path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
}, false},
{"connection not found", func() {
path.Setup()
Expand Down Expand Up @@ -710,8 +709,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
path.Setup()
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

err := path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
}, true},
{"success with upgrade info", func() {
path.Setup()
Expand Down Expand Up @@ -748,8 +746,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
path.Setup()
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

err := path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
}, false},
{"connection not found", func() {
path.Setup()
Expand Down Expand Up @@ -779,8 +776,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
path.Setup()
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

err := path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })

heightDiff = 3
}, false},
Expand All @@ -793,8 +789,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
path.Setup()
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

err := path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })

channelCap = capabilitytypes.NewCapability(3)
}, false},
Expand All @@ -809,8 +804,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
err := path.EndpointB.ChanUpgradeInit()
suite.Require().NoError(err)

err = path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })

channelCap = capabilitytypes.NewCapability(3)
},
Expand Down
48 changes: 19 additions & 29 deletions modules/core/04-channel/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,26 @@ func (suite *KeeperTestSuite) TestSendPacket() {
path.Setup()
sourceChannel = path.EndpointA.ChannelID

err := path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
}, false},
{"channel is in INIT state", func() {
path.Setup()
sourceChannel = path.EndpointA.ChannelID

err := path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.INIT })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.INIT })
}, false},
{"channel is in TRYOPEN stage", func() {
path.Setup()
sourceChannel = path.EndpointA.ChannelID

err := path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.TRYOPEN })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.TRYOPEN })
}, false},
{"connection not found", func() {
// pass channel check
path.Setup()
sourceChannel = path.EndpointA.ChannelID

err := path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.ConnectionHops[0] = "invalid-connection" })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.ConnectionHops[0] = "invalid-connection" })

channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
}, false},
Expand Down Expand Up @@ -220,8 +216,7 @@ func (suite *KeeperTestSuite) TestSendPacket() {
path.Setup()
sourceChannel = path.EndpointA.ChannelID

err := path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHCOMPLETE })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHCOMPLETE })
},
false,
},
Expand Down Expand Up @@ -322,7 +317,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
func() {
// setup uses an UNORDERED channel
path.Setup()
suite.Require().NoError(path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }))
path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING })

sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)
Expand All @@ -336,7 +331,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
func() {
// setup uses an UNORDERED channel
path.Setup()
suite.Require().NoError(path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHCOMPLETE }))
path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHCOMPLETE })

sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)
Expand Down Expand Up @@ -370,7 +365,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

suite.Require().NoError(path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }))
path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING })

// set upgrade next sequence send to sequence + 1
counterpartyUpgrade := types.Upgrade{NextSequenceSend: sequence + 1}
Expand All @@ -387,7 +382,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

suite.Require().NoError(path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }))
path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING })
},
nil,
},
Expand All @@ -403,7 +398,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

suite.Require().NoError(path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }))
path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING })

// set upgrade next sequence send to sequence - 1
counterpartyUpgrade := types.Upgrade{NextSequenceSend: sequence - 1}
Expand Down Expand Up @@ -476,8 +471,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
path.Setup()
packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)

err := path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
},
types.ErrInvalidChannelState,
Expand Down Expand Up @@ -710,8 +704,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() {
packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
ack = ibcmock.MockAcknowledgement

err := path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING })
suite.Require().NoError(err)
path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING })
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
},
true,
Expand All @@ -723,8 +716,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() {
packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
ack = ibcmock.MockAcknowledgement

err := path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHCOMPLETE })
suite.Require().NoError(err)
path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHCOMPLETE })
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
},
true,
Expand All @@ -741,8 +733,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() {
packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
ack = ibcmock.MockAcknowledgement

err := path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
}, false},
{
Expand Down Expand Up @@ -903,7 +894,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {

channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

suite.Require().NoError(path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }))
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING })
},
expResult: func(commitment []byte, err error) {
suite.Require().NoError(err)
Expand Down Expand Up @@ -934,7 +925,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {

channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

suite.Require().NoError(path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }))
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING })

counterpartyUpgrade := types.Upgrade{
Timeout: types.NewTimeout(suite.chainB.GetTimeoutHeight(), 0),
Expand Down Expand Up @@ -985,7 +976,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {

channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

suite.Require().NoError(path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }))
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING })

upgrade := types.Upgrade{
Fields: types.NewUpgradeFields(types.UNORDERED, []string{ibctesting.FirstConnectionID}, ibcmock.UpgradeVersion),
Expand Down Expand Up @@ -1085,8 +1076,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {

packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)

err = path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
},
expResult: assertErr(types.ErrInvalidChannelState),
Expand All @@ -1098,7 +1088,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

suite.Require().NoError(path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHCOMPLETE }))
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHCOMPLETE })
},
expResult: func(commitment []byte, err error) {
suite.Require().Error(err)
Expand Down
Loading
Loading