aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2014-09-05 10:48:28 -0400
committerGavin Andresen <gavinandresen@gmail.com>2014-09-05 10:48:28 -0400
commit6ee78938ee6fda4fd80ece1eb5d736c79045eddd (patch)
tree18510adf12d5f3b9ab55d46fa581d9763830a810
parentf79323b0ddbab5c8e6a3bc26450d2699d838e229 (diff)
parent3a7c3483b6df12e84aefb937b85afec746b06b5e (diff)
Merge pull request #4836 from morcos/fix-make_change
Fix make_change to not create half-satoshis
-rw-r--r--qa/rpc-tests/util.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/qa/rpc-tests/util.py b/qa/rpc-tests/util.py
index da2b6df197..87baadc5d6 100644
--- a/qa/rpc-tests/util.py
+++ b/qa/rpc-tests/util.py
@@ -10,7 +10,7 @@ import os
import sys
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "python-bitcoinrpc"))
-from decimal import Decimal
+from decimal import Decimal, ROUND_DOWN
import json
import random
import shutil
@@ -230,10 +230,12 @@ def make_change(from_node, amount_in, amount_out, fee):
change = amount_in - amount
if change > amount*2:
# Create an extra change output to break up big inputs
- outputs[from_node.getnewaddress()] = float(change/2)
- change = change/2
+ change_address = from_node.getnewaddress()
+ # Split change in two, being careful of rounding:
+ outputs[change_address] = Decimal(change/2).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN)
+ change = amount_in - amount - outputs[change_address]
if change > 0:
- outputs[from_node.getnewaddress()] = float(change)
+ outputs[from_node.getnewaddress()] = change
return outputs
def send_zeropri_transaction(from_node, to_node, amount, fee):