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 9 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1196,9 +1196,9 @@ func (suite *InterchainAccountsTestSuite) TestClosedChannelReopensWithMsgServer(
suite.Require().NoError(err)

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

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

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

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

path.EndpointA.ChannelID = ""
Expand Down Expand Up @@ -579,9 +579,7 @@ func (suite *KeeperTestSuite) TestOnChanUpgradeInit() {
{
name: "failure: cannot decode self version string",
malleate: func() {
ch := path.EndpointA.GetChannel()
ch.Version = invalidVersion
path.EndpointA.SetChannel(ch)
suite.Require().NoError(path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.Version = invalidVersion }))
},
expError: icatypes.ErrUnknownDataType,
},
Expand Down Expand Up @@ -739,9 +737,7 @@ func (suite *KeeperTestSuite) TestOnChanUpgradeAck() {
{
name: "failure: cannot decode self version string",
malleate: func() {
channel := path.EndpointA.GetChannel()
channel.Version = invalidVersion
path.EndpointA.SetChannel(channel)
suite.Require().NoError(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,19 +98,14 @@ func (suite *KeeperTestSuite) TestSendTx() {
{
"channel in INIT state - optimistic packet sends fail",
func() {
channel, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
suite.Require().True(found)

channel.State = channeltypes.INIT
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, channel)
suite.Require().NoError(path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.INIT }))
},
false,
},
{
"sendPacket fails - channel closed",
func() {
err := path.EndpointA.SetChannelState(channeltypes.CLOSED)
suite.Require().NoError(err)
suite.Require().NoError(path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.CLOSED }))
},
false,
},
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/27-interchain-accounts/host/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,9 @@ func (suite *InterchainAccountsTestSuite) TestControlAccountAfterChannelClose()
suite.assertBalance(icaAddr, expBalAfterFirstSend)

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

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

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

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

path.EndpointA.ChannelID = ""
Expand Down
12 changes: 6 additions & 6 deletions modules/core/04-channel/keeper/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ func (suite *KeeperTestSuite) TestChanCloseInit() {
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

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

err := path.EndpointA.SetChannelState(types.CLOSED)
err := path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
}, true},
{"channel doesn't exist", func() {
Expand All @@ -746,7 +746,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
path.Setup()
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)

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

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

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

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

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

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

channelCap = capabilitytypes.NewCapability(3)
Expand Down
55 changes: 17 additions & 38 deletions modules/core/04-channel/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,21 @@ func (suite *KeeperTestSuite) TestSendPacket() {
path.Setup()
sourceChannel = path.EndpointA.ChannelID

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

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

err := path.EndpointA.SetChannelState(types.TRYOPEN)
err := path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.TRYOPEN })
suite.Require().NoError(err)
}, false},
{"connection not found", func() {
Expand Down Expand Up @@ -328,9 +328,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
func() {
// setup uses an UNORDERED channel
path.Setup()
channel := path.EndpointB.GetChannel()
channel.State = types.FLUSHING
path.EndpointB.SetChannel(channel)
suite.Require().NoError(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 @@ -344,9 +342,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
func() {
// setup uses an UNORDERED channel
path.Setup()
channel := path.EndpointB.GetChannel()
channel.State = types.FLUSHCOMPLETE
path.EndpointB.SetChannel(channel)
suite.Require().NoError(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 @@ -380,9 +376,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)

channel := path.EndpointB.GetChannel()
channel.State = types.FLUSHING
path.EndpointB.SetChannel(channel)
suite.Require().NoError(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 @@ -399,9 +393,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)

channel := path.EndpointB.GetChannel()
channel.State = types.FLUSHING
path.EndpointB.SetChannel(channel)
suite.Require().NoError(path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }))
},
nil,
},
Expand All @@ -417,9 +409,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)

channel := path.EndpointB.GetChannel()
channel.State = types.FLUSHING
path.EndpointB.SetChannel(channel)
suite.Require().NoError(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 @@ -492,7 +482,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.SetChannelState(types.CLOSED)
err := path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
},
Expand Down Expand Up @@ -726,7 +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.SetChannelState(types.FLUSHING)
err := path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING })
suite.Require().NoError(err)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
},
Expand All @@ -739,7 +729,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.SetChannelState(types.FLUSHCOMPLETE)
err := path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHCOMPLETE })
suite.Require().NoError(err)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
},
Expand All @@ -757,7 +747,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.SetChannelState(types.CLOSED)
err := path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
}, false},
Expand Down Expand Up @@ -919,9 +909,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {

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

channel := path.EndpointA.GetChannel()
channel.State = types.FLUSHING
path.EndpointA.SetChannel(channel)
suite.Require().NoError(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 @@ -952,10 +940,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {

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

channel := path.EndpointA.GetChannel()
channel.State = types.FLUSHING

path.EndpointA.SetChannel(channel)
suite.Require().NoError(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 @@ -1006,10 +991,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {

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

channel := path.EndpointA.GetChannel()
channel.State = types.FLUSHING

path.EndpointA.SetChannel(channel)
suite.Require().NoError(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 @@ -1109,7 +1091,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.SetChannelState(types.CLOSED)
err = path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED })
suite.Require().NoError(err)
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
},
Expand All @@ -1122,10 +1104,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)

channel := path.EndpointA.GetChannel()
channel.State = types.FLUSHCOMPLETE

path.EndpointA.SetChannel(channel)
suite.Require().NoError(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