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

added switch case to detect blank pointers in keeper #2403

Conversation

alizahidraja
Copy link
Contributor

@alizahidraja alizahidraja commented Sep 27, 2022

Description

Added switch case to detect blank pointers in the keeper.

closes: #2268


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/) (not applicable)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this, @alizahidraja!

Could you also please try to add some tests for the empty pointer situations here?

modules/core/keeper/keeper.go Outdated Show resolved Hide resolved
modules/core/keeper/keeper.go Outdated Show resolved Hide resolved
Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Thanks for your contributions @alizahidraja, much appreciated! 🙏

I have some doubts over this code needing to change, but perhaps some additional tests could get to the bottom of it!

modules/core/keeper/keeper.go Show resolved Hide resolved
@alizahidraja
Copy link
Contributor Author

alizahidraja commented Sep 28, 2022

@crodriguezvega will have a look and add some tests for empty pointers

@alizahidraja
Copy link
Contributor Author

@crodriguezvega @damiannolan I added 2 new test cases and ran them on both, the switch case code and previous code; the previous code fail the new test cases with pointers

Please do have a look and lmk your thoughts

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Thanks, @alizahidraja!

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up @alizahidraja. It's a bit of a tricky issue so I appreciate your patience. See my latest comment. I think it makes sense to add this to the bottom of the keeper.go file

@alizahidraja
Copy link
Contributor Author

No worries @colin-axner, I'll make a function to check for that at the bottom

@alizahidraja
Copy link
Contributor Author

Added an isEmpty function at the bottom of the keeper

The final concern would be that the error message cannot specify if the keeper object is a struct or a pointer, dk if that is important, lmk what you guys think

@codecov-commenter
Copy link

codecov-commenter commented Sep 29, 2022

Codecov Report

Merging #2403 (40f33c6) into main (7dcfc2c) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2403      +/-   ##
==========================================
+ Coverage   78.63%   78.64%   +0.01%     
==========================================
  Files         178      178              
  Lines       12354    12365      +11     
==========================================
+ Hits         9714     9725      +11     
  Misses       2208     2208              
  Partials      432      432              
Impacted Files Coverage Δ
modules/core/keeper/keeper.go 91.11% <100.00%> (+2.87%) ⬆️

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Thanks @alizahidraja!

@colin-axner
Copy link
Contributor

The final concern would be that the error message cannot specify if the keeper object is a struct or a pointer, dk if that is important, lmk what you guys think

No, I think as you have it now is great. We mostly just want to panic if something is misconfigured so the chain developer knows to look into the code

@crodriguezvega crodriguezvega merged commit 462ccb6 into cosmos:main Sep 29, 2022
mergify bot pushed a commit that referenced this pull request Sep 29, 2022
* added switch case to detect blank pointers in keeper

* updated changelog.md

* updated error message for keeper

* fixed switch-case; added test cases

* added function to check for empty keeper

Co-authored-by: Carlos Rodriguez <[email protected]>
Co-authored-by: colin axnér <[email protected]>
(cherry picked from commit 462ccb6)

# Conflicts:
#	CHANGELOG.md
crodriguezvega pushed a commit that referenced this pull request Sep 30, 2022
…#2447)

* added switch case to detect blank pointers in keeper (#2403)

* added switch case to detect blank pointers in keeper

* updated changelog.md

* updated error message for keeper

* fixed switch-case; added test cases

* added function to check for empty keeper

Co-authored-by: Carlos Rodriguez <[email protected]>
Co-authored-by: colin axnér <[email protected]>
(cherry picked from commit 462ccb6)

# Conflicts:
#	CHANGELOG.md

* fix conflict

* Update CHANGELOG.md

Co-authored-by: Ali Zahid Raja <[email protected]>
Co-authored-by: Carlos Rodriguez <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants