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

fix: Make MulDecTruncate() return nil DecCoins when multiplier is 0 #10687

Conversation

evancholmberg
Copy link
Contributor

@evancholmberg evancholmberg commented Dec 6, 2021

Description

The DecCoins.MulDecTruncate function is supposed to panic instead of returning nil when multiplier d is zero. This fixes that behavior and updates the related test decCoinTestSuite.TestDecCoins_MulDecTruncate to expect a panic when multiplier d is zero.

Closes: #9790


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)

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

LGTM, possibly in the future we can avoid panics

@atheeshp
Copy link
Contributor

atheeshp commented Dec 7, 2021

There are few failing tests.

@alexanderbez
Copy link
Contributor

Should this be backported?

@amaury1093
Copy link
Contributor

Hey @evancholmberg, simulations are failing on this PR, could you have a look?

I tried running the exact command in the failing CI: go test ./simapp -run TestAppImportExport -Enabled=true -NumBlocks=50 -Genesis= -Verbose=true -Commit=true -Seed=1 -Period=5 -ExportParamsPath /tmp/sim-logs-826299046/sim_params-1.json -ExportStatePath /tmp/sim-logs-826299046/sim_state-1.json -v -timeout 24h, and i got:

panic: invalid zero decimal

@evancholmberg
Copy link
Contributor Author

Yes, I have time tomorrow to work on this.

@ValarDragon
Copy link
Contributor

Agreed this follows the comment, confused why we want to panic vs just return sdk.DecCoins{} when the multiplier is 0.

@ValarDragon ValarDragon changed the title fix: Update behavior of MulDecTruncate() fix: Make MulDecTruncate() panic when multiplier is 0 Dec 14, 2021
@evancholmberg
Copy link
Contributor Author

I can change it to return sdk.DecCoins{}. That would make sense to only have division by 0 panic i.e. in DecCoins.QuoDec() and DecCoins.QuoDecTruncate().

@ValarDragon
Copy link
Contributor

I'd prefer that personally! Makes a lot more sense imo

@evancholmberg evancholmberg changed the title fix: Make MulDecTruncate() panic when multiplier is 0 fix: Make MulDecTruncate() return nil DecCoins when multiplier is 0 Dec 16, 2021
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

🌮

@tac0turtle tac0turtle added the A:automerge Automatically merge PR once all prerequisites pass. label Dec 17, 2021
@atheeshp
Copy link
Contributor

@evancholmberg can you resolve the conflicts here.

@mergify mergify bot merged commit 08db287 into cosmos:master Jan 12, 2022
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mismatch in function documentation and observed behavior for DecCoin.MulDecTruncate function
6 participants