mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-11 03:53:22 +02:00
scripted-diff: Use generate* from TestFramework
-BEGIN VERIFY SCRIPT- sed --regexp-extended -i \ 's/((self\.)?(nodes\[[^]]+\]|[a-z_]*(wallet|node)[0-9a-z_]*))\.(generate(|toaddress|block|todescriptor)(\(|, ))/self.\5\1, /g' \ $(git grep -l generate ./test | grep -v 'test_framework/' | grep -v 'feature_rbf') -END VERIFY SCRIPT-
This commit is contained in:
@@ -24,13 +24,13 @@ class GenerateBlockTest(BitcoinTestFramework):
|
||||
|
||||
self.log.info('Generate an empty block to address')
|
||||
address = node.getnewaddress()
|
||||
hash = node.generateblock(output=address, transactions=[])['hash']
|
||||
hash = self.generateblock(node, output=address, transactions=[])['hash']
|
||||
block = node.getblock(blockhash=hash, verbose=2)
|
||||
assert_equal(len(block['tx']), 1)
|
||||
assert_equal(block['tx'][0]['vout'][0]['scriptPubKey']['address'], address)
|
||||
|
||||
self.log.info('Generate an empty block to a descriptor')
|
||||
hash = node.generateblock('addr(' + address + ')', [])['hash']
|
||||
hash = self.generateblock(node, 'addr(' + address + ')', [])['hash']
|
||||
block = node.getblock(blockhash=hash, verbosity=2)
|
||||
assert_equal(len(block['tx']), 1)
|
||||
assert_equal(block['tx'][0]['vout'][0]['scriptPubKey']['address'], address)
|
||||
@@ -38,7 +38,7 @@ class GenerateBlockTest(BitcoinTestFramework):
|
||||
self.log.info('Generate an empty block to a combo descriptor with compressed pubkey')
|
||||
combo_key = '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'
|
||||
combo_address = 'bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7kygt080'
|
||||
hash = node.generateblock('combo(' + combo_key + ')', [])['hash']
|
||||
hash = self.generateblock(node, 'combo(' + combo_key + ')', [])['hash']
|
||||
block = node.getblock(hash, 2)
|
||||
assert_equal(len(block['tx']), 1)
|
||||
assert_equal(block['tx'][0]['vout'][0]['scriptPubKey']['address'], combo_address)
|
||||
@@ -46,13 +46,13 @@ class GenerateBlockTest(BitcoinTestFramework):
|
||||
self.log.info('Generate an empty block to a combo descriptor with uncompressed pubkey')
|
||||
combo_key = '0408ef68c46d20596cc3f6ddf7c8794f71913add807f1dc55949fa805d764d191c0b7ce6894c126fce0babc6663042f3dde9b0cf76467ea315514e5a6731149c67'
|
||||
combo_address = 'mkc9STceoCcjoXEXe6cm66iJbmjM6zR9B2'
|
||||
hash = node.generateblock('combo(' + combo_key + ')', [])['hash']
|
||||
hash = self.generateblock(node, 'combo(' + combo_key + ')', [])['hash']
|
||||
block = node.getblock(hash, 2)
|
||||
assert_equal(len(block['tx']), 1)
|
||||
assert_equal(block['tx'][0]['vout'][0]['scriptPubKey']['address'], combo_address)
|
||||
|
||||
# Generate 110 blocks to spend
|
||||
node.generatetoaddress(110, address)
|
||||
self.generatetoaddress(node, 110, address)
|
||||
|
||||
# Generate some extra mempool transactions to verify they don't get mined
|
||||
for _ in range(10):
|
||||
@@ -60,7 +60,7 @@ class GenerateBlockTest(BitcoinTestFramework):
|
||||
|
||||
self.log.info('Generate block with txid')
|
||||
txid = node.sendtoaddress(address, 1)
|
||||
hash = node.generateblock(address, [txid])['hash']
|
||||
hash = self.generateblock(node, address, [txid])['hash']
|
||||
block = node.getblock(hash, 1)
|
||||
assert_equal(len(block['tx']), 2)
|
||||
assert_equal(block['tx'][1], txid)
|
||||
@@ -69,7 +69,7 @@ class GenerateBlockTest(BitcoinTestFramework):
|
||||
utxos = node.listunspent(addresses=[address])
|
||||
raw = node.createrawtransaction([{'txid':utxos[0]['txid'], 'vout':utxos[0]['vout']}],[{address:1}])
|
||||
signed_raw = node.signrawtransactionwithwallet(raw)['hex']
|
||||
hash = node.generateblock(address, [signed_raw])['hash']
|
||||
hash = self.generateblock(node, address, [signed_raw])['hash']
|
||||
block = node.getblock(hash, 1)
|
||||
assert_equal(len(block['tx']), 2)
|
||||
txid = block['tx'][1]
|
||||
@@ -81,26 +81,26 @@ class GenerateBlockTest(BitcoinTestFramework):
|
||||
txid1 = node.sendrawtransaction(signed_raw1)
|
||||
raw2 = node.createrawtransaction([{'txid':txid1, 'vout':0}],[{address:0.999}])
|
||||
signed_raw2 = node.signrawtransactionwithwallet(raw2)['hex']
|
||||
assert_raises_rpc_error(-25, 'TestBlockValidity failed: bad-txns-inputs-missingorspent', node.generateblock, address, [signed_raw2, txid1])
|
||||
assert_raises_rpc_error(-25, 'TestBlockValidity failed: bad-txns-inputs-missingorspent', self.generateblock, node, address, [signed_raw2, txid1])
|
||||
|
||||
self.log.info('Fail to generate block with txid not in mempool')
|
||||
missing_txid = '0000000000000000000000000000000000000000000000000000000000000000'
|
||||
assert_raises_rpc_error(-5, 'Transaction ' + missing_txid + ' not in mempool.', node.generateblock, address, [missing_txid])
|
||||
assert_raises_rpc_error(-5, 'Transaction ' + missing_txid + ' not in mempool.', self.generateblock, node, address, [missing_txid])
|
||||
|
||||
self.log.info('Fail to generate block with invalid raw tx')
|
||||
invalid_raw_tx = '0000'
|
||||
assert_raises_rpc_error(-22, 'Transaction decode failed for ' + invalid_raw_tx, node.generateblock, address, [invalid_raw_tx])
|
||||
assert_raises_rpc_error(-22, 'Transaction decode failed for ' + invalid_raw_tx, self.generateblock, node, address, [invalid_raw_tx])
|
||||
|
||||
self.log.info('Fail to generate block with invalid address/descriptor')
|
||||
assert_raises_rpc_error(-5, 'Invalid address or descriptor', node.generateblock, '1234', [])
|
||||
assert_raises_rpc_error(-5, 'Invalid address or descriptor', self.generateblock, node, '1234', [])
|
||||
|
||||
self.log.info('Fail to generate block with a ranged descriptor')
|
||||
ranged_descriptor = 'pkh(tpubD6NzVbkrYhZ4XgiXtGrdW5XDAPFCL9h7we1vwNCpn8tGbBcgfVYjXyhWo4E1xkh56hjod1RhGjxbaTLV3X4FyWuejifB9jusQ46QzG87VKp/0/*)'
|
||||
assert_raises_rpc_error(-8, 'Ranged descriptor not accepted. Maybe pass through deriveaddresses first?', node.generateblock, ranged_descriptor, [])
|
||||
assert_raises_rpc_error(-8, 'Ranged descriptor not accepted. Maybe pass through deriveaddresses first?', self.generateblock, node, ranged_descriptor, [])
|
||||
|
||||
self.log.info('Fail to generate block with a descriptor missing a private key')
|
||||
child_descriptor = 'pkh(tpubD6NzVbkrYhZ4XgiXtGrdW5XDAPFCL9h7we1vwNCpn8tGbBcgfVYjXyhWo4E1xkh56hjod1RhGjxbaTLV3X4FyWuejifB9jusQ46QzG87VKp/0\'/0)'
|
||||
assert_raises_rpc_error(-5, 'Cannot derive script without private keys', node.generateblock, child_descriptor, [])
|
||||
assert_raises_rpc_error(-5, 'Cannot derive script without private keys', self.generateblock, node, child_descriptor, [])
|
||||
|
||||
if __name__ == '__main__':
|
||||
GenerateBlockTest().main()
|
||||
|
Reference in New Issue
Block a user