@@ -39,7 +39,9 @@ impl Rpc for LightProgramTest {
3939 where
4040 Self : Sized ,
4141 {
42- unimplemented ! ( )
42+ Err ( RpcError :: CustomError (
43+ "LightProgramTest::new is not supported in program-test context" . into ( ) ,
44+ ) )
4345 }
4446
4547 fn get_payer ( & self ) -> & Keypair {
@@ -146,14 +148,7 @@ impl Rpc for LightProgramTest {
146148
147149 RpcError :: TransactionError ( x. err )
148150 } ) ?;
149- if !self . config . no_logs {
150- #[ cfg( debug_assertions) ]
151- {
152- if std:: env:: var ( "RUST_BACKTRACE" ) . is_ok ( ) {
153- println ! ( "{}" , _res. pretty_logs( ) ) ;
154- }
155- }
156- }
151+ self . maybe_print_logs ( _res. pretty_logs ( ) ) ;
157152 }
158153 Ok ( sig)
159154 }
@@ -164,20 +159,12 @@ impl Rpc for LightProgramTest {
164159 ) -> Result < ( Signature , Slot ) , RpcError > {
165160 let sig = * transaction. signatures . first ( ) . unwrap ( ) ;
166161 let _res = self . context . send_transaction ( transaction) . map_err ( |x| {
167- #[ cfg( not( debug_assertions) ) ]
168- {
169- if self . config . log_failed_tx {
170- println ! ( "{}" , x. meta. pretty_logs( ) ) ;
171- }
162+ if self . config . log_failed_tx {
163+ println ! ( "{}" , x. meta. pretty_logs( ) ) ;
172164 }
173165 RpcError :: TransactionError ( x. err )
174166 } ) ?;
175- #[ cfg( debug_assertions) ]
176- {
177- if std:: env:: var ( "RUST_BACKTRACE" ) . is_ok ( ) {
178- println ! ( "{}" , _res. pretty_logs( ) ) ;
179- }
180- }
167+ self . maybe_print_logs ( _res. pretty_logs ( ) ) ;
181168
182169 let slot = self . context . get_sysvar :: < Clock > ( ) . slot ;
183170 Ok ( ( sig, slot) )
@@ -303,6 +290,12 @@ impl Rpc for LightProgramTest {
303290}
304291
305292impl LightProgramTest {
293+ fn maybe_print_logs ( & self , logs : impl std:: fmt:: Display ) {
294+ if !self . config . no_logs && cfg ! ( debug_assertions) && std:: env:: var ( "RUST_BACKTRACE" ) . is_ok ( )
295+ {
296+ println ! ( "{}" , logs) ;
297+ }
298+ }
306299 #[ cfg( feature = "v2" ) ]
307300 pub fn get_address_tree_v2 ( & self ) -> TreeInfo {
308301 TreeInfo {
@@ -474,20 +467,12 @@ impl LightProgramTest {
474467 } ) ;
475468 // If transaction was successful, execute it.
476469 let _res = self . context . send_transaction ( transaction) . map_err ( |x| {
477- #[ cfg( not( debug_assertions) ) ]
478- {
479- if self . config . log_failed_tx {
480- println ! ( "{}" , x. meta. pretty_logs( ) ) ;
481- }
470+ if self . config . log_failed_tx {
471+ println ! ( "{}" , x. meta. pretty_logs( ) ) ;
482472 }
483473 RpcError :: TransactionError ( x. err )
484474 } ) ?;
485- #[ cfg( debug_assertions) ]
486- {
487- if std:: env:: var ( "RUST_BACKTRACE" ) . is_ok ( ) {
488- println ! ( "{}" , _res. pretty_logs( ) ) ;
489- }
490- }
475+ self . maybe_print_logs ( _res. pretty_logs ( ) ) ;
491476
492477 let slot = self . get_slot ( ) . await ?;
493478 let result = event. map ( |event| ( event, signature, slot) ) ;
0 commit comments