Skip to content

Commit

Permalink
fix(tokenfactory): disable force transfer from module accounts (#173)
Browse files Browse the repository at this point in the history
* add upgrade details

* fix: patch token factory force transfer msg
  • Loading branch information
harish551 authored Jun 3, 2024
1 parent aa0c729 commit 83f984c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
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")
})
}

0 comments on commit 83f984c

Please sign in to comment.