Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Sep 5, 2023
1 parent ccce188 commit f4f2a31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
12 changes: 7 additions & 5 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}

Expand All @@ -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)
}
Expand Down Expand Up @@ -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")
Expand All @@ -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))

Expand Down

0 comments on commit f4f2a31

Please sign in to comment.