Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

[CBR-461] Improve diagnostic for NotEnoughMoney error #3702

Merged
merged 2 commits into from
Oct 3, 2018

Conversation

KtorZ
Copy link
Contributor

@KtorZ KtorZ commented Oct 3, 2018

Description

When computing fees or making a transaction, it could happen that funds
are currently "locked" out because selected in a pending transaction. In
such case, the UTxO can't be spent until the transaction has been
accepted by (at least) a node. The API currently returns a
NotEnoughMoney error in such case, whereas the total balance (as
returned by /api/v1/wallets/{walletId} endpoint) might show enough
funds.

This refines a bit the NotEnoughMoney error to make the reason
of failure clearer without breaking (too much) the existing API.

NOTE: There's one "expected" failing integration test which actually shed the light on a newly discovered bug (0 fee transaction).

Linked issue

[CBR-461]

Type of change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🛠 New feature (non-breaking change which adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)
  • 🏭 Refactoring that does not change existing functionality but does improve things like code readability, structure etc
  • 🔨 New or improved tests for existing code
  • ⛑ git-flow chore (backport, hotfix, etc)

Developer checklist

  • I have read the style guide document, and my code follows the code style of this project.
  • If my code deals with exceptions, it follows the guidelines.
  • I have updated any documentation accordingly, if needed. Documentation changes can be reflected in opening a PR on cardanodocs.com, amending the inline Haddock comments, any relevant README file or one of the document listed in the docs directory.
  • CHANGELOG entry has been added and is linked to the correct PR on GitHub.

Testing checklist

  • I have added tests to cover my changes.
  • [ ] All new and existing tests passed.

QA Steps

Screenshots (if available)

When computing fees or making a transaction, it could happen that funds
are currently "locked" out because selected in a pending transaction. In
such case, the UTxO can't be spent until the transaction has been
accepted by (at least) a node. The API currently returns a
NotEnoughMoney error in such case, whereas the total balance (as
returned by /api/v1/wallets/{walletId} endpoint) might show enough
funds.

This refines a bit the `NotEnoughMoney` error to make the reason
of failure clearer without breaking (too much) the existing API.
@KtorZ
Copy link
Contributor Author

KtorZ commented Oct 3, 2018

Integration tests failing as "expected":

  integration/Util.hs:129:5: 
  1) Transactions fails if you can't cover fee with a transaction
       Falsifiable (after 1 test):
       
       predicate failed on: Right (Transaction {txId = AbstractHash 9459bb25a09439a0337857db0e2d3f95bf240a0a1608d60b9616072da4873ad6, txConfirmations = 0, txAmount = Coin {getCoin = 42}, txInputs = PaymentDistribution {pdAddress = Address {addrRoot = AbstractHash 42a18f1ee2cbbf37aad3370b27e43861c5330931c310157d75462dd7, addrAttributes = Attributes { data: AddrAttributes {aaPkDerivationPath = Just (HDAddressPayload {getHDAddressPayload = "\ENQ\SO{ \SI\RS\222\212\193\255\192c\166\200\v\204\182\240\201\161\213M\166V\134\160\172\212"}), aaStakeDistribution = BootstrapEraDistr} }, addrType = ATPubKey}, pdAmount = Coin {getCoin = 42}} :| [], txOutputs = PaymentDistribution {pdAddress = Address {addrRoot = AbstractHash f4cbe4cdeb6f727dd973b130c1233753415b69a601a3509c692eff45, addrAttributes = Attributes { data: AddrAttributes {aaPkDerivationPath = Just (HDAddressPayload {getHDAddressPayload = "\137\229\DC3(\US\229rmFE9\EOT+\129\GS\218w\166baK\156\213\EOT<\192-\147"}), aaStakeDistribution = BootstrapEraDistr} }, addrType = ATPubKey}, pdAmount = Coin {getCoin = 42}} :| [], txType = ForeignTransaction, txDirection = OutgoingTransaction, txCreationTime = 1538569020551488, txStatus = Applying})

Investigating in [CBR-462]

Copy link
Contributor

@adinapoli-iohk adinapoli-iohk left a comment

Choose a reason for hiding this comment

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

LGTM.

@@ -60,6 +60,7 @@

- The codebase now relies on the package `cryptonite` (instead of `ed25519`) for Ed25519 implementation (CO-325)

- **[API BREAKING CHANGE]** Improve diagnostic for `NotEnoughMoney` error (CBR-461)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Whoops :trollface:

@@ -350,7 +350,7 @@ $errors
errors = T.intercalate "\n" rows
rows =
-- 'WalletError'
[ mkRow fmtErr $ NotEnoughMoney 1400
[ mkRow fmtErr $ NotEnoughMoney (ErrAvailableBalanceIsInsufficient 1400)
Copy link
Contributor

Choose a reason for hiding this comment

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

Good lad!

@KtorZ KtorZ merged commit 5d59841 into develop Oct 3, 2018
@KtorZ KtorZ deleted the KtorZ/CBR-461/improve-not-enough-money-error branch October 3, 2018 15:03
KtorZ added a commit that referenced this pull request Nov 9, 2018
…ot-enough-money-error

[CBR-461] Improve diagnostic for `NotEnoughMoney` error
KtorZ added a commit to input-output-hk/cardano-wallet-legacy that referenced this pull request Nov 9, 2018
…hk/KtorZ/CBR-461/improve-not-enough-money-error

[CBR-461] Improve diagnostic for `NotEnoughMoney` error
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants