6
6
'''
7
7
8
8
from test_framework .test_framework import BitcoinTestFramework
9
+ from test_framework .wallet import MiniWallet
9
10
from test_framework .util import (
10
11
assert_equal ,
11
12
assert_raises_rpc_error ,
@@ -16,14 +17,13 @@ class GenerateBlockTest(BitcoinTestFramework):
16
17
def set_test_params (self ):
17
18
self .num_nodes = 1
18
19
19
- def skip_test_if_missing_module (self ):
20
- self .skip_if_no_wallet ()
21
-
22
20
def run_test (self ):
23
21
node = self .nodes [0 ]
22
+ miniwallet = MiniWallet (node )
23
+ miniwallet .rescan_utxos ()
24
24
25
25
self .log .info ('Generate an empty block to address' )
26
- address = node . getnewaddress ()
26
+ address = miniwallet . get_address ()
27
27
hash = self .generateblock (node , output = address , transactions = [])['hash' ]
28
28
block = node .getblock (blockhash = hash , verbose = 2 )
29
29
assert_equal (len (block ['tx' ]), 1 )
@@ -51,37 +51,31 @@ def run_test(self):
51
51
assert_equal (len (block ['tx' ]), 1 )
52
52
assert_equal (block ['tx' ][0 ]['vout' ][0 ]['scriptPubKey' ]['address' ], combo_address )
53
53
54
- # Generate 110 blocks to spend
55
- self .generatetoaddress (node , 110 , address )
56
-
57
54
# Generate some extra mempool transactions to verify they don't get mined
58
55
for _ in range (10 ):
59
- node . sendtoaddress ( address , 0.001 )
56
+ miniwallet . send_self_transfer ( from_node = node )
60
57
61
58
self .log .info ('Generate block with txid' )
62
- txid = node . sendtoaddress ( address , 1 )
59
+ txid = miniwallet . send_self_transfer ( from_node = node )[ 'txid' ]
63
60
hash = self .generateblock (node , address , [txid ])['hash' ]
64
61
block = node .getblock (hash , 1 )
65
62
assert_equal (len (block ['tx' ]), 2 )
66
63
assert_equal (block ['tx' ][1 ], txid )
67
64
68
65
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
+
73
69
block = node .getblock (hash , 1 )
74
70
assert_equal (len (block ['tx' ]), 2 )
75
71
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 )
77
73
78
74
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 ])
85
79
86
80
self .log .info ('Fail to generate block with txid not in mempool' )
87
81
missing_txid = '0000000000000000000000000000000000000000000000000000000000000000'
0 commit comments