diff options
author | Ava Chow <github@achow101.com> | 2024-09-04 13:26:57 -0400 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2024-09-04 13:26:57 -0400 |
commit | 210210c923187f914cad5ddcf719c65dde225438 (patch) | |
tree | bbe0604310a7be0e91eac19bb85ddd1c0bf0cb71 /test/functional/test_framework | |
parent | b0c3de684795f7f5e54b59e810d1bc57433d476e (diff) | |
parent | ec317bc44b0cb089419d809b5fef38ecb9423051 (diff) |
Merge bitcoin/bitcoin#29566: test: update satoshi_round function
ec317bc44b0cb089419d809b5fef38ecb9423051 test: update satoshi_round function (naiyoma)
Pull request description:
This PR refactors `satoshi_round` to accept different rounding modes and make rounding a required argument.
Continuation of https://github.com/bitcoin/bitcoin/pull/23225
ACKs for top commit:
maflcko:
review ACK ec317bc44b0cb089419d809b5fef38ecb9423051
achow101:
ACK ec317bc44b0cb089419d809b5fef38ecb9423051
AngusP:
ACK ec317bc44b0cb089419d809b5fef38ecb9423051
Tree-SHA512: 070f0aa6f66e58bff7412cae6b71f5f4ab8c718c7b5eeba4bb604fe22c6416a1ced0474294f504e1c28943ddc073104466b5944b43bae27e42bee5ca85afa468
Diffstat (limited to 'test/functional/test_framework')
-rw-r--r-- | test/functional/test_framework/util.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 00fe5b08e4..ce68de7eaa 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -5,7 +5,7 @@ """Helpful routines for regression testing.""" from base64 import b64encode -from decimal import Decimal, ROUND_DOWN +from decimal import Decimal from subprocess import CalledProcessError import hashlib import inspect @@ -21,7 +21,9 @@ import time from . import coverage from .authproxy import AuthServiceProxy, JSONRPCException from collections.abc import Callable -from typing import Optional +from typing import Optional, Union + +SATOSHI_PRECISION = Decimal('0.00000001') logger = logging.getLogger("TestFramework.utils") @@ -261,8 +263,9 @@ def get_fee(tx_size, feerate_btc_kvb): return target_fee_sat / Decimal(1e8) # Return result in BTC -def satoshi_round(amount): - return Decimal(amount).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN) +def satoshi_round(amount: Union[int, float, str], *, rounding: str) -> Decimal: + """Rounds a Decimal amount to the nearest satoshi using the specified rounding mode.""" + return Decimal(amount).quantize(SATOSHI_PRECISION, rounding=rounding) def wait_until_helper_internal(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None, timeout_factor=1.0): |