Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mempool_packages.py
Show All 29 Lines | class MempoolPackagesTest(BitcoinTestFramework): | ||||
# Return amount sent | # Return amount sent | ||||
def chain_transaction(self, node, parent_txid, vout, value, fee, num_outputs): | def chain_transaction(self, node, parent_txid, vout, 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 i 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.signrawtransaction(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. ''' | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
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 i 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].signrawtransaction(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) | ||||
Show All 9 Lines | def run_test(self): | ||||
# 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() | ||||
# Now generate tx8, with a big fee | # Now generate tx8, with a big fee | ||||
inputs = [{'txid': tx1_id, 'vout': 0}, {'txid': txid, 'vout': 0}] | inputs = [{'txid': tx1_id, 'vout': 0}, {'txid': txid, 'vout': 0}] | ||||
outputs = {self.nodes[0].getnewaddress(): send_value + value - 4 * fee} | outputs = {self.nodes[0].getnewaddress(): send_value + value - 4 * fee} | ||||
rawtx = self.nodes[0].createrawtransaction(inputs, outputs) | rawtx = self.nodes[0].createrawtransaction(inputs, outputs) | ||||
signedtx = self.nodes[0].signrawtransaction(rawtx) | signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx) | ||||
txid = self.nodes[0].sendrawtransaction(signedtx['hex']) | txid = self.nodes[0].sendrawtransaction(signedtx['hex']) | ||||
sync_mempools(self.nodes) | sync_mempools(self.nodes) | ||||
# Now try to disconnect the tip on each node... | # Now try to disconnect the tip on each node... | ||||
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash()) | self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash()) | ||||
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) | ||||
sync_blocks(self.nodes) | sync_blocks(self.nodes) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
MempoolPackagesTest().main() | MempoolPackagesTest().main() |