Add sat_to_btc
, btc_to_sat
utility functions to test framework and refactors all manual conversion on tests to use it;
Closes #31345
90@@ -91,7 +91,7 @@ def test_disable_flag(self):
91 utxo = self.wallet.send_self_transfer(from_node=self.nodes[0])["new_utxo"]
92
93 tx1 = CTransaction()
94- value = int((utxo["value"] - self.relayfee) * COIN)
95+ value = btc_to_sat(utxo["value"] - self.relayfee)
As mentioned previously, I don’t really see the benefit. a * COIN
should already be self-explanatory. On top of that, your approach comes with several downsides:
I think it is a fair enough critique, although I don’t fully agree that isn’t enforceable;
PRs go through review, and the test_framework exists as a facilitator; It is part of the review process to see if we are adding repetitive code that could be abstracted away;
Many parts of the test_framework could arguably be inlined; Even the COIN
constant itself could be removed, and replaced with just 1e8, since that is bounded to never change;
Out of curiosity: would a class Sats/Coin/Bitcoin
with constructors for str, int and decimal, that has these two methods to represent the value in different unit scales be any better?
Or do you believe the concept is flawed in itself?
On the defaults: That is already a problem on the test suite - there is some interactions of float and decimal, and by definition all operations should be in sats/integer and just displayed as BTC when it makes sense; I could tackle that, but I believe it would make the most sense to be in a different issue/PR?
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31420.
See the guideline for information on the review process.
Type | Reviewers |
---|---|
Concept NACK | brunoerg |
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Concept NACK
I agree with @maflcko (https://github.com/bitcoin/bitcoin/pull/31420#discussion_r1870885962) and prefer to leave is as-is. I don’t see any strong benefit on having these functions and I think if we start mixing both styles the code would get more confusing.
Also, I think the third commit should be squashed, you are not removing current unused imports, you are removing imports that became unecessary due to the usage of these new functions. So, you could remove the imports along with the adoption of the functions.
The squash makes sense, will do it if the this goes forward;
As for the nack, I’d kindly ask to check my reply #31420 (review) Added an extra proposal; I believe there is value in having a standard way to represent and interact with sats amounts without doing conversions but rather representations and better constructors
🐙 This pull request conflicts with the target branch and needs rebase.