11#[ cfg( test) ]
22mod tests {
3- use bitcoin:: consensus:: deserialize;
43 use bitcoinkernel:: {
54 prelude:: * , verify, Block , BlockHash , BlockSpentOutputs , BlockTreeEntry ,
65 BlockValidationStateRef , ChainParams , ChainType , ChainstateManager ,
@@ -27,9 +26,9 @@ mod tests {
2726 static mut GLOBAL_LOG_CALLBACK_HOLDER : Option < Logger > = None ;
2827
2928 fn setup_logging ( ) {
30- let mut builder = env_logger:: Builder :: from_default_env ( ) ;
31- builder . filter ( None , log :: LevelFilter :: Debug ) . init ( ) ;
32-
29+ let _ = env_logger:: Builder :: from_default_env ( )
30+ . is_test ( true )
31+ . try_init ( ) ;
3332 unsafe { GLOBAL_LOG_CALLBACK_HOLDER = Some ( Logger :: new ( TestLog { } ) . unwrap ( ) ) } ;
3433 }
3534
@@ -187,85 +186,6 @@ mod tests {
187186 }
188187 }
189188
190- #[ test]
191- fn test_scan_tx ( ) {
192- #[ allow( dead_code) ]
193- #[ derive( Debug ) ]
194- struct Input {
195- height : u32 ,
196- prevout : Vec < u8 > ,
197- script_sig : Vec < u8 > ,
198- witness : Vec < Vec < u8 > > ,
199- }
200-
201- #[ derive( Debug ) ]
202- struct ScanTxHelper {
203- ins : Vec < Input > ,
204- #[ allow( dead_code) ]
205- outs : Vec < Vec < u8 > > ,
206- }
207-
208- let ( context, data_dir) = testing_setup ( ) ;
209- let chainman = setup_chainman_with_blocks ( & context, & data_dir) . unwrap ( ) ;
210-
211- let active_chain = chainman. active_chain ( ) ;
212-
213- for ( height, block_index) in active_chain. iter ( ) . enumerate ( ) {
214- assert_eq ! ( height, block_index. height( ) . try_into( ) . unwrap( ) ) ;
215- }
216-
217- let block_index_tip = active_chain. tip ( ) ;
218-
219- let raw_block_tip: Vec < u8 > = chainman
220- . read_block_data ( & block_index_tip)
221- . unwrap ( )
222- . consensus_encode ( )
223- . unwrap ( ) ;
224-
225- let spent_outputs_tip = chainman. read_spent_outputs ( & block_index_tip) . unwrap ( ) ;
226- let block_tip: bitcoin:: Block = deserialize ( & raw_block_tip) . unwrap ( ) ;
227- // Should be the same size minus the coinbase transaction
228- assert_eq ! ( block_tip. txdata. len( ) - 1 , spent_outputs_tip. count( ) ) ;
229-
230- let block_index_tip_prev = block_index_tip. prev ( ) . unwrap ( ) ;
231- let raw_block: Vec < u8 > = chainman
232- . read_block_data ( & block_index_tip_prev)
233- . unwrap ( )
234- . try_into ( )
235- . unwrap ( ) ;
236-
237- let spent_outputs = chainman. read_spent_outputs ( & block_index_tip_prev) . unwrap ( ) ;
238- let block: bitcoin:: Block = deserialize ( & raw_block) . unwrap ( ) ;
239- // Should be the same size minus the coinbase transaction
240- assert_eq ! ( block. txdata. len( ) - 1 , spent_outputs. count( ) ) ;
241-
242- for i in 0 ..( block. txdata . len ( ) - 1 ) {
243- let tx_spent_outputs = spent_outputs. transaction_spent_outputs ( i) . unwrap ( ) ;
244- let coins_spent_count = tx_spent_outputs. count ( ) ;
245- let transaction_input_size = block. txdata [ i + 1 ] . input . len ( ) ;
246-
247- assert_eq ! ( transaction_input_size, coins_spent_count) ;
248- let mut helper = ScanTxHelper {
249- ins : vec ! [ ] ,
250- outs : block. txdata [ i + 1 ]
251- . output
252- . iter ( )
253- . map ( |output| output. script_pubkey . to_bytes ( ) )
254- . collect ( ) ,
255- } ;
256- for j in 0 ..transaction_input_size {
257- let coin = tx_spent_outputs. coin ( j) . unwrap ( ) ;
258- helper. ins . push ( Input {
259- height : coin. confirmation_height ( ) ,
260- prevout : coin. output ( ) . script_pubkey ( ) . to_bytes ( ) ,
261- script_sig : block. txdata [ i + 1 ] . input [ j] . script_sig . to_bytes ( ) ,
262- witness : block. txdata [ i + 1 ] . input [ j] . witness . to_vec ( ) ,
263- } ) ;
264- }
265- println ! ( "helper: {:?}" , helper) ;
266- }
267- }
268-
269189 #[ test]
270190 fn test_process_data ( ) {
271191 let ( context, data_dir) = testing_setup ( ) ;
0 commit comments