66'''
77
88from test_framework .test_framework import BitcoinTestFramework
9+ from test_framework .wallet import MiniWallet
910from test_framework .util import (
1011 assert_equal ,
1112 assert_raises_rpc_error ,
@@ -16,14 +17,13 @@ class GenerateBlockTest(BitcoinTestFramework):
1617 def set_test_params (self ):
1718 self .num_nodes = 1
1819
19- def skip_test_if_missing_module (self ):
20- self .skip_if_no_wallet ()
21-
2220 def run_test (self ):
2321 node = self .nodes [0 ]
22+ miniwallet = MiniWallet (node )
23+ miniwallet .rescan_utxos ()
2424
2525 self .log .info ('Generate an empty block to address' )
26- address = node . getnewaddress ()
26+ address = miniwallet . get_address ()
2727 hash = self .generateblock (node , output = address , transactions = [])['hash' ]
2828 block = node .getblock (blockhash = hash , verbose = 2 )
2929 assert_equal (len (block ['tx' ]), 1 )
@@ -51,37 +51,31 @@ def run_test(self):
5151 assert_equal (len (block ['tx' ]), 1 )
5252 assert_equal (block ['tx' ][0 ]['vout' ][0 ]['scriptPubKey' ]['address' ], combo_address )
5353
54- # Generate 110 blocks to spend
55- self .generatetoaddress (node , 110 , address )
56-
5754 # Generate some extra mempool transactions to verify they don't get mined
5855 for _ in range (10 ):
59- node . sendtoaddress ( address , 0.001 )
56+ miniwallet . send_self_transfer ( from_node = node )
6057
6158 self .log .info ('Generate block with txid' )
62- txid = node . sendtoaddress ( address , 1 )
59+ txid = miniwallet . send_self_transfer ( from_node = node )[ 'txid' ]
6360 hash = self .generateblock (node , address , [txid ])['hash' ]
6461 block = node .getblock (hash , 1 )
6562 assert_equal (len (block ['tx' ]), 2 )
6663 assert_equal (block ['tx' ][1 ], txid )
6764
6865 self .log .info ('Generate block with raw tx' )
69- utxos = node .listunspent (addresses = [address ])
70- raw = node .createrawtransaction ([{'txid' :utxos [0 ]['txid' ], 'vout' :utxos [0 ]['vout' ]}],[{address :1 }])
71- signed_raw = node .signrawtransactionwithwallet (raw )['hex' ]
72- hash = self .generateblock (node , address , [signed_raw ])['hash' ]
66+ rawtx = miniwallet .create_self_transfer (from_node = node )['hex' ]
67+ hash = self .generateblock (node , address , [rawtx ])['hash' ]
68+
7369 block = node .getblock (hash , 1 )
7470 assert_equal (len (block ['tx' ]), 2 )
7571 txid = block ['tx' ][1 ]
76- assert_equal (node .gettransaction (txid )[ 'hex' ], signed_raw )
72+ assert_equal (node .getrawtransaction (txid = txid , verbose = False , blockhash = hash ), rawtx )
7773
7874 self .log .info ('Fail to generate block with out of order txs' )
79- raw1 = node .createrawtransaction ([{'txid' :txid , 'vout' :0 }],[{address :0.9999 }])
80- signed_raw1 = node .signrawtransactionwithwallet (raw1 )['hex' ]
81- txid1 = node .sendrawtransaction (signed_raw1 )
82- raw2 = node .createrawtransaction ([{'txid' :txid1 , 'vout' :0 }],[{address :0.999 }])
83- signed_raw2 = node .signrawtransactionwithwallet (raw2 )['hex' ]
84- assert_raises_rpc_error (- 25 , 'TestBlockValidity failed: bad-txns-inputs-missingorspent' , self .generateblock , node , address , [signed_raw2 , txid1 ])
75+ txid1 = miniwallet .send_self_transfer (from_node = node )['txid' ]
76+ utxo1 = miniwallet .get_utxo (txid = txid1 )
77+ rawtx2 = miniwallet .create_self_transfer (from_node = node , utxo_to_spend = utxo1 )['hex' ]
78+ assert_raises_rpc_error (- 25 , 'TestBlockValidity failed: bad-txns-inputs-missingorspent' , self .generateblock , node , address , [rawtx2 , txid1 ])
8579
8680 self .log .info ('Fail to generate block with txid not in mempool' )
8781 missing_txid = '0000000000000000000000000000000000000000000000000000000000000000'
0 commit comments