18
18
)
19
19
from test_framework .messages import (
20
20
COIN ,
21
- COutPoint ,
22
- CTransaction ,
23
- CTxIn ,
24
21
CTxOut ,
25
22
)
26
23
from test_framework .script import (
33
30
assert_equal ,
34
31
assert_raises_rpc_error ,
35
32
)
33
+ from test_framework .wallet import (
34
+ MiniWallet ,
35
+ getnewdestination ,
36
+ )
37
+
36
38
37
39
class CoinStatsIndexTest (BitcoinTestFramework ):
38
40
def set_test_params (self ):
39
41
self .setup_clean_chain = True
40
42
self .num_nodes = 2
41
43
self .supports_cli = False
42
44
self .extra_args = [
43
- # Explicitly set the output type in order to have consistent tx vsize / fees
44
- # for both legacy and descriptor wallets (disables the change address type detection algorithm)
45
- ["-addresstype=bech32" , "-changetype=bech32" ],
45
+ [],
46
46
["-coinstatsindex" ]
47
47
]
48
48
49
- def skip_test_if_missing_module (self ):
50
- self .skip_if_no_wallet ()
51
-
52
49
def run_test (self ):
50
+ self .wallet = MiniWallet (self .nodes [0 ])
53
51
self ._test_coin_stats_index ()
54
52
self ._test_use_index_option ()
55
53
self ._test_reorg_index ()
@@ -69,9 +67,8 @@ def _test_coin_stats_index(self):
69
67
index_hash_options = ['none' , 'muhash' ]
70
68
71
69
# Generate a normal transaction and mine it
72
- self .generate (node , COINBASE_MATURITY + 1 )
73
- address = self .nodes [0 ].get_deterministic_priv_key ().address
74
- node .sendtoaddress (address = address , amount = 10 , subtractfeefromamount = True )
70
+ self .generate (self .wallet , COINBASE_MATURITY + 1 )
71
+ self .wallet .send_self_transfer (from_node = node )
75
72
self .generate (node , 1 )
76
73
77
74
self .log .info ("Test that gettxoutsetinfo() output is consistent with or without coinstatsindex option" )
@@ -136,36 +133,31 @@ def _test_coin_stats_index(self):
136
133
assert_equal (res5 ['block_info' ], {
137
134
'unspendable' : 0 ,
138
135
'prevout_spent' : 50 ,
139
- 'new_outputs_ex_coinbase' : Decimal ('49.99995560 ' ),
140
- 'coinbase' : Decimal ('50.00004440 ' ),
136
+ 'new_outputs_ex_coinbase' : Decimal ('49.99968800 ' ),
137
+ 'coinbase' : Decimal ('50.00031200 ' ),
141
138
'unspendables' : {
142
139
'genesis_block' : 0 ,
143
140
'bip30' : 0 ,
144
141
'scripts' : 0 ,
145
- 'unclaimed_rewards' : 0
142
+ 'unclaimed_rewards' : 0 ,
146
143
}
147
144
})
148
145
self .block_sanity_check (res5 ['block_info' ])
149
146
150
147
# Generate and send a normal tx with two outputs
151
- tx1_inputs = []
152
- tx1_outputs = {self .nodes [0 ].getnewaddress (): 21 , self .nodes [0 ].getnewaddress (): 42 }
153
- raw_tx1 = self .nodes [0 ].createrawtransaction (tx1_inputs , tx1_outputs )
154
- funded_tx1 = self .nodes [0 ].fundrawtransaction (raw_tx1 )
155
- signed_tx1 = self .nodes [0 ].signrawtransactionwithwallet (funded_tx1 ['hex' ])
156
- tx1_txid = self .nodes [0 ].sendrawtransaction (signed_tx1 ['hex' ])
148
+ tx1_txid , tx1_vout = self .wallet .send_to (
149
+ from_node = node ,
150
+ scriptPubKey = self .wallet .get_scriptPubKey (),
151
+ amount = 21 * COIN ,
152
+ )
157
153
158
154
# Find the right position of the 21 BTC output
159
- tx1_final = self .nodes [0 ].gettransaction (tx1_txid )
160
- for output in tx1_final ['details' ]:
161
- if output ['amount' ] == Decimal ('21.00000000' ) and output ['category' ] == 'receive' :
162
- n = output ['vout' ]
155
+ tx1_out_21 = self .wallet .get_utxo (txid = tx1_txid , vout = tx1_vout )
163
156
164
157
# Generate and send another tx with an OP_RETURN output (which is unspendable)
165
- tx2 = CTransaction ()
166
- tx2 .vin .append (CTxIn (COutPoint (int (tx1_txid , 16 ), n ), b'' ))
167
- tx2 .vout .append (CTxOut (int (Decimal ('20.99' ) * COIN ), CScript ([OP_RETURN ] + [OP_FALSE ]* 30 )))
168
- tx2_hex = self .nodes [0 ].signrawtransactionwithwallet (tx2 .serialize ().hex ())['hex' ]
158
+ tx2 = self .wallet .create_self_transfer (utxo_to_spend = tx1_out_21 )['tx' ]
159
+ tx2 .vout = [CTxOut (int (Decimal ('20.99' ) * COIN ), CScript ([OP_RETURN ] + [OP_FALSE ] * 30 ))]
160
+ tx2_hex = tx2 .serialize ().hex ()
169
161
self .nodes [0 ].sendrawtransaction (tx2_hex )
170
162
171
163
# Include both txs in a block
@@ -177,14 +169,14 @@ def _test_coin_stats_index(self):
177
169
assert_equal (res6 ['total_unspendable_amount' ], Decimal ('70.99000000' ))
178
170
assert_equal (res6 ['block_info' ], {
179
171
'unspendable' : Decimal ('20.99000000' ),
180
- 'prevout_spent' : 111 ,
181
- 'new_outputs_ex_coinbase' : Decimal ('89.99993620 ' ),
182
- 'coinbase' : Decimal ('50.01006380 ' ),
172
+ 'prevout_spent' : 71 ,
173
+ 'new_outputs_ex_coinbase' : Decimal ('49.99999000 ' ),
174
+ 'coinbase' : Decimal ('50.01001000 ' ),
183
175
'unspendables' : {
184
176
'genesis_block' : 0 ,
185
177
'bip30' : 0 ,
186
178
'scripts' : Decimal ('20.99000000' ),
187
- 'unclaimed_rewards' : 0
179
+ 'unclaimed_rewards' : 0 ,
188
180
}
189
181
})
190
182
self .block_sanity_check (res6 ['block_info' ])
@@ -246,7 +238,7 @@ def _test_reorg_index(self):
246
238
247
239
# Generate two block, let the index catch up, then invalidate the blocks
248
240
index_node = self .nodes [1 ]
249
- reorg_blocks = self .generatetoaddress (index_node , 2 , index_node . getnewaddress () )
241
+ reorg_blocks = self .generatetoaddress (index_node , 2 , getnewdestination ()[ 2 ] )
250
242
reorg_block = reorg_blocks [1 ]
251
243
res_invalid = index_node .gettxoutsetinfo ('muhash' )
252
244
index_node .invalidateblock (reorg_blocks [0 ])
0 commit comments