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

refactor: use mocks for x/slashing #12937

Merged
merged 10 commits into from
Aug 17, 2022
Merged

Conversation

cool-develope
Copy link
Contributor

@cool-develope cool-develope commented Aug 16, 2022

Description

Closes: #12748


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 16, 2022

Codecov Report

Merging #12937 (f6bbd00) into main (4fe7797) will decrease coverage by 0.38%.
The diff coverage is 88.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #12937      +/-   ##
==========================================
- Coverage   55.87%   55.49%   -0.39%     
==========================================
  Files         646      646              
  Lines       54895    54865      -30     
==========================================
- Hits        30675    30448     -227     
- Misses      21762    21964     +202     
+ Partials     2458     2453       -5     
Impacted Files Coverage Δ
x/distribution/keeper/params.go 75.00% <ø> (-3.58%) ⬇️
x/distribution/module.go 64.28% <ø> (ø)
types/dec_coin.go 98.41% <50.00%> (-0.79%) ⬇️
crypto/keyring/keyring.go 61.95% <100.00%> (ø)
types/events.go 84.65% <100.00%> (+0.35%) ⬆️
x/distribution/abci.go 76.92% <100.00%> (-23.08%) ⬇️
x/distribution/keeper/allocation.go 97.10% <100.00%> (+10.43%) ⬆️
x/staking/simulation/operations.go 76.08% <100.00%> (+0.33%) ⬆️
x/genutil/gentx.go 0.00% <0.00%> (-85.49%) ⬇️
x/slashing/keeper/infractions.go 0.00% <0.00%> (-85.15%) ⬇️
... and 15 more

@cool-develope cool-develope marked this pull request as draft August 16, 2022 20:34
@cool-develope cool-develope marked this pull request as ready for review August 16, 2022 21:49
@JeancarloBarrios JeancarloBarrios self-assigned this Aug 17, 2022
@kocubinski kocubinski self-assigned this Aug 17, 2022
tstaking.CheckValidator(valAddr, stakingtypes.Unbonding, true)
expectedPubKey, err := keeper.GetPubkey(ctx, addr.Bytes())
require.NoError(err)
require.Equal(pubKey, expectedPubKey)
}
Copy link
Member

Choose a reason for hiding this comment

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

The gutting of this file seems OK since it was moved as an integration test to integration/slashing/keeper. Is that what you're thinking too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One thing which I am struggling is test coverage, moving the original ones to integration leads to a massive dropdown of test coverage.

Copy link
Contributor

@JeancarloBarrios JeancarloBarrios left a comment

Choose a reason for hiding this comment

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

LGTM

@cool-develope cool-develope merged commit b515372 into main Aug 17, 2022
@cool-develope cool-develope deleted the john/12748-mock-slashing branch August 17, 2022 18:40
s.slashingKeeper.HandleValidatorSignature(ctx, val.Address(), newPower, true)

// validator should not be kicked since we reset counter/array when it was jailed
staking.EndBlocker(ctx, s.stakingKeeper)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey quick question @cool-develope : did you also convert this test to use mocks? In particular how did you deal with this EndBlocker function, that takes a real keeper and not an interface.

(having the same issue in x/gov)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, I couldn't mock that one, this is why I moved keeper_test.go to integration/slashing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AmauryM tests/integration/slashing/keeper/keeper_test.go

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.

refactor x/slashing tests to use mocks
5 participants