Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update burn from #308

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading