Skip to content

Commit

Permalink
add counterparty not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
crodriguezvega committed Aug 26, 2024
1 parent eab030b commit 97b5777
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 32 deletions.
1 change: 1 addition & 0 deletions modules/core/02-client/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
6 changes: 3 additions & 3 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -670,7 +670,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacketV2() {
func() {
packet.SourceChannel = "invalid-client"
},
channeltypes.ErrChannelNotFound,
clienttypes.ErrCounterpartyNotFound,
false,
},
{
Expand Down Expand Up @@ -996,7 +996,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacketV2() {

packetKey = host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())
},
channeltypes.ErrChannelNotFound,
clienttypes.ErrCounterpartyNotFound,
false,
},
}
Expand Down
22 changes: 11 additions & 11 deletions modules/core/packet-server/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, clienttypes.ErrClientNotFound
return 0, errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, sourceChannel)
}
destChannel := counterparty.ClientId

Expand Down Expand Up @@ -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 it was indeed sent by our counterparty.
counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel)
if !ok {
return "", clienttypes.ErrClientNotFound
return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.DestinationChannel)
}
if counterparty.ClientId != packet.SourceChannel {
return "", channeltypes.ErrInvalidChannelIdentifier
Expand Down Expand Up @@ -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 it was indeed sent by our counterparty.
counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.DestinationChannel)
if !ok {
return clienttypes.ErrClientNotFound
return errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.DestinationChannel)
}
if counterparty.ClientId != packet.SourceChannel {
return channeltypes.ErrInvalidChannelIdentifier
Expand Down Expand Up @@ -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 it was indeed sent by our counterparty.
counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.SourceChannel)
if !ok {
return "", clienttypes.ErrClientNotFound
return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.SourceChannel)
}

if counterparty.ClientId != packet.DestinationChannel {
Expand Down Expand Up @@ -338,7 +338,7 @@ func (k Keeper) TimeoutPacket(
// is the expected counterparty
counterparty, ok := k.ClientKeeper.GetCounterparty(ctx, packet.SourceChannel)
if !ok {
return "", clienttypes.ErrClientNotFound
return "", errorsmod.Wrap(clienttypes.ErrCounterpartyNotFound, packet.SourceChannel)
}

if counterparty.ClientId != packet.DestinationChannel {
Expand Down
55 changes: 37 additions & 18 deletions modules/core/packet-server/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,39 @@ func (suite *KeeperTestSuite) TestSendPacket() {
malleate func()
expError error
}{
{"success", func() {}, nil},
{"counterparty not found", func() {
packet.SourceChannel = ibctesting.FirstChannelID
}, clienttypes.ErrClientNotFound},
{"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 {
Expand Down Expand Up @@ -139,7 +158,7 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
func() {
packet.DestinationChannel = ibctesting.FirstChannelID
},
clienttypes.ErrClientNotFound,
clienttypes.ErrCounterpartyNotFound,
},
{
"failure: client is not active",
Expand Down Expand Up @@ -246,7 +265,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() {
func() {
packet.DestinationChannel = ibctesting.FirstChannelID
},
clienttypes.ErrClientNotFound,
clienttypes.ErrCounterpartyNotFound,
},
{
"failure: counterparty client identifier different than source channel",
Expand Down Expand Up @@ -347,7 +366,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
func() {
packet.SourceChannel = ibctesting.FirstChannelID
},
clienttypes.ErrClientNotFound,
clienttypes.ErrCounterpartyNotFound,
},
{
"failure: counterparty client identifier different than source channel",
Expand Down Expand Up @@ -489,7 +508,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {

packet.SourceChannel = ibctesting.FirstChannelID
},
clienttypes.ErrClientNotFound,
clienttypes.ErrCounterpartyNotFound,
},
{
"failure: counterparty client identifier different than source channel",
Expand Down

0 comments on commit 97b5777

Please sign in to comment.