Skip to content

Commit

Permalink
try to fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Sep 8, 2023
1 parent f4f2a31 commit c8b026b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
1 change: 0 additions & 1 deletion x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ func (k BaseKeeper) MintCoins(ctx context.Context, moduleName string, amounts sd
// It will panic if the module account does not exist or is unauthorized.
func (k BaseKeeper) BurnCoins(ctx context.Context, address []byte, amounts sdk.Coins) error {
acc := k.ak.GetAccount(ctx, address)
fmt.Println("acc", fmt.Sprintf("%x", address))
if acc == nil {
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "account %x does not exist", address)
}
Expand Down
11 changes: 4 additions & 7 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ func (suite *KeeperTestSuite) mockSendCoinsFromAccountToModule(acc *authtypes.Ba
}

func (suite *KeeperTestSuite) mockSendCoins(ctx context.Context, sender sdk.AccountI, receiver sdk.AccAddress) {
fmt.Println(sender.GetAddress(), receiver)
suite.authKeeper.EXPECT().GetAccount(ctx, sender.GetAddress()).Return(sender)
suite.authKeeper.EXPECT().HasAccount(ctx, receiver).Return(true)
}
Expand Down Expand Up @@ -248,7 +247,6 @@ func (suite *KeeperTestSuite) mockUnDelegateCoins(ctx context.Context, acc, mAcc
}
suite.authKeeper.EXPECT().GetAccount(ctx, acc.GetAddress()).Return(acc)
suite.authKeeper.EXPECT().GetAccount(ctx, mAcc.GetAddress()).Return(mAcc)
suite.authKeeper.EXPECT().GetAccount(ctx, mAcc.GetAddress()).Return(mAcc)
}

func (suite *KeeperTestSuite) TestAppendSendRestriction() {
Expand Down Expand Up @@ -564,13 +562,13 @@ func (suite *KeeperTestSuite) TestSupply_BurnCoins() {
supplyAfterInflation, _, err := keeper.GetPaginatedTotalSupply(ctx, &query.PageRequest{})
require.NoError(err)

authKeeper.EXPECT().GetAccount(ctx, []byte{}).Return(nil).AnyTimes()
require.Error(keeper.BurnCoins(ctx, []byte{}, initCoins), "no module account")
authKeeper.EXPECT().GetAccount(ctx, []byte{}).Return(nil).MaxTimes(1)
require.Error(keeper.BurnCoins(ctx, []byte{}, initCoins), "no account")

authKeeper.EXPECT().GetAccount(ctx, minterAcc.GetAddress()).Return(nil).AnyTimes()
authKeeper.EXPECT().GetAccount(ctx, minterAcc.GetAddress()).Return(minterAcc).MaxTimes(1)
require.Error(keeper.BurnCoins(ctx, minterAcc.GetAddress(), initCoins), "invalid permission")

authKeeper.EXPECT().GetAccount(ctx, randomAcc.GetAddress()).Return(nil).AnyTimes()
authKeeper.EXPECT().GetAccount(ctx, randomAcc.GetAddress()).Return(randomAcc)
require.Error(keeper.BurnCoins(ctx, randomAcc.GetAddress(), supplyAfterInflation), "random permission")

suite.mockBurnCoins(burnerAcc)
Expand All @@ -591,7 +589,6 @@ func (suite *KeeperTestSuite) TestSupply_BurnCoins() {
supplyAfterInflation, _, err = keeper.GetPaginatedTotalSupply(ctx, &query.PageRequest{})
require.NoError(err)

authKeeper.EXPECT().GetAccount(ctx, multiPermAcc.GetAddress()).Return(nil).AnyTimes()
suite.mockSendCoins(ctx, minterAcc, multiPermAcc.GetAddress())
require.NoError(keeper.SendCoins(ctx, minterAcc.GetAddress(), multiPermAcc.GetAddress(), initCoins))

Expand Down
5 changes: 3 additions & 2 deletions x/bank/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"fmt"

"github.com/hashicorp/go-metrics"

Expand Down Expand Up @@ -190,7 +191,7 @@ func (k msgServer) Burn(goCtx context.Context, msg *types.MsgBurn) (*types.MsgBu

var coins sdk.Coins
for _, coin := range msg.Amount {
coins = append(coins, sdk.NewCoin(coin.Denom, coin.Amount))
coins = coins.Add(sdk.NewCoin(coin.Denom, coin.Amount))
}

if base, ok := k.Keeper.(BaseKeeper); ok {
Expand All @@ -205,7 +206,7 @@ func (k msgServer) Burn(goCtx context.Context, msg *types.MsgBurn) (*types.MsgBu
if !coins.IsValid() {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidCoins, coins.String())
}

fmt.Println("coins", coins)
if !coins.IsAllPositive() {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidCoins, coins.String())
}
Expand Down

0 comments on commit c8b026b

Please sign in to comment.