Skip to content

Commit 26ad2ae

Browse files
committed
test: fix wallet_import_rescan unrounded minimum amount
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
1 parent 5fbcc8f commit 26ad2ae

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

test/functional/wallet_import_rescan.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ def check(self, txid=None, amount=None, confirmation_height=None):
145145
AMOUNT_DUST = 0.00000546
146146

147147

148-
def get_rand_amount():
149-
r = random.uniform(AMOUNT_DUST, 1)
148+
def get_rand_amount(min_amount=AMOUNT_DUST):
149+
assert min_amount <= 1
150+
r = random.uniform(min_amount, 1)
151+
# note: min_amount can get rounded down here
150152
return Decimal(str(round(r, 8)))
151153

152154

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

0 commit comments

Comments
 (0)