Page MenuHomePhabricator

tests: fix a few misuses of Decimal
ClosedPublic

Authored by PiRK on Dec 2 2021, 07:48.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABCa6f4136791e7: tests: fix a few misuses of Decimal
Summary
  • In abc_rpc_avalancheproof.py, dust_amount was unneccesarily converted from a string to string via a Decimal. Use the string directly.
  • In rpc_fundrawtransaction.py, use quote around the float value, to avoid loss of precision caused by intermediate float storage.
  • In wallet_send.py, the tx size is an integer. Just use an integer division instead of creating an intermediate float and a Decimal.

Changes related to D10599

Test Plan

ninja check-functional

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Dec 2 2021, 07:48
Fabien requested changes to this revision.Dec 3 2021, 15:02
Fabien added a subscriber: Fabien.
Fabien added inline comments.
test/functional/wallet_send.py
297 ↗(On Diff #31228)

This is not equivalent ? In previous version the value was a floating point (represented as decimal) whereas it is now integer only. If len(res["hex"]) is odd you don't get the same result.

This revision now requires changes to proceed.Dec 3 2021, 15:02
test/functional/wallet_send.py
297 ↗(On Diff #31228)

Is it enough if we add an assertion to make sure len(res["hex"]) is even? If a raw transaction in hexadecimal format has an odd length, then we have a problem that is worse than the fee amount being incorrect.

use count_bytes instead of simply dividing the hex length by 2. This has the benefit of raising an error if the raw hex string is not valid because it has an odd length.

This is the same way assert_fee_amount is also used in another test (wallet_basic.py:229)

This revision is now accepted and ready to land.Dec 6 2021, 09:03
This revision was automatically updated to reflect the committed changes.