diff --git a/modules/core/02-client/types/errors.go b/modules/core/02-client/types/errors.go index 116e322ac6d..f663019ab0f 100644 --- a/modules/core/02-client/types/errors.go +++ b/modules/core/02-client/types/errors.go @@ -39,4 +39,5 @@ var ( ErrRouteNotFound = errorsmod.Register(SubModuleName, 32, "light client module route not found") ErrClientTypeNotSupported = errorsmod.Register(SubModuleName, 33, "client type not supported") ErrInvalidCounterparty = errorsmod.Register(SubModuleName, 34, "invalid counterparty") + ErrCounterpartyNotFound = errorsmod.Register(SubModuleName, 35, "counterparty not found") ) diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index 43e59b1c130..4a87d594d09 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -307,7 +307,7 @@ func (suite *KeeperTestSuite) TestRecvPacketV2() { // any non-nil value of packet is valid suite.Require().NotNil(packet) }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrCounterpartyNotFound, false, false, false, @@ -670,7 +670,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacketV2() { func() { packet.SourceChannel = "invalid-client" }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrCounterpartyNotFound, false, }, { @@ -996,7 +996,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacketV2() { packetKey = host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrCounterpartyNotFound, false, }, } diff --git a/modules/core/packet-server/keeper/keeper.go b/modules/core/packet-server/keeper/keeper.go index b816df12fd8..894ebb59b4a 100644 --- a/modules/core/packet-server/keeper/keeper.go +++ b/modules/core/packet-server/keeper/keeper.go @@ -59,7 +59,7 @@ func (k Keeper) SendPacket( // Lookup counterparty associated with our source channel to retrieve the destination channel counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, sourceChannel) if !ok { - return 0, channeltypes.ErrChannelNotFound + return 0, errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, sourceChannel) } destChannel := counterparty.ClientId @@ -131,11 +131,11 @@ func (k Keeper) RecvPacket( return "", channeltypes.ErrInvalidPacket } - // Lookup counterparty associated with our channel and ensure that it was packet was indeed - // sent by our counterparty. + // Lookup counterparty associated with our channel and ensure + // that the packet was indeed sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel) if !ok { - return "", channeltypes.ErrChannelNotFound + return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.DestinationChannel) } if counterparty.ClientId != packet.SourceChannel { return "", channeltypes.ErrInvalidChannelIdentifier @@ -206,11 +206,11 @@ func (k Keeper) WriteAcknowledgement( return channeltypes.ErrInvalidPacket } - // Lookup counterparty associated with our channel and ensure that it was packet was indeed - // sent by our counterparty. + // Lookup counterparty associated with our channel and ensure + // that the packet was indeed sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel) if !ok { - return channeltypes.ErrChannelNotFound + return errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.DestinationChannel) } if counterparty.ClientId != packet.SourceChannel { return channeltypes.ErrInvalidChannelIdentifier @@ -263,11 +263,11 @@ func (k Keeper) AcknowledgePacket( return "", channeltypes.ErrInvalidPacket } - // Lookup counterparty associated with our channel and ensure that it was packet was indeed - // sent by our counterparty. + // Lookup counterparty associated with our channel and ensure + // that the packet was indeed sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.SourceChannel) if !ok { - return "", channeltypes.ErrChannelNotFound + return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.SourceChannel) } if counterparty.ClientId != packet.DestinationChannel { @@ -334,11 +334,11 @@ func (k Keeper) TimeoutPacket( if packet.ProtocolVersion != channeltypes.IBC_VERSION_2 { return "", channeltypes.ErrInvalidPacket } - // Lookup counterparty associated with our channel and ensure that destination channel - // is the expected counterparty + // Lookup counterparty associated with our channel and ensure + // that the packet was indeed sent by our counterparty. counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.SourceChannel) if !ok { - return "", channeltypes.ErrChannelNotFound + return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.SourceChannel) } if counterparty.ClientId != packet.DestinationChannel { diff --git a/modules/core/packet-server/keeper/keeper_test.go b/modules/core/packet-server/keeper/keeper_test.go index 513a5412dbb..183f32a6be4 100644 --- a/modules/core/packet-server/keeper/keeper_test.go +++ b/modules/core/packet-server/keeper/keeper_test.go @@ -58,20 +58,39 @@ func (suite *KeeperTestSuite) TestSendPacket() { malleate func() expError error }{ - {"success", func() {}, nil}, - {"counterparty not found", func() { - packet.SourceChannel = ibctesting.FirstChannelID - }, channeltypes.ErrChannelNotFound}, - {"packet failed basic validation", func() { - // invalid data - packet.Data = nil - }, channeltypes.ErrInvalidPacket}, - {"client status invalid", func() { - path.EndpointA.FreezeClient() - }, clienttypes.ErrClientNotActive}, - {"timeout elapsed", func() { - packet.TimeoutTimestamp = 1 - }, channeltypes.ErrTimeoutElapsed}, + { + "success", + func() {}, + nil, + }, + { + "counterparty not found", + func() { + packet.SourceChannel = ibctesting.FirstChannelID + }, + clienttypes.ErrCounterpartyNotFound, + }, + { + "packet failed basic validation", + func() { + // invalid data + packet.Data = nil + }, + channeltypes.ErrInvalidPacket, + }, + { + "client status invalid", + func() { + path.EndpointA.FreezeClient() + }, + clienttypes.ErrClientNotActive, + }, + { + "timeout elapsed", func() { + packet.TimeoutTimestamp = 1 + }, + channeltypes.ErrTimeoutElapsed, + }, } for i, tc := range testCases { @@ -139,7 +158,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() { func() { packet.DestinationChannel = ibctesting.FirstChannelID }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrCounterpartyNotFound, }, { "failure: client is not active", @@ -246,7 +265,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { func() { packet.DestinationChannel = ibctesting.FirstChannelID }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrCounterpartyNotFound, }, { "failure: counterparty client identifier different than source channel", @@ -347,7 +366,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { func() { packet.SourceChannel = ibctesting.FirstChannelID }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrCounterpartyNotFound, }, { "failure: counterparty client identifier different than source channel", @@ -489,7 +508,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() { packet.SourceChannel = ibctesting.FirstChannelID }, - channeltypes.ErrChannelNotFound, + clienttypes.ErrCounterpartyNotFound, }, { "failure: counterparty client identifier different than source channel",