Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_generateblock.py
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
['addresses'][0], combo_address) | ['addresses'][0], combo_address) | ||||
# Generate 110 blocks to spend | # Generate 110 blocks to spend | ||||
node.generatetoaddress(110, address) | node.generatetoaddress(110, address) | ||||
# Generate some extra mempool transactions to verify they don't get | # Generate some extra mempool transactions to verify they don't get | ||||
# mined | # mined | ||||
for i in range(10): | for i in range(10): | ||||
node.sendtoaddress(address, 0.001) | node.sendtoaddress(address, 1000) | ||||
self.log.info('Generate block with txid') | self.log.info('Generate block with txid') | ||||
txid = node.sendtoaddress(address, 1) | txid = node.sendtoaddress(address, 1000000) | ||||
hash = node.generateblock(address, [txid])['hash'] | hash = node.generateblock(address, [txid])['hash'] | ||||
block = node.getblock(hash, 1) | block = node.getblock(hash, 1) | ||||
assert_equal(len(block['tx']), 2) | assert_equal(len(block['tx']), 2) | ||||
assert_equal(block['tx'][1], txid) | assert_equal(block['tx'][1], txid) | ||||
self.log.info('Generate block with raw tx') | self.log.info('Generate block with raw tx') | ||||
utxos = node.listunspent(addresses=[address]) | utxos = node.listunspent(addresses=[address]) | ||||
raw = node.createrawtransaction( | raw = node.createrawtransaction( | ||||
[{'txid': utxos[0]['txid'], 'vout':utxos[0]['vout']}], [{address: 1}]) | [{'txid': utxos[0]['txid'], 'vout':utxos[0]['vout']}], [{address: 1000000}]) | ||||
signed_raw = node.signrawtransactionwithwallet(raw)['hex'] | signed_raw = node.signrawtransactionwithwallet(raw)['hex'] | ||||
hash = node.generateblock(address, [signed_raw])['hash'] | hash = node.generateblock(address, [signed_raw])['hash'] | ||||
block = node.getblock(hash, 1) | block = node.getblock(hash, 1) | ||||
assert_equal(len(block['tx']), 2) | assert_equal(len(block['tx']), 2) | ||||
txid = block['tx'][1] | txid = block['tx'][1] | ||||
assert_equal(node.gettransaction(txid)['hex'], signed_raw) | assert_equal(node.gettransaction(txid)['hex'], signed_raw) | ||||
self.log.info('Fail to generate block with out of order txs') | self.log.info('Fail to generate block with out of order txs') | ||||
raw1 = node.createrawtransaction( | raw1 = node.createrawtransaction( | ||||
[{'txid': txid, 'vout': 0}], [{address: 0.9999}]) | [{'txid': txid, 'vout': 0}], [{address: 999900}]) | ||||
signed_raw1 = node.signrawtransactionwithwallet(raw1)['hex'] | signed_raw1 = node.signrawtransactionwithwallet(raw1)['hex'] | ||||
txid1 = node.sendrawtransaction(signed_raw1) | txid1 = node.sendrawtransaction(signed_raw1) | ||||
raw2 = node.createrawtransaction( | raw2 = node.createrawtransaction( | ||||
[{'txid': txid1, 'vout': 0}], [{address: 0.999}]) | [{'txid': txid1, 'vout': 0}], [{address: 999000}]) | ||||
signed_raw2 = node.signrawtransactionwithwallet(raw2)['hex'] | signed_raw2 = node.signrawtransactionwithwallet(raw2)['hex'] | ||||
txid2 = node.sendrawtransaction(signed_raw2) | txid2 = node.sendrawtransaction(signed_raw2) | ||||
# Reversed CTOR | # Reversed CTOR | ||||
txids = sorted([txid1, txid2], reverse=True) | txids = sorted([txid1, txid2], reverse=True) | ||||
assert_raises_rpc_error(-25, | assert_raises_rpc_error(-25, | ||||
'TestBlockValidity failed: tx-ordering', | 'TestBlockValidity failed: tx-ordering', | ||||
node.generateblock, | node.generateblock, | ||||
address, | address, | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |