-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
refactor: add mock unit tests for bank module #12721
Conversation
6754426
to
f08617e
Compare
f08617e
to
9952b31
Compare
9952b31
to
07d6055
Compare
x/bank/keeper/keeper_test.go
Outdated
err = keeper.MintCoins(ctx, authtypes.Minter, sdk.Coins{sdk.Coin{Denom: "denom", Amount: sdk.NewInt(-10)}}) | ||
suite.Require().Error(err, "insufficient coins") | ||
suite.mockMintCoins(burnerAcc) | ||
require.Panics(func() { keeper.MintCoins(ctx, authtypes.Burner, initCoins) }, "invalid permission") // nolint:errcheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though we're expecting a panic, probably best to handle the error like you have above:
require.Panics(func() { keeper.MintCoins(ctx, authtypes.Burner, initCoins) }, "invalid permission") // nolint:errcheck | |
require.Panics(func() { _ = keeper.MintCoins(ctx, authtypes.Burner, initCoins) }, "invalid permission") // nolint:errcheck |
x/bank/keeper/keeper_test.go
Outdated
authKeeper.SetModuleAccount(ctx, multiPermAcc) | ||
authKeeper.SetModuleAccount(ctx, randomPermAcc) | ||
require := suite.Require() | ||
authKeeper, keeper := suite.authKeeper, suite.keeper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: the var name keeper
shadows the imported package name
@@ -8,6 +8,7 @@ import ( | |||
"github.com/cosmos/cosmos-sdk/telemetry" | |||
sdk "github.com/cosmos/cosmos-sdk/types" | |||
"github.com/cosmos/cosmos-sdk/types/errors" | |||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same package seems to be import twice with a different alias the second time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌 LGTM, pls fix Matt's comments
@@ -59,3 +61,113 @@ func (suite *IntegrationTestSuite) TestMsgUpdateParams() { | |||
}) | |||
} | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@facundomedica I added new test-cases for MsgSend and MsgMultiSend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I'll approve and automerge
x/bank/keeper/keeper_test.go
Outdated
key := sdk.NewKVStoreKey(banktypes.StoreKey) | ||
testCtx := testutil.DefaultContextWithDB(suite.T(), key, sdk.NewTransientStoreKey("transient_test")) | ||
ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) | ||
encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encCfg := moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) | |
encCfg := moduletestutil.MakeTestEncodingConfig() |
x/bank/keeper/keeper_test.go
Outdated
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" | ||
"github.com/cosmos/cosmos-sdk/x/nft/module" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"github.com/cosmos/cosmos-sdk/x/nft/module" |
We don't need the NFT module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Description
Closes: #12503
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change