diff --git a/test/functional/abandonconflict.py b/test/functional/abandonconflict.py --- a/test/functional/abandonconflict.py +++ b/test/functional/abandonconflict.py @@ -12,6 +12,7 @@ """ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import * +from test_framework.mininode import * class AbandonConflictTest(BitcoinTestFramework): @@ -20,6 +21,14 @@ self.extra_args = [["-minrelaytxfee=0.00001"], []] def run_test(self): + def total_fees(*txids): + total = 0 + for txid in txids: + ctx = FromHex(CTransaction(), + self.nodes[0].getrawtransaction(txid)) + total += self.nodes[0].calculate_fee_from_txid(txid) + + return satoshi_round(total) self.nodes[1].generate(100) sync_blocks(self.nodes) balance = self.nodes[0].getbalance() @@ -29,13 +38,14 @@ self.nodes[0].getnewaddress(), Decimal("10")) txC = self.nodes[0].sendtoaddress( self.nodes[0].getnewaddress(), Decimal("10")) + sync_mempools(self.nodes) self.nodes[1].generate(1) - sync_blocks(self.nodes) newbalance = self.nodes[0].getbalance() + # no more than fees lost - assert(balance - newbalance < Decimal("0.001")) + assert(balance - newbalance <= total_fees(txA, txB, txC)) balance = newbalance # Disconnect nodes so node0's transactions don't get into node1's mempool diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -13,7 +13,7 @@ import subprocess import time -from .mininode import COIN, ToHex +from .mininode import COIN, ToHex, FromHex, CTransaction from .util import ( assert_equal, get_rpc_proxy, @@ -169,6 +169,10 @@ # to get back to an amount of satoshis. return int(self.relay_fee() / 1000 * len(ToHex(tx)) * COIN) + def calculate_fee_from_txid(self, txid): + ctx = FromHex(CTransaction(), self.getrawtransaction(txid)) + return self.calculate_fee(ctx) + class TestNodeCLI(): """Interface to bitcoin-cli for an individual node"""