Skip to content

test: Convert amounts from float to decimal - #20039

Merged
maflcko merged 1 commit into
masterfrom
unknown repository
Oct 22, 2020
Merged

maflcko merged 1 commit into
masterfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Sep 29, 2020 •

Copy link
Copy Markdown

decimal is preferred in accounting applications

https://docs.python.org/3.8/library/decimal.html

Decimal type saves an exact value so better than using float.

3 variables declared with type as 'Decimal' in test/functional/mempool_accept.py: fee, fee_expected, output_amount

Not required to convert to string anymore for using the above variables as decimal

  • fee, fee_expected, output_amount
    + 8 decimal places
  • Using value of coin['amount'] as decimal and removed 'int'
  • Removed unnecessary parentheses
  • Remove str() and use quotes

Fixes #20011

Comment thread test/functional/mempool_accept.py Resolved
Comment thread test/functional/mempool_accept.py Resolved
@DrahtBot DrahtBot added the Tests label Sep 29, 2020
@ghost

ghost commented Oct 1, 2020 •

Copy link
Copy Markdown
Author

Made the changes in ba15b84

Was even thinking about adding getcontext().prec = 8 so that all operations in this file on decimals eventually result in 8 decimal places but not sure if it's the best approach to be used because it counts from most significant non-zero digit

@ghost
ghost marked this pull request as ready for review October 3, 2020 02:08

@guggero guggero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Concept ACK 3f56b32c.

Comment thread test/functional/mempool_accept.py Resolved
@decryp2kanon

decryp2kanon commented Oct 4, 2020 •

Copy link
Copy Markdown
Contributor

Concept ACK

@kristapsk

Copy link
Copy Markdown
Contributor

Concept ACK, but should squash the commits, I think.

Comment thread test/functional/mempool_accept.py Resolved

@guggero guggero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK 3afdc9bd - assuming commits are being squashed on merge.

Comment thread test/functional/mempool_accept.py Resolved
@maflcko

maflcko commented Oct 21, 2020

Copy link
Copy Markdown
Member

+ fee, fee_expected, output_amount
+ Using value of coin['amount'] as decimal and removed 'int'
+ Removed unnecessary parentheses
+ Remove str() and use quotes
@guggero

guggero commented Oct 22, 2020

Copy link
Copy Markdown
Contributor

ACK 5aadd4b

@maflcko
maflcko merged commit 1cb4e33 into bitcoin:master Oct 22, 2020
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 6, 2021
Summary:
Use python `Decimal` when defining fees and amounts. This ensures that subsequent operations on these amounts produces exact decimal amount, without potential rounding errors, instead of floats.

This is a backport of [[bitcoin/bitcoin#20039 | core#20039]]

Test Plan: `ninja check-functional`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10599
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: Convert amounts in testmempoolaccept test from float to decimal

8 participants