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

test(x/staking): write integration tests #15890

Merged
merged 29 commits into from
May 2, 2023

Conversation

likhita-809
Copy link
Contributor

@likhita-809 likhita-809 commented Apr 19, 2023

Description

Closes: #14677
ref: #14145

This PR refactors the staking integration tests to use new testing framework setup


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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

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...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@github-actions github-actions bot added the C:CLI label Apr 20, 2023
@likhita-809 likhita-809 marked this pull request as ready for review April 21, 2023 09:52
@likhita-809 likhita-809 requested a review from a team as a code owner April 21, 2023 09:52
@julienrbrt julienrbrt self-assigned this Apr 21, 2023
tests/integration/staking/keeper/params_test.go Outdated Show resolved Hide resolved
tests/integration/staking/keeper/keeper_test.go Outdated Show resolved Hide resolved
tests/e2e/staking/grpc.go Outdated Show resolved Hide resolved
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! one nit. This does seem more like a mechanical rewrite, but given how big staking is, I'd say it is fine for this PR. Eventually, we do need to think about what should stay an integration test and what can be simplified to a unit test, and re-thinking about our test cases. Let's do that immediately for smaller modules.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can this not be a unit test?

Comment on lines 92 to 161
func initFixture(t testing.TB) *fixture {
keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, types.StoreKey,
)
cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, distribution.AppModuleBasic{}).Codec

logger := log.NewTestLogger(t)
cms := integration.CreateMultiStore(keys, logger)

newCtx := sdk.NewContext(cms, cmtprototypes.Header{}, true, logger)

authority := authtypes.NewModuleAddress("gov")

maccPerms := map[string][]string{
minttypes.ModuleName: {authtypes.Minter},
types.ModuleName: {authtypes.Minter},
types.BondedPoolName: {authtypes.Burner, authtypes.Staking},
types.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
}

accountKeeper := authkeeper.NewAccountKeeper(
cdc,
runtime.NewKVStoreService(keys[authtypes.StoreKey]),
authtypes.ProtoBaseAccount,
maccPerms,
sdk.Bech32MainPrefix,
authority.String(),
)

blockedAddresses := map[string]bool{
accountKeeper.GetAuthority(): false,
}
bankKeeper := bankkeeper.NewBaseKeeper(
cdc,
runtime.NewKVStoreService(keys[banktypes.StoreKey]),
accountKeeper,
blockedAddresses,
authority.String(),
log.NewNopLogger(),
)

stakingKeeper := stakingkeeper.NewKeeper(cdc, keys[types.StoreKey], accountKeeper, bankKeeper, authority.String())

authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts, nil)
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil)
stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper, nil)

integrationApp := integration.NewIntegrationApp(newCtx, logger, keys, cdc, authModule, bankModule, stakingModule)

sdkCtx := sdk.UnwrapSDKContext(integrationApp.Context())

// Register MsgServer and QueryServer
types.RegisterMsgServer(integrationApp.MsgServiceRouter(), stakingkeeper.NewMsgServerImpl(stakingKeeper))
types.RegisterQueryServer(integrationApp.QueryHelper(), stakingkeeper.NewQuerier(stakingKeeper))

// set default staking params
stakingKeeper.SetParams(sdkCtx, types.DefaultParams())

f := fixture{
app: integrationApp,
sdkCtx: sdkCtx,
cdc: cdc,
keys: keys,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
stakingKeeper: stakingKeeper,
}

return &f
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: A lot of initFixture code is looking redundant in other modules' tests too, can this code pulled out to a helper method?
cc: @julienrbrt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its true that initFixture code seems redundant wherever used in integration tests, but every module has different requirements. The StoreKeys, AppModule, module account permissions, etc. whichever are required to create a new integration app differs from every module.
I think that's the downside of this new integration tests, everything needed should be manually given.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I think still eventually we can use depinject for the quick setup. We just do not need to inject an app.

@tac0turtle tac0turtle added this pull request to the merge queue May 2, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks May 2, 2023
@tac0turtle tac0turtle added this pull request to the merge queue May 2, 2023
Merged via the queue into main with commit 672b1f9 May 2, 2023
@tac0turtle tac0turtle deleted the likhita/staking-integration-tests branch May 2, 2023 20:03
rllola pushed a commit to Zondax/cosmos-sdk that referenced this pull request May 11, 2023
@likhita-809 likhita-809 mentioned this pull request May 22, 2023
42 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate x/staking to use integration test framework
5 participants