mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-04 13:55:23 -05:00
test: run rpc-generateblock.py even with wallet disabled
This commit is contained in:
parent
f63bf05e73
commit
1e86ff7941
1 changed files with 14 additions and 20 deletions
|
@ -6,6 +6,7 @@
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
|
from test_framework.wallet import MiniWallet
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
assert_equal,
|
assert_equal,
|
||||||
assert_raises_rpc_error,
|
assert_raises_rpc_error,
|
||||||
|
@ -16,14 +17,13 @@ class GenerateBlockTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.num_nodes = 1
|
self.num_nodes = 1
|
||||||
|
|
||||||
def skip_test_if_missing_module(self):
|
|
||||||
self.skip_if_no_wallet()
|
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
node = self.nodes[0]
|
node = self.nodes[0]
|
||||||
|
miniwallet = MiniWallet(node)
|
||||||
|
miniwallet.rescan_utxos()
|
||||||
|
|
||||||
self.log.info('Generate an empty block to address')
|
self.log.info('Generate an empty block to address')
|
||||||
address = node.getnewaddress()
|
address = miniwallet.get_address()
|
||||||
hash = self.generateblock(node, output=address, transactions=[])['hash']
|
hash = self.generateblock(node, output=address, transactions=[])['hash']
|
||||||
block = node.getblock(blockhash=hash, verbose=2)
|
block = node.getblock(blockhash=hash, verbose=2)
|
||||||
assert_equal(len(block['tx']), 1)
|
assert_equal(len(block['tx']), 1)
|
||||||
|
@ -51,37 +51,31 @@ class GenerateBlockTest(BitcoinTestFramework):
|
||||||
assert_equal(len(block['tx']), 1)
|
assert_equal(len(block['tx']), 1)
|
||||||
assert_equal(block['tx'][0]['vout'][0]['scriptPubKey']['address'], combo_address)
|
assert_equal(block['tx'][0]['vout'][0]['scriptPubKey']['address'], combo_address)
|
||||||
|
|
||||||
# Generate 110 blocks to spend
|
|
||||||
self.generatetoaddress(node, 110, address)
|
|
||||||
|
|
||||||
# Generate some extra mempool transactions to verify they don't get mined
|
# Generate some extra mempool transactions to verify they don't get mined
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
node.sendtoaddress(address, 0.001)
|
miniwallet.send_self_transfer(from_node=node)
|
||||||
|
|
||||||
self.log.info('Generate block with txid')
|
self.log.info('Generate block with txid')
|
||||||
txid = node.sendtoaddress(address, 1)
|
txid = miniwallet.send_self_transfer(from_node=node)['txid']
|
||||||
hash = self.generateblock(node, address, [txid])['hash']
|
hash = self.generateblock(node, 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])
|
rawtx = miniwallet.create_self_transfer(from_node=node)['hex']
|
||||||
raw = node.createrawtransaction([{'txid':utxos[0]['txid'], 'vout':utxos[0]['vout']}],[{address:1}])
|
hash = self.generateblock(node, address, [rawtx])['hash']
|
||||||
signed_raw = node.signrawtransactionwithwallet(raw)['hex']
|
|
||||||
hash = self.generateblock(node, 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.getrawtransaction(txid=txid, verbose=False, blockhash=hash), rawtx)
|
||||||
|
|
||||||
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([{'txid':txid, 'vout':0}],[{address:0.9999}])
|
txid1 = miniwallet.send_self_transfer(from_node=node)['txid']
|
||||||
signed_raw1 = node.signrawtransactionwithwallet(raw1)['hex']
|
utxo1 = miniwallet.get_utxo(txid=txid1)
|
||||||
txid1 = node.sendrawtransaction(signed_raw1)
|
rawtx2 = miniwallet.create_self_transfer(from_node=node, utxo_to_spend=utxo1)['hex']
|
||||||
raw2 = node.createrawtransaction([{'txid':txid1, 'vout':0}],[{address:0.999}])
|
assert_raises_rpc_error(-25, 'TestBlockValidity failed: bad-txns-inputs-missingorspent', self.generateblock, node, address, [rawtx2, txid1])
|
||||||
signed_raw2 = node.signrawtransactionwithwallet(raw2)['hex']
|
|
||||||
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')
|
self.log.info('Fail to generate block with txid not in mempool')
|
||||||
missing_txid = '0000000000000000000000000000000000000000000000000000000000000000'
|
missing_txid = '0000000000000000000000000000000000000000000000000000000000000000'
|
||||||
|
|
Loading…
Add table
Reference in a new issue