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(tokenfactory): disable force transfer from module accounts #173

Merged
merged 2 commits into from
Jun 3, 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
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ curl https://raw.githubusercontent.com/OmniFlix/mainnet/main/omniflixhub-1/genes
- [v0.12.x](https://github.com/OmniFlix/docs/blob/main/guides/mainnet/omniflixhub-1/upgrades/v0.12.x-upgrade.md) at block 8054200
- [v2](https://github.com/OmniFlix/docs/blob/main/guides/mainnet/omniflixhub-1/upgrades/v2-upgrade.md) at block 10428200
- [v2.1]((https://github.com/OmniFlix/docs/blob/main/guides/mainnet/omniflixhub-1/upgrades/v2.1-upgrade.md)) at block 10678600
- [v3]((https://github.com/OmniFlix/docs/blob/main/guides/mainnet/omniflixhub-1/upgrades/v3-upgrade.md)) at block 10872800
- [v3.3.0]((https://github.com/OmniFlix/docs/blob/main/guides/mainnet/omniflixhub-1/upgrades/v3.3.0-upgrade.md)) at block 11140000
- [v4]((https://github.com/OmniFlix/docs/blob/main/guides/mainnet/omniflixhub-1/upgrades/v4-upgrade.md)) at block 11914000

### Testnets

Expand Down
4 changes: 4 additions & 0 deletions x/tokenfactory/keeper/bankactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr string,
return err
}

if k.bankKeeper.BlockedAddr(fromSdkAddr) {
return fmt.Errorf("failed to force transfer from a blocked address: %s", fromAddr)
}

if k.bankKeeper.BlockedAddr(toSdkAddr) {
return fmt.Errorf("failed to force transfer to blocked address: %s", toSdkAddr)
}
Expand Down
39 changes: 37 additions & 2 deletions x/tokenfactory/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package keeper_test
import (
"fmt"

"github.com/OmniFlix/omniflixhub/v4/x/tokenfactory/types"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/OmniFlix/omniflixhub/v4/x/tokenfactory/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

// TestMintDenomMsg tests TypeMsgMint message is emitted on a successful mint
Expand Down Expand Up @@ -251,3 +251,38 @@ func (suite *KeeperTestSuite) TestSetDenomMetaDataMsg() {
})
}
}

func (s *KeeperTestSuite) TestForceTransferMsg() {
// Create a denom
s.CreateDefaultDenom()

s.Run("test force transfer", func() {
mintAmt := sdk.NewInt64Coin(s.defaultDenom, 10)

_, _ = s.msgServer.Mint(sdk.WrapSDKContext(s.Ctx), types.NewMsgMint(s.TestAccs[0].String(), mintAmt))

govModAcc := s.App.AccountKeeper.GetModuleAccount(s.Ctx, govtypes.ModuleName)

err := s.App.BankKeeper.SendCoins(s.Ctx, s.TestAccs[0], govModAcc.GetAddress(), sdk.NewCoins(mintAmt))
s.Require().NoError(err)

_, err = s.msgServer.ForceTransfer(s.Ctx, types.NewMsgForceTransfer(s.TestAccs[0].String(), mintAmt, govModAcc.GetAddress().String(), s.TestAccs[1].String()))
s.Require().ErrorContains(err, "failed to force transfer from a blocked address")
})
}

func (s *KeeperTestSuite) TestForceTransferMsgAccToModule() {
// Create a denom
s.CreateDefaultDenom()

s.Run("test force transfer account to module", func() {
mintAmt := sdk.NewInt64Coin(s.defaultDenom, 10)

_, _ = s.msgServer.Mint(sdk.WrapSDKContext(s.Ctx), types.NewMsgMint(s.TestAccs[0].String(), mintAmt))

govModAcc := s.App.AccountKeeper.GetModuleAccount(s.Ctx, govtypes.ModuleName)

_, err := s.msgServer.ForceTransfer(s.Ctx, types.NewMsgForceTransfer(s.TestAccs[0].String(), mintAmt, s.TestAccs[0].String(), govModAcc.GetAddress().String()))
s.Require().ErrorContains(err, "failed to force transfer to blocked address")
})
}
Loading