diff --git a/test/functional/abc-high_priority_transaction.py b/test/functional/abc-high_priority_transaction.py --- a/test/functional/abc-high_priority_transaction.py +++ b/test/functional/abc-high_priority_transaction.py @@ -11,6 +11,7 @@ from test_framework.util import * from test_framework.mininode import COIN from test_framework.cdefs import LEGACY_MAX_BLOCK_SIZE, COINBASE_MATURITY +from test_framework.blocktools import create_confirmed_utxos class HighPriorityTransactionTest(BitcoinTestFramework): diff --git a/test/functional/dbcrash.py b/test/functional/dbcrash.py --- a/test/functional/dbcrash.py +++ b/test/functional/dbcrash.py @@ -35,6 +35,7 @@ from test_framework.script import * from test_framework.test_framework import BitcoinTestFramework from test_framework.util import * +from test_framework.blocktools import create_confirmed_utxos HTTP_DISCONNECT_ERRORS = [http.client.CannotSendRequest] try: diff --git a/test/functional/mempool_limit.py b/test/functional/mempool_limit.py --- a/test/functional/mempool_limit.py +++ b/test/functional/mempool_limit.py @@ -7,7 +7,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import * -from test_framework.blocktools import send_big_transactions +from test_framework.blocktools import send_big_transactions, create_confirmed_utxos class MempoolLimitTest(BitcoinTestFramework): diff --git a/test/functional/prioritise_transaction.py b/test/functional/prioritise_transaction.py --- a/test/functional/prioritise_transaction.py +++ b/test/functional/prioritise_transaction.py @@ -12,7 +12,7 @@ from test_framework.mininode import COIN # FIXME: review how this test needs to be adapted w.r.t _LEGACY_MAX_BLOCK_SIZE from test_framework.cdefs import LEGACY_MAX_BLOCK_SIZE -from test_framework.blocktools import send_big_transactions +from test_framework.blocktools import send_big_transactions, create_confirmed_utxos class PrioritiseTransactionTest(BitcoinTestFramework): diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py --- a/test/functional/test_framework/blocktools.py +++ b/test/functional/test_framework/blocktools.py @@ -99,6 +99,41 @@ return count +# Helper to create at least "count" utxos +# Pass in a fee that is sufficient for relay and mining new transactions. + + +def create_confirmed_utxos(fee, node, count, age=101): + to_generate = int(0.5 * count) + age + while to_generate > 0: + node.generate(min(25, to_generate)) + to_generate -= 25 + utxos = node.listunspent() + iterations = count - len(utxos) + addr1 = node.getnewaddress() + addr2 = node.getnewaddress() + if iterations <= 0: + return utxos + for i in range(iterations): + t = utxos.pop() + inputs = [] + inputs.append({"txid": t["txid"], "vout": t["vout"]}) + outputs = {} + send_value = t['amount'] - fee + outputs[addr1] = satoshi_round(send_value / 2) + outputs[addr2] = satoshi_round(send_value / 2) + raw_tx = node.createrawtransaction(inputs, outputs) + signed_tx = node.signrawtransaction(raw_tx)["hex"] + node.sendrawtransaction(signed_tx) + + while (node.getmempoolinfo()['size'] > 0): + node.generate(1) + + utxos = node.listunspent() + assert(len(utxos) >= count) + return utxos + + def send_big_transactions(node, utxos, num, fee_multiplier): txids = [] padding = "1"*(512*127) diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -575,40 +575,6 @@ return (txid, signresult["hex"], fee) -# Helper to create at least "count" utxos -# Pass in a fee that is sufficient for relay and mining new transactions. - - -def create_confirmed_utxos(fee, node, count, age=101): - to_generate = int(0.5 * count) + age - while to_generate > 0: - node.generate(min(25, to_generate)) - to_generate -= 25 - utxos = node.listunspent() - iterations = count - len(utxos) - addr1 = node.getnewaddress() - addr2 = node.getnewaddress() - if iterations <= 0: - return utxos - for i in range(iterations): - t = utxos.pop() - inputs = [] - inputs.append({"txid": t["txid"], "vout": t["vout"]}) - outputs = {} - send_value = t['amount'] - fee - outputs[addr1] = satoshi_round(send_value / 2) - outputs[addr2] = satoshi_round(send_value / 2) - raw_tx = node.createrawtransaction(inputs, outputs) - signed_tx = node.signrawtransaction(raw_tx)["hex"] - node.sendrawtransaction(signed_tx) - - while (node.getmempoolinfo()['size'] > 0): - node.generate(1) - - utxos = node.listunspent() - assert(len(utxos) >= count) - return utxos - # Create large OP_RETURN txouts that can be appended to a transaction # to make it large (helper for constructing large transactions).