Skip to content

Conversation

@hungdinh82
Copy link
Contributor

Description

ref: #7175


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 the 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 and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

@hungdinh82
Copy link
Contributor Author

can you review it? @gjermundgaraba @srdtrk @AdityaSripal

@hungdinh82
Copy link
Contributor Author

How about this PR? @gjermundgaraba

expAmount = sdkmath.NewInt(-1)
},
false,
errors.New("negative coin amount: -1"),
Copy link
Contributor

Choose a reason for hiding this comment

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

A bit unsure why this passes 🤔 From the code it calls, it looks like the error should be different.

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 want to break it down comparing the old code and the new code to make it easier to understand. @gjermundgaraba

Old code:
expPass bool
// true => Pass
// false => Panic with message "negative coin amount: -1"
New code:
expError error
// nil => Pass
// not nill =>errors.New("negative coin amount: -1") => Same error as before (panic)

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I get that part. But if you look at the actual code that is being called, it looks like it should be failing with a different error message. So I wonder if that message is checked at all.

Copy link
Contributor Author

@hungdinh82 hungdinh82 Apr 14, 2025

Choose a reason for hiding this comment

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

In this case, the panic message "negative coin amount: -1" is actually raised by sdk.NewCoin(...), not by SetTotalEscrowForDenom(...). @gjermundgaraba

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 a comment in the test code to clarify that the panic is expected from sdk.NewCoin.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, in that case, the test is actually wrong. We're just testing our test code :)
Can you instead change it so that we manually create a Coin struct with the expAmount, so we test the actual code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok wait for me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok I created a coin struct, can you review it again? @gjermundgaraba

@hungdinh82
Copy link
Contributor Author

"PanicsWithError(...) is still being used → the test is still expecting a panic, not switching the logic to a returned error."
@gjermundgaraba

@hungdinh82
Copy link
Contributor Author

can you review it again? @gjermundgaraba

@gjermundgaraba gjermundgaraba added this pull request to the merge queue Apr 15, 2025
Merged via the queue into cosmos:main with commit c6d52d0 Apr 15, 2025
50 of 51 checks passed
mergify bot pushed a commit that referenced this pull request Apr 15, 2025
…8282)

* fix TestSetGetTotalEscrowForDenom

* fix TestSetGetTotalEscrowForDenom

* add comment to explain where is panic

* test(transfer): construct Coin manually to test SetTotalEscrowForDenom panic logic

* lint

---------

Co-authored-by: Gjermund Garaba <gjermund@garaba.net>
(cherry picked from commit c6d52d0)
gjermundgaraba pushed a commit that referenced this pull request Apr 15, 2025
…8282) (#8308)

* fix TestSetGetTotalEscrowForDenom

* fix TestSetGetTotalEscrowForDenom

* add comment to explain where is panic

* test(transfer): construct Coin manually to test SetTotalEscrowForDenom panic logic

* lint

---------

Co-authored-by: Gjermund Garaba <gjermund@garaba.net>
(cherry picked from commit c6d52d0)

Co-authored-by: Hung Dinh | Decentrio <76930315+hungdinh82@users.noreply.github.com>
DeshErBojhaa pushed a commit that referenced this pull request May 12, 2025
…8282)

* fix TestSetGetTotalEscrowForDenom

* fix TestSetGetTotalEscrowForDenom

* add comment to explain where is panic

* test(transfer): construct Coin manually to test SetTotalEscrowForDenom panic logic

* lint

---------

Co-authored-by: Gjermund Garaba <gjermund@garaba.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants