Skip to content

Commit

Permalink
Merge bitcoin#29343: test: fix wallet_import_rescan unrounded minimum…
Browse files Browse the repository at this point in the history
… amount

26ad2ae test: fix wallet_import_rescan unrounded minimum amount (stickies-v)

Pull request description:

  Addresses bitcoin#29283 (comment).

  Fixes a `JSONRPCException: Invalid amount (-3)` exception by ensuring the amount sent to `sendtoaddress` is rounded to 8 decimals.

  See https://cirrus-ci.com/task/5562947183837184?logs=ci#L2559

  Note: since `round` can also round down, `min_amount` is not _exactly_ guaranteed, but this is not a problem for the current usage. I've added a docstring to highlight this.

ACKs for top commit:
  sr-gi:
    ACK [26ad2ae](bitcoin@26ad2ae)

Tree-SHA512: 82ce16447f30535f17fa73336f7e4f74639e33215a228294b9b8005b8050a760b90a3726de279cce98c7e439f09104172b74072be3a300dbd461bf0c3f54b954
  • Loading branch information
fanquake committed Jan 31, 2024
2 parents cad2df2 + 26ad2ae commit 11b436a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions test/functional/wallet_import_rescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ def check(self, txid=None, amount=None, confirmation_height=None):
AMOUNT_DUST = 0.00000546


def get_rand_amount():
r = random.uniform(AMOUNT_DUST, 1)
def get_rand_amount(min_amount=AMOUNT_DUST):
assert min_amount <= 1
r = random.uniform(min_amount, 1)
# note: min_amount can get rounded down here
return Decimal(str(round(r, 8)))


Expand Down Expand Up @@ -273,7 +275,7 @@ def run_test(self):
variant.key = self.nodes[1].dumpprivkey(variant.address["address"])
# Ensure output is large enough to pay for fees: conservatively assuming txsize of
# 500 vbytes and feerate of 20 sats/vbytes
variant.initial_amount = max(get_rand_amount(), (500 * 20 / COIN) + AMOUNT_DUST)
variant.initial_amount = get_rand_amount(min_amount=((500 * 20 / COIN) + AMOUNT_DUST))
variant.initial_txid = self.nodes[0].sendtoaddress(variant.address["address"], variant.initial_amount)
variant.confirmation_height = 0
variant.timestamp = timestamp
Expand Down

0 comments on commit 11b436a

Please sign in to comment.