mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 11:27:28 -03:00
Merge bitcoin/bitcoin#29566: test: update satoshi_round function
Some checks are pending
Some checks are pending
ec317bc44b
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 ACKec317bc44b
achow101: ACKec317bc44b
AngusP: ACKec317bc44b
Tree-SHA512: 070f0aa6f66e58bff7412cae6b71f5f4ab8c718c7b5eeba4bb604fe22c6416a1ced0474294f504e1c28943ddc073104466b5944b43bae27e42bee5ca85afa468
This commit is contained in:
commit
210210c923
2 changed files with 9 additions and 6 deletions
|
@ -4,7 +4,7 @@
|
|||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
"""Test fee estimation code."""
|
||||
from copy import deepcopy
|
||||
from decimal import Decimal
|
||||
from decimal import Decimal, ROUND_DOWN
|
||||
import os
|
||||
import random
|
||||
import time
|
||||
|
@ -40,7 +40,7 @@ def small_txpuzzle_randfee(
|
|||
# Exponentially distributed from 1-128 * fee_increment
|
||||
rand_fee = float(fee_increment) * (1.1892 ** random.randint(0, 28))
|
||||
# Total fee ranges from min_fee to min_fee + 127*fee_increment
|
||||
fee = min_fee - fee_increment + satoshi_round(rand_fee)
|
||||
fee = min_fee - fee_increment + satoshi_round(rand_fee, rounding=ROUND_DOWN)
|
||||
utxos_to_spend = []
|
||||
total_in = Decimal("0.00000000")
|
||||
while total_in <= (amount + fee) and len(conflist) > 0:
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue