From f4f2a317e2b4f1a41c10218308079788dbd7e936 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 5 Sep 2023 09:37:50 +0200 Subject: [PATCH] debugging --- x/bank/keeper/keeper.go | 6 +++--- x/bank/keeper/keeper_test.go | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index c54b37acee3a..e0ea2751c420 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -382,14 +382,14 @@ 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", acc) + fmt.Println("acc", fmt.Sprintf("%x", address)) if acc == nil { - return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", address) + return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "account %x does not exist", address) } if macc, ok := acc.(sdk.ModuleAccountI); ok { if !macc.HasPermission(authtypes.Burner) { - return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "account %s does not have permissions to burn tokens", address) + return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "account %x does not have permissions to burn tokens", address) } } diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index bc490a2ffb8c..7871cc419036 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -51,6 +51,7 @@ const ( var ( holderAcc = authtypes.NewEmptyModuleAccount(holder) + randomAcc = authtypes.NewEmptyModuleAccount(randomPerm) burnerAcc = authtypes.NewEmptyModuleAccount(authtypes.Burner, authtypes.Burner, authtypes.Staking) minterAcc = authtypes.NewEmptyModuleAccount(authtypes.Minter, authtypes.Minter) mintAcc = authtypes.NewEmptyModuleAccount(banktypes.MintModuleName, authtypes.Minter) @@ -177,7 +178,6 @@ func (suite *KeeperTestSuite) mockSendCoinsFromModuleToAccount(moduleAcc *authty } func (suite *KeeperTestSuite) mockBurnCoins(moduleAcc *authtypes.ModuleAccount) { - suite.authKeeper.EXPECT().GetModuleAccount(suite.ctx, moduleAcc.Name).Return(moduleAcc).AnyTimes() suite.authKeeper.EXPECT().GetAccount(suite.ctx, moduleAcc.GetAddress()).Return(moduleAcc).AnyTimes() } @@ -195,6 +195,7 @@ 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) } @@ -563,14 +564,14 @@ func (suite *KeeperTestSuite) TestSupply_BurnCoins() { supplyAfterInflation, _, err := keeper.GetPaginatedTotalSupply(ctx, &query.PageRequest{}) require.NoError(err) - authKeeper.EXPECT().GetAccount(ctx, []byte{}).Return(nil) + authKeeper.EXPECT().GetAccount(ctx, []byte{}).Return(nil).AnyTimes() require.Error(keeper.BurnCoins(ctx, []byte{}, initCoins), "no module account") - authKeeper.EXPECT().GetAccount(ctx, minterAcc.GetAddress()).Return(nil) + authKeeper.EXPECT().GetAccount(ctx, minterAcc.GetAddress()).Return(nil).AnyTimes() require.Error(keeper.BurnCoins(ctx, minterAcc.GetAddress(), initCoins), "invalid permission") - authKeeper.EXPECT().GetModuleAccount(ctx, randomPerm).Return(nil) - require.Error(keeper.BurnCoins(ctx, []byte{}, supplyAfterInflation), "random permission") + authKeeper.EXPECT().GetAccount(ctx, randomAcc.GetAddress()).Return(nil).AnyTimes() + require.Error(keeper.BurnCoins(ctx, randomAcc.GetAddress(), supplyAfterInflation), "random permission") suite.mockBurnCoins(burnerAcc) require.Error(keeper.BurnCoins(ctx, burnerAcc.GetAddress(), supplyAfterInflation), "insufficient coins") @@ -590,6 +591,7 @@ 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))