From 3f8d824ef6c8ef451d3fd6d0b7ee821259e99e83 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 16 May 2023 11:53:15 +0200 Subject: [PATCH] use nil return in updated authz response to consume less gas and avoid potential pitfalls --- modules/apps/transfer/types/transfer_authorization.go | 3 ++- .../apps/transfer/types/transfer_authorization_test.go | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/apps/transfer/types/transfer_authorization.go b/modules/apps/transfer/types/transfer_authorization.go index 7a152b23dc6..6f8da05fce9 100644 --- a/modules/apps/transfer/types/transfer_authorization.go +++ b/modules/apps/transfer/types/transfer_authorization.go @@ -7,6 +7,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/authz" + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -47,7 +48,7 @@ func (a TransferAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.Accep // If the spend limit is set to the MaxUint256 sentinel value, do not subtract the amount from the spend limit. if allocation.SpendLimit.AmountOf(msgTransfer.Token.Denom).Equal(UnboundedSpendLimit()) { - return authz.AcceptResponse{Accept: true, Delete: false, Updated: &a}, nil + return authz.AcceptResponse{Accept: true, Delete: false, Updated: nil}, nil } limitLeft, isNegative := allocation.SpendLimit.SafeSub(msgTransfer.Token) diff --git a/modules/apps/transfer/types/transfer_authorization_test.go b/modules/apps/transfer/types/transfer_authorization_test.go index 39d7a827c38..a549bce954e 100644 --- a/modules/apps/transfer/types/transfer_authorization_test.go +++ b/modules/apps/transfer/types/transfer_authorization_test.go @@ -93,11 +93,9 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { func(res authz.AcceptResponse, err error) { suite.Require().NoError(err) - updatedTransferAuthz, ok := res.Updated.(*types.TransferAuthorization) - suite.Require().True(ok) - - remainder := updatedTransferAuthz.Allocations[0].SpendLimit.AmountOf(sdk.DefaultBondDenom) - suite.Require().True(types.UnboundedSpendLimit().Equal(remainder)) + suite.Require().True(res.Accept) + suite.Require().False(res.Delete) + suite.Require().Nil(res.Updated) }, }, {