Skip to content

Commit

Permalink
chore: add missing blockedAddr checking in bankplus (#705)
Browse files Browse the repository at this point in the history
* chore: add missing blockedAddr checking in bankplus

Signed-off-by: zemyblue <zemyblue@gmail.com>

* fix: unittest error about blockedAddr

Signed-off-by: zemyblue <zemyblue@gmail.com>

* chore: update changelog

Signed-off-by: zemyblue <zemyblue@gmail.com>

* chore: add unittest of `bankplus` blockedAddr

Signed-off-by: zemyblue <zemyblue@gmail.com>

Signed-off-by: zemyblue <zemyblue@gmail.com>
  • Loading branch information
zemyblue authored Oct 12, 2022
1 parent 580d404 commit 9ef6557
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (simapp) [\#679](https://github.com/line/lbm-sdk/pull/679) fix the bug not setting `iavl-cache-size` value of `app.toml`
* (x/foundation) [\#687](https://github.com/line/lbm-sdk/pull/687) fix bugs on aborting x/foundation proposals
* (global) [\#694](https://github.com/line/lbm-sdk/pull/694) replace deprecated functions since go 1.16 or 1.17
* (x/bankplus) [\#705](https://github.com/line/lbm-sdk/pull/705) add missing blockedAddr checking in bankplus

### Breaking Changes
* (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path
Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (suite *IntegrationTestSuite) TestExportGenesis() {

func (suite *IntegrationTestSuite) getTestBalancesAndSupply() ([]types.Balance, sdk.Coins) {
addr2, _ := sdk.AccAddressFromBech32("link1f9xjhxm0plzrh9cskf4qee4pc2xwp0n0p662v8")
addr1, _ := sdk.AccAddressFromBech32("link1fl48vsnmsdzcv85q5d2q4z5ajdha8yu3q4fdzl")
addr1, _ := sdk.AccAddressFromBech32("link1jv65s3grqf6v6jl3dp4t6c9t9rk99cd8j3y7jh") // distribution module address
addr1Balance := sdk.Coins{sdk.NewInt64Coin("testcoin3", 10)}
addr2Balance := sdk.Coins{sdk.NewInt64Coin("testcoin1", 32), sdk.NewInt64Coin("testcoin2", 34)}

Expand Down
4 changes: 4 additions & 0 deletions x/bankplus/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (keeper BaseKeeper) SendCoinsFromModuleToAccount(
panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", senderModule))
}

if keeper.BlockedAddr(recipientAddr) {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", recipientAddr)
}

return keeper.SendCoins(ctx, senderAddr, recipientAddr, amt)
}

Expand Down
27 changes: 27 additions & 0 deletions x/bankplus/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,33 @@ func (suite *IntegrationTestSuite) TestInitializeBankPlus() {
}
}

func (suite *IntegrationTestSuite) TestSendCoinsFromModuleToAccount_Blacklist() {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, ocproto.Header{Height: 1})
appCodec := app.AppCodec()

// add module accounts to supply keeper
maccPerms := simapp.GetMaccPerms()
maccPerms[holder] = nil
maccPerms[authtypes.Burner] = []string{authtypes.Burner}
maccPerms[authtypes.Minter] = []string{authtypes.Minter}

addr1 := sdk.AccAddress([]byte("addr1_______________"))

authKeeper := authkeeper.NewAccountKeeper(
appCodec, app.GetKey(types.StoreKey), app.GetSubspace(types.ModuleName),
authtypes.ProtoBaseAccount, maccPerms,
)
keeper := bankpluskeeper.NewBaseKeeper(
appCodec, app.GetKey(types.StoreKey), authKeeper,
app.GetSubspace(types.ModuleName), map[string]bool{addr1.String(): true})

suite.Require().NoError(keeper.MintCoins(ctx, minttypes.ModuleName, initCoins))
suite.Require().Error(keeper.SendCoinsFromModuleToAccount(
ctx, minttypes.ModuleName, addr1, initCoins,
))
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
4 changes: 1 addition & 3 deletions x/ibc/applications/transfer/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
}, true, false},

// - coin being sent to module address on chainA
// Change the original test (https://github.com/cosmos/ibc-go/blob/v3.0.0/modules/apps/transfer/keeper/relay_test.go#L171-L174)
// because the bankplus module SendCoinsFromModuleToAccount function does not have a blacklist check
{"failure: receive on module account", func() {
receiver = suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(types.ModuleName).String()
}, false, true},
}, false, false},

// - coin being sent back to original chain (chainB) to module address
{"failure: receive on module account on source chain", func() {
Expand Down

0 comments on commit 9ef6557

Please sign in to comment.