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(gov): Refactor x/gov keeper tests to use mocks #12988

Merged
merged 26 commits into from
Aug 25, 2022
Merged

test(gov): Refactor x/gov keeper tests to use mocks #12988

merged 26 commits into from
Aug 25, 2022

Conversation

amaury1093
Copy link
Contributor

@amaury1093 amaury1093 commented Aug 22, 2022

Description

ref: #12752


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)

@codecov
Copy link

codecov bot commented Aug 24, 2022

Codecov Report

Merging #12988 (0ae0cdc) into main (4fe7797) will decrease coverage by 0.29%.
The diff coverage is 58.24%.

❗ Current head 0ae0cdc differs from pull request most recent head 4aa3b92. Consider uploading reports for the commit 4aa3b92 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #12988      +/-   ##
==========================================
- Coverage   55.87%   55.58%   -0.30%     
==========================================
  Files         646      644       -2     
  Lines       54895    54935      +40     
==========================================
- Hits        30675    30535     -140     
- Misses      21762    21932     +170     
- Partials     2458     2468      +10     
Impacted Files Coverage Δ
baseapp/abci.go 64.09% <0.00%> (-0.33%) ⬇️
client/flags/flags.go 19.35% <0.00%> (-0.32%) ⬇️
client/rpc/status.go 66.66% <ø> (ø)
client/utils.go 34.92% <0.00%> (ø)
server/config/config.go 38.00% <0.00%> (-1.59%) ⬇️
server/rosetta/client_online.go 1.35% <0.00%> (ø)
server/swagger.go 0.00% <0.00%> (ø)
testutil/list.go 0.00% <0.00%> (ø)
types/result.go 76.74% <ø> (ø)
x/auth/tx/query.go 0.00% <ø> (ø)
... and 69 more

@amaury1093 amaury1093 mentioned this pull request Aug 25, 2022
2 tasks
@amaury1093 amaury1093 marked this pull request as ready for review August 25, 2022 13:44
@amaury1093 amaury1093 requested a review from a team as a code owner August 25, 2022 13:44
Comment on lines +19 to +23
// KeeperTestSuite only tests gov's keeper logic around tallying, since it
// relies on complex interactions with x/staking.
//
// It also uses simapp (and not a depinjected app) because we manually set a
// new app.StakingKeeper in `createValidators`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only tallying tests have been moved here. I don't think it's easy to mock them.

Comment on lines +20 to +25
// BondDenomProvider is a subset of the staking keeper's public interface that
// provides the staking bond denom. It is used in arguments in this package's
// functions so that a mock staking keeper can be passed instead of the real one.
type BondDenomProvider interface {
BondDenom(ctx sdk.Context) string
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any objections to this? Or better ideas?

)

func (suite *KeeperTestSuite) TestSubmitProposalReq() {
govAcct := suite.app.GovKeeper.GetGovernanceAccount(suite.ctx).GetAddress()
suite.reset()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this line in some tests. If I don't, I have an off-by-1 error in proposal ID, only when running the whole suite. Like some other test got run before and created a proposal or something

Resetting makes each test more independent.

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!

@julienrbrt julienrbrt added the A:automerge Automatically merge PR once all prerequisites pass. label Aug 25, 2022
@mergify mergify bot merged commit fc7ee0b into main Aug 25, 2022
@mergify mergify bot deleted the am/gov-mocks branch August 25, 2022 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:x/gov Type: Build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants