Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_packages.py
Show All 35 Lines | class MempoolPackagesTest(BitcoinTestFramework): | ||||
# Build a transaction that spends parent_txid:vout | # Build a transaction that spends parent_txid:vout | ||||
# Return amount sent | # Return amount sent | ||||
def chain_transaction(self, node, parent_txid, vout, | def chain_transaction(self, node, parent_txid, vout, | ||||
value, fee, num_outputs): | value, fee, num_outputs): | ||||
send_value = satoshi_round((value - fee) / num_outputs) | send_value = satoshi_round((value - fee) / num_outputs) | ||||
inputs = [{'txid': parent_txid, 'vout': vout}] | inputs = [{'txid': parent_txid, 'vout': vout}] | ||||
outputs = {} | outputs = {} | ||||
for i in range(num_outputs): | for _ in range(num_outputs): | ||||
outputs[node.getnewaddress()] = send_value | outputs[node.getnewaddress()] = send_value | ||||
rawtx = node.createrawtransaction(inputs, outputs) | rawtx = node.createrawtransaction(inputs, outputs) | ||||
signedtx = node.signrawtransactionwithwallet(rawtx) | signedtx = node.signrawtransactionwithwallet(rawtx) | ||||
txid = node.sendrawtransaction(signedtx['hex']) | txid = node.sendrawtransaction(signedtx['hex']) | ||||
fulltx = node.getrawtransaction(txid, 1) | fulltx = node.getrawtransaction(txid, 1) | ||||
# make sure we didn't generate a change output | # make sure we didn't generate a change output | ||||
assert len(fulltx['vout']) == num_outputs | assert len(fulltx['vout']) == num_outputs | ||||
return (txid, send_value) | return (txid, send_value) | ||||
def run_test(self): | def run_test(self): | ||||
# Mine some blocks and have them mature. | # Mine some blocks and have them mature. | ||||
# keep track of invs | # keep track of invs | ||||
self.nodes[0].add_p2p_connection(P2PTxInvStore()) | self.nodes[0].add_p2p_connection(P2PTxInvStore()) | ||||
self.nodes[0].generate(101) | self.nodes[0].generate(101) | ||||
utxo = self.nodes[0].listunspent(10) | utxo = self.nodes[0].listunspent(10) | ||||
txid = utxo[0]['txid'] | txid = utxo[0]['txid'] | ||||
vout = utxo[0]['vout'] | vout = utxo[0]['vout'] | ||||
value = utxo[0]['amount'] | value = utxo[0]['amount'] | ||||
fee = Decimal("100") | fee = Decimal("100") | ||||
# MAX_ANCESTORS transactions off a confirmed tx should be fine | # MAX_ANCESTORS transactions off a confirmed tx should be fine | ||||
chain = [] | chain = [] | ||||
for i in range(MAX_ANCESTORS): | for _ in range(MAX_ANCESTORS): | ||||
(txid, sent_value) = self.chain_transaction( | (txid, sent_value) = self.chain_transaction( | ||||
self.nodes[0], txid, 0, value, fee, 1) | self.nodes[0], txid, 0, value, fee, 1) | ||||
value = sent_value | value = sent_value | ||||
chain.append(txid) | chain.append(txid) | ||||
# Wait until mempool transactions have passed initial broadcast | # Wait until mempool transactions have passed initial broadcast | ||||
# (sent inv and received getdata) | # (sent inv and received getdata) | ||||
# Otherwise, getrawmempool may be inconsistent with getmempoolentry if | # Otherwise, getrawmempool may be inconsistent with getmempoolentry if | ||||
▲ Show 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.nodes[0], txid, vout, value, fee, 10) | self.nodes[0], txid, vout, value, fee, 10) | ||||
parent_transaction = txid | parent_transaction = txid | ||||
for i in range(10): | for i in range(10): | ||||
transaction_package.append( | transaction_package.append( | ||||
{'txid': txid, 'vout': i, 'amount': sent_value}) | {'txid': txid, 'vout': i, 'amount': sent_value}) | ||||
# Sign and send up to MAX_DESCENDANT transactions chained off the | # Sign and send up to MAX_DESCENDANT transactions chained off the | ||||
# parent tx | # parent tx | ||||
for i in range(MAX_DESCENDANTS - 1): | for _ in range(MAX_DESCENDANTS - 1): | ||||
utxo = transaction_package.pop(0) | utxo = transaction_package.pop(0) | ||||
(txid, sent_value) = self.chain_transaction( | (txid, sent_value) = self.chain_transaction( | ||||
self.nodes[0], utxo['txid'], utxo['vout'], utxo['amount'], fee, 10) | self.nodes[0], utxo['txid'], utxo['vout'], utxo['amount'], fee, 10) | ||||
if utxo['txid'] is parent_transaction: | if utxo['txid'] is parent_transaction: | ||||
tx_children.append(txid) | tx_children.append(txid) | ||||
for j in range(10): | for j in range(10): | ||||
transaction_package.append( | transaction_package.append( | ||||
{'txid': txid, 'vout': j, 'amount': sent_value}) | {'txid': txid, 'vout': j, 'amount': sent_value}) | ||||
Show All 40 Lines | def run_test(self): | ||||
utxo = self.nodes[0].listunspent() | utxo = self.nodes[0].listunspent() | ||||
txid = utxo[0]['txid'] | txid = utxo[0]['txid'] | ||||
value = utxo[0]['amount'] | value = utxo[0]['amount'] | ||||
vout = utxo[0]['vout'] | vout = utxo[0]['vout'] | ||||
send_value = satoshi_round((value - fee) / 2) | send_value = satoshi_round((value - fee) / 2) | ||||
inputs = [{'txid': txid, 'vout': vout}] | inputs = [{'txid': txid, 'vout': vout}] | ||||
outputs = {} | outputs = {} | ||||
for i in range(2): | for _ in range(2): | ||||
outputs[self.nodes[0].getnewaddress()] = send_value | outputs[self.nodes[0].getnewaddress()] = send_value | ||||
rawtx = self.nodes[0].createrawtransaction(inputs, outputs) | rawtx = self.nodes[0].createrawtransaction(inputs, outputs) | ||||
signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx) | signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx) | ||||
txid = self.nodes[0].sendrawtransaction(signedtx['hex']) | txid = self.nodes[0].sendrawtransaction(signedtx['hex']) | ||||
tx0_id = txid | tx0_id = txid | ||||
value = send_value | value = send_value | ||||
# Create tx1 | # Create tx1 | ||||
tx1_id, _ = self.chain_transaction( | tx1_id, _ = self.chain_transaction( | ||||
self.nodes[0], tx0_id, 0, value, fee, 1) | self.nodes[0], tx0_id, 0, value, fee, 1) | ||||
# Create tx2-7 | # Create tx2-7 | ||||
vout = 1 | vout = 1 | ||||
txid = tx0_id | txid = tx0_id | ||||
for i in range(6): | for _ in range(6): | ||||
(txid, sent_value) = self.chain_transaction( | (txid, sent_value) = self.chain_transaction( | ||||
self.nodes[0], txid, vout, value, fee, 1) | self.nodes[0], txid, vout, value, fee, 1) | ||||
vout = 0 | vout = 0 | ||||
value = sent_value | value = sent_value | ||||
# Mine these in a block | # Mine these in a block | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
self.sync_all() | self.sync_all() | ||||
Show All 17 Lines |