Skip to content

fix: error message for over available tokens to mint or melt #791

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

Merged
merged 4 commits into from
Oct 11, 2024

Conversation

alexruzenhack
Copy link
Contributor

@alexruzenhack alexruzenhack commented Oct 9, 2024

Motivation

When we try to mint or melt tokens with more than the available amount, it throws an error. The error message informs the requested amount to mint or melt and the available token amount. The bug here is that the available amount is always zero.

Acceptance Criteria

  • The available amount should be equal to the total available token, not zero

It closes https://github.com/HathorNetwork/internal-issues/issues/398

Security Checklist

  • Make sure you do not include new dependencies in the project unless strictly necessary and do not include dev-dependencies as production ones. More dependencies increase the possibility of one of them being hijacked and affecting us.

@alexruzenhack alexruzenhack requested a review from r4mmer October 9, 2024 23:23
@alexruzenhack alexruzenhack self-assigned this Oct 9, 2024
@@ -1981,7 +1981,8 @@ describe('mintTokens', () => {
const { hash: tokenUid } = await createTokenHelper(hWallet, 'Token to Mint', 'TMINT', 100);

// Should not mint more tokens than the HTR funds allow
await expect(hWallet.mintTokens(tokenUid, 9000)).rejects.toThrow('HTR tokens');
await expect(hWallet.mintTokens(tokenUid, 9000))
.rejects.toThrow(/^Not enough HTR tokens for deposit: 90 required, \d+ available$/);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The available tokens can change for each test, therefore we match for any digit with \d+.

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.53%. Comparing base (cd6c695) to head (ac64e40).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #791   +/-   ##
=======================================
  Coverage   80.52%   80.53%           
=======================================
  Files          81       81           
  Lines        6460     6462    +2     
  Branches     1400     1393    -7     
=======================================
+ Hits         5202     5204    +2     
  Misses       1245     1245           
  Partials       13       13           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

throw new InsufficientFundsError(
`Not enough HTR tokens for deposit: ${depositAmount} required, ${foundAmount} available`
`Not enough HTR tokens for deposit: ${depositAmount} required, ${availableAmount} available`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error message is used as an error feedback message for users on Wallet Desktop. We could have removed the "available" part from the message as an easier solution, however as it is used in the frontend Carneiro and I discussed it would be better to change the "internals" rather then the message.

pedroferreira1
pedroferreira1 previously approved these changes Oct 10, 2024
@@ -49,7 +49,7 @@ export async function fastUtxoSelection(
storage: IStorage,
token: string,
amount: OutputValueType
): Promise<{ utxos: IUtxo[]; amount: OutputValueType }> {
): Promise<{ utxos: IUtxo[]; amount: OutputValueType; available?: OutputValueType }> {
Copy link
Member

Choose a reason for hiding this comment

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

Missing this new return key in the docstring

pedroferreira1
pedroferreira1 previously approved these changes Oct 11, 2024
@alexruzenhack alexruzenhack force-pushed the fix/mint-melt-over-available-tokens branch from 90a7018 to ac64e40 Compare October 11, 2024 15:49
@alexruzenhack alexruzenhack merged commit 951eef3 into master Oct 11, 2024
5 checks passed
@alexruzenhack alexruzenhack deleted the fix/mint-melt-over-available-tokens branch October 11, 2024 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants