Skip to content

Commit

Permalink
Merge pull request #308 from terra-money/update/tf
Browse files Browse the repository at this point in the history
fix: update burn from
  • Loading branch information
tuky191 authored Jun 11, 2024
2 parents d2810c5 + fe8e971 commit 4258834
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
45 changes: 45 additions & 0 deletions x/tokenfactory/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/stretchr/testify/suite"

Expand Down Expand Up @@ -58,3 +63,43 @@ func (s *KeeperTestSuite) TestCreateModuleAccount() {
// check that the account number of the module account is now initialized correctly
s.Require().Equal(nextAccountNumber+1, tokenfactoryModuleAccount.GetAccountNumber())
}

func (s *KeeperTestSuite) TestBurnFromModuleAccount() {
// Create Msg Server
msgServer := keeper.NewMsgServerImpl(s.App.Keepers.TokenFactoryKeeper)

// Create token factory token
res, err := msgServer.CreateDenom(s.Ctx, &types.MsgCreateDenom{
Sender: s.TestAccs[0].String(),
Subdenom: "bitcoin",
})
s.Require().NoError(err)

denom := res.GetNewTokenDenom()

// Gov address
govAddr := s.App.Keepers.AccountKeeper.GetModuleAddress("gov")
s.App.Keepers.AccountKeeper.SetModuleAccount(s.Ctx, authtypes.NewModuleAccount(authtypes.NewBaseAccount(govAddr, nil, 0, 0), "gov", authtypes.Minter))
ma := s.App.Keepers.AccountKeeper.GetAccount(s.Ctx, govAddr)
_, ok := ma.(authtypes.ModuleAccountI)
s.Require().True(ok)

_, err = msgServer.Mint(s.Ctx, &types.MsgMint{
Sender: s.TestAccs[0].String(),
Amount: sdk.NewCoin(denom, sdk.NewInt(1000)),
MintToAddress: s.TestAccs[0].String(),
})
s.Require().NoError(err)

// Send to gov address
err = s.App.Keepers.BankKeeper.SendCoinsFromAccountToModule(s.Ctx, s.TestAccs[0], "gov", sdk.NewCoins(sdk.NewCoin(denom, sdk.NewInt(1000))))
s.Require().NoError(err)

_, err = msgServer.Burn(s.Ctx, &types.MsgBurn{
Sender: s.TestAccs[0].String(),
Amount: sdk.NewCoin(denom, sdk.NewInt(1000)),
BurnFromAddress: govAddr.String(),
})

require.Error(s.T(), err)
}
6 changes: 5 additions & 1 deletion x/tokenfactory/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ func (server msgServer) Burn(goCtx context.Context, msg *types.MsgBurn) (*types.
msg.BurnFromAddress = msg.Sender
}

accountI := server.Keeper.accountKeeper.GetAccount(ctx, sdk.AccAddress(msg.BurnFromAddress))
acc, err := sdk.AccAddressFromBech32(msg.BurnFromAddress)
if err != nil {
return nil, err
}
accountI := server.Keeper.accountKeeper.GetAccount(ctx, acc)
_, ok := accountI.(authtypes.ModuleAccountI)
if ok {
return nil, types.ErrBurnFromModuleAccount
Expand Down

0 comments on commit 4258834

Please sign in to comment.