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

Mismatch in function documentation and observed behavior for DecCoin.MulDecTruncate function #9790

Closed
4 tasks
spoo-bar opened this issue Jul 27, 2021 · 2 comments · Fixed by #10687
Closed
4 tasks

Comments

@spoo-bar
Copy link
Contributor

spoo-bar commented Jul 27, 2021

Summary of Bug

Function comment documentation for MulDecTruncate (for DecCoin ) says if multiplier d is zero, it should panic.
However, that is not the observed behavior. Currently nil is returned.

// MulDecTruncate multiplies all the decimal coins by a decimal, truncating. It
// panics if d is zero.
//
// CONTRACT: No zero coins will be returned.
func (coins DecCoins) MulDecTruncate(d Dec) DecCoins {

Version

v0.43

Steps to Reproduce

Pass in parameter d value as sdk.NewDec(0)

Or

Test case # 1 tests for this scenario

{"Multiple coins - zero multiplier", sdk.DecCoins{
sdk.DecCoin{testDenom1, sdk.NewDecWithPrec(10, 3)},
sdk.DecCoin{testDenom1, sdk.NewDecWithPrec(30, 2)},
}, sdk.NewDec(0), sdk.DecCoins(nil), false},


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@evancholmberg
Copy link
Contributor

I would like to work on this issue. I see that there is a comment above the test that states it needs to be fixed. So the behavior of the function needs to change to panic when multiplier d is zero and the test needs to change to expect a panic?

@alexanderbez
Copy link
Contributor

I would like to work on this issue. I see that there is a comment above the test that states it needs to be fixed. So the behavior of the function needs to change to panic when multiplier d is zero and the test needs to change to expect a panic?

Yes :)

@mergify mergify bot closed this as completed in #10687 Jan 12, 2022
mergify bot pushed a commit that referenced this issue Jan 12, 2022
…10687)

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

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants