Skip to content

Commit

Permalink
fixed lint errors in icacallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Aug 23, 2024
1 parent af9debb commit ad10e1e
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 29 deletions.
15 changes: 7 additions & 8 deletions x/stakeibc/keeper/icacallbacks_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package keeper
import (
"fmt"

"github.com/Stride-Labs/stride/v23/utils"
icacallbackstypes "github.com/Stride-Labs/stride/v23/x/icacallbacks/types"
recordstypes "github.com/Stride-Labs/stride/v23/x/records/types"
"github.com/Stride-Labs/stride/v23/x/stakeibc/types"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/proto"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"

"github.com/Stride-Labs/stride/v23/utils"
icacallbackstypes "github.com/Stride-Labs/stride/v23/x/icacallbacks/types"
recordstypes "github.com/Stride-Labs/stride/v23/x/records/types"
"github.com/Stride-Labs/stride/v23/x/stakeibc/types"
)

// Marshal claim callback args
Expand All @@ -28,8 +28,7 @@ func (k Keeper) MarshalClaimCallbackArgs(ctx sdk.Context, claimCallback types.Cl
func (k Keeper) UnmarshalClaimCallbackArgs(ctx sdk.Context, claimCallback []byte) (*types.ClaimCallback, error) {
unmarshalledDelegateCallback := types.ClaimCallback{}
if err := proto.Unmarshal(claimCallback, &unmarshalledDelegateCallback); err != nil {
k.Logger(ctx).Error(fmt.Sprintf("UnmarshalClaimCallbackArgs %v", err.Error()))
return nil, err
return nil, errorsmod.Wrap(err, "unable to unmarshal claim callback args")
}
return &unmarshalledDelegateCallback, nil
}
Expand All @@ -41,7 +40,7 @@ func (k Keeper) ClaimCallback(ctx sdk.Context, packet channeltypes.Packet, ackRe
// Fetch callback args
claimCallback, err := k.UnmarshalClaimCallbackArgs(ctx, args)
if err != nil {
return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal claim callback args: %s", err.Error()))
return err
}
chainId := claimCallback.ChainId
k.Logger(ctx).Info(utils.LogICACallbackWithHostZone(chainId, ICACallbackID_Claim,
Expand Down
2 changes: 1 addition & 1 deletion x/stakeibc/keeper/icacallbacks_claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (s *KeeperTestSuite) TestClaimCallback_WrongCallbackArgs() {
invalidCallbackArgs := []byte("random bytes")

err := s.App.StakeibcKeeper.ClaimCallback(s.Ctx, tc.validArgs.packet, tc.validArgs.ackResponse, invalidCallbackArgs)
s.Require().EqualError(err, "Unable to unmarshal claim callback args: unexpected EOF: unable to unmarshal data structure")
s.Require().ErrorContains(err, "unable to unmarshal claim callback args")
}

func (s *KeeperTestSuite) TestClaimCallback_RecordNotFound() {
Expand Down
5 changes: 2 additions & 3 deletions x/stakeibc/keeper/icacallbacks_rebalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ func (k Keeper) MarshalRebalanceCallbackArgs(ctx sdk.Context, rebalanceCallback
func (k Keeper) UnmarshalRebalanceCallbackArgs(ctx sdk.Context, rebalanceCallback []byte) (*types.RebalanceCallback, error) {
unmarshalledRebalanceCallback := types.RebalanceCallback{}
if err := proto.Unmarshal(rebalanceCallback, &unmarshalledRebalanceCallback); err != nil {
k.Logger(ctx).Error(fmt.Sprintf("UnmarshalRebalanceCallbackArgs %v", err.Error()))
return nil, err
return nil, errorsmod.Wrap(err, "unable to unmarshal rebalance callback args")
}
return &unmarshalledRebalanceCallback, nil
}
Expand All @@ -41,7 +40,7 @@ func (k Keeper) RebalanceCallback(ctx sdk.Context, packet channeltypes.Packet, a
// Fetch callback args
rebalanceCallback, err := k.UnmarshalRebalanceCallbackArgs(ctx, args)
if err != nil {
return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal rebalance callback args: %s", err.Error()))
return err
}
chainId := rebalanceCallback.HostZoneId
k.Logger(ctx).Info(utils.LogICACallbackWithHostZone(chainId, ICACallbackID_Rebalance, "Starting rebalance callback"))
Expand Down
2 changes: 1 addition & 1 deletion x/stakeibc/keeper/icacallbacks_rebalance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (s *KeeperTestSuite) TestRebalanceCallback_WrongCallbackArgs() {
invalidCallbackArgs := []byte("random bytes")

err := s.App.StakeibcKeeper.RebalanceCallback(s.Ctx, invalidArgs.packet, invalidArgs.ackResponse, invalidCallbackArgs)
s.Require().EqualError(err, "Unable to unmarshal rebalance callback args: unexpected EOF: unable to unmarshal data structure")
s.Require().ErrorContains(err, "unable to unmarshal rebalance callback args")
}

func (s *KeeperTestSuite) TestRebalanceCallback_WrongValidator() {
Expand Down
7 changes: 3 additions & 4 deletions x/stakeibc/keeper/icacallbacks_redemption.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ func (k Keeper) MarshalRedemptionCallbackArgs(ctx sdk.Context, redemptionCallbac
func (k Keeper) UnmarshalRedemptionCallbackArgs(ctx sdk.Context, redemptionCallback []byte) (types.RedemptionCallback, error) {
unmarshalledRedemptionCallback := types.RedemptionCallback{}
if err := proto.Unmarshal(redemptionCallback, &unmarshalledRedemptionCallback); err != nil {
k.Logger(ctx).Error(fmt.Sprintf("UnmarshalRedemptionCallbackArgs | %s", err.Error()))
return unmarshalledRedemptionCallback, err
return unmarshalledRedemptionCallback, errorsmod.Wrap(err, "unable to unmarshal redemption callback args")
}
return unmarshalledRedemptionCallback, nil
}
Expand All @@ -43,7 +42,7 @@ func (k Keeper) RedemptionCallback(ctx sdk.Context, packet channeltypes.Packet,
// Fetch callback args
redemptionCallback, err := k.UnmarshalRedemptionCallbackArgs(ctx, args)
if err != nil {
return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal redemption callback args: %s", err.Error()))
return err
}
chainId := redemptionCallback.HostZoneId
k.Logger(ctx).Info(utils.LogICACallbackWithHostZone(chainId, ICACallbackID_Redemption,
Expand All @@ -64,7 +63,7 @@ func (k Keeper) RedemptionCallback(ctx sdk.Context, packet channeltypes.Packet,
icacallbackstypes.AckResponseStatus_FAILURE, packet))

// Reset unbondings record status
err = k.RecordsKeeper.SetHostZoneUnbondingStatus(ctx, chainId, redemptionCallback.EpochUnbondingRecordIds, recordstypes.HostZoneUnbonding_EXIT_TRANSFER_QUEUE)
err := k.RecordsKeeper.SetHostZoneUnbondingStatus(ctx, chainId, redemptionCallback.EpochUnbondingRecordIds, recordstypes.HostZoneUnbonding_EXIT_TRANSFER_QUEUE)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion x/stakeibc/keeper/icacallbacks_redemption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (s *KeeperTestSuite) TestRedemptionCallback_WrongCallbackArgs() {
invalidCallbackArgs := []byte("random bytes")

err := s.App.StakeibcKeeper.RedemptionCallback(s.Ctx, invalidArgs.packet, invalidArgs.ackResponse, invalidCallbackArgs)
s.Require().EqualError(err, "Unable to unmarshal redemption callback args: unexpected EOF: unable to unmarshal data structure")
s.Require().ErrorContains(err, "unable to unmarshal redemption callback args: unexpected EOF")
s.checkRedemptionStateIfCallbackFailed(tc)
}

Expand Down
5 changes: 2 additions & 3 deletions x/stakeibc/keeper/icacallbacks_reinvest.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ func (k Keeper) MarshalReinvestCallbackArgs(ctx sdk.Context, reinvestCallback ty
func (k Keeper) UnmarshalReinvestCallbackArgs(ctx sdk.Context, reinvestCallback []byte) (*types.ReinvestCallback, error) {
unmarshalledReinvestCallback := types.ReinvestCallback{}
if err := proto.Unmarshal(reinvestCallback, &unmarshalledReinvestCallback); err != nil {
k.Logger(ctx).Error(fmt.Sprintf("UnmarshalReinvestCallbackArgs %s", err.Error()))
return nil, err
return nil, errorsmod.Wrap(err, "unable to unmarshal reinvest callback args")
}
return &unmarshalledReinvestCallback, nil
}
Expand All @@ -53,7 +52,7 @@ func (k Keeper) ReinvestCallback(ctx sdk.Context, packet channeltypes.Packet, ac
// Fetch callback args
reinvestCallback, err := k.UnmarshalReinvestCallbackArgs(ctx, args)
if err != nil {
return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal reinvest callback args: %s", err.Error()))
return err
}
chainId := reinvestCallback.HostZoneId
k.Logger(ctx).Info(utils.LogICACallbackWithHostZone(chainId, ICACallbackID_Reinvest, "Starting reinvest callback"))
Expand Down
8 changes: 4 additions & 4 deletions x/stakeibc/keeper/icacallbacks_reinvest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (s *KeeperTestSuite) TestReinvestCallback_Successful() {
s.Require().Equal(tc.initialState.durationUntilNextEpoch, query.TimeoutDuration, "query timeout duration")
}

func (s *KeeperTestSuite) checkReinvestStateIfCallbackFailed(tc ReinvestCallbackTestCase) {
func (s *KeeperTestSuite) checkReinvestStateIfCallbackFailed() {
// Confirm deposit record has not been added
records := s.App.RecordsKeeper.GetAllDepositRecord(s.Ctx)
s.Require().Len(records, 0, "number of deposit records")
Expand All @@ -151,7 +151,7 @@ func (s *KeeperTestSuite) TestReinvestCallback_ReinvestCallbackTimeout() {

err := s.App.StakeibcKeeper.ReinvestCallback(s.Ctx, invalidArgs.packet, invalidArgs.ackResponse, invalidArgs.args)
s.Require().NoError(err)
s.checkReinvestStateIfCallbackFailed(tc)
s.checkReinvestStateIfCallbackFailed()
}

func (s *KeeperTestSuite) TestReinvestCallback_ReinvestCallbackErrorOnHost() {
Expand All @@ -163,7 +163,7 @@ func (s *KeeperTestSuite) TestReinvestCallback_ReinvestCallbackErrorOnHost() {

err := s.App.StakeibcKeeper.ReinvestCallback(s.Ctx, invalidArgs.packet, invalidArgs.ackResponse, invalidArgs.args)
s.Require().NoError(err)
s.checkReinvestStateIfCallbackFailed(tc)
s.checkReinvestStateIfCallbackFailed()
}

func (s *KeeperTestSuite) TestReinvestCallback_WrongCallbackArgs() {
Expand All @@ -174,7 +174,7 @@ func (s *KeeperTestSuite) TestReinvestCallback_WrongCallbackArgs() {
invalidCallbackArgs := []byte("random bytes")

err := s.App.StakeibcKeeper.ReinvestCallback(s.Ctx, invalidArgs.packet, invalidArgs.ackResponse, invalidCallbackArgs)
s.Require().EqualError(err, "Unable to unmarshal reinvest callback args: unexpected EOF: unable to unmarshal data structure")
s.Require().ErrorContains(err, "unable to unmarshal reinvest callback args")
}

func (s *KeeperTestSuite) TestReinvestCallback_HostZoneNotFound() {
Expand Down
4 changes: 1 addition & 3 deletions x/stakeibc/keeper/icacallbacks_undelegate.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package keeper

import (
"fmt"

sdkmath "cosmossdk.io/math"

"github.com/Stride-Labs/stride/v23/utils"
Expand Down Expand Up @@ -32,7 +30,7 @@ func (k Keeper) UndelegateCallback(ctx sdk.Context, packet channeltypes.Packet,
// Fetch callback args
var undelegateCallback types.UndelegateCallback
if err := proto.Unmarshal(args, &undelegateCallback); err != nil {
return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal undelegate callback args: %s", err.Error()))
return errorsmod.Wrap(err, "unable to unmarshal undelegate callback args")
}

// Fetch the relevant host zone
Expand Down
2 changes: 1 addition & 1 deletion x/stakeibc/keeper/icacallbacks_undelegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (s *KeeperTestSuite) TestUndelegateCallback_WrongCallbackArgs() {
invalidCallbackArgs := []byte("random bytes")

err := s.App.StakeibcKeeper.UndelegateCallback(s.Ctx, tc.validArgs.packet, tc.validArgs.ackResponse, invalidCallbackArgs)
s.Require().EqualError(err, "Unable to unmarshal undelegate callback args: unexpected EOF: unable to unmarshal data structure")
s.Require().ErrorContains(err, "unable to unmarshal undelegate callback args")
}

func (s *KeeperTestSuite) TestUndelegateCallback_HostNotFound() {
Expand Down

0 comments on commit ad10e1e

Please sign in to comment.