@@ -5662,3 +5662,59 @@ fn test_mem_syscalls_overlap_account_begin_or_end() {
56625662 }
56635663 }
56645664}
5665+
5666+ #[ test]
5667+ #[ cfg( feature = "sbf_rust" ) ]
5668+ fn test_efficient_panic ( ) {
5669+ let GenesisConfigInfo {
5670+ genesis_config,
5671+ mint_keypair,
5672+ ..
5673+ } = create_genesis_config ( 50 ) ;
5674+
5675+ let ( bank, bank_forks) = Bank :: new_with_bank_forks_for_tests ( & genesis_config) ;
5676+ let mut bank_client = BankClient :: new_shared ( bank. clone ( ) ) ;
5677+ let authority_keypair = Keypair :: new ( ) ;
5678+
5679+ let ( bank, program_id) = load_upgradeable_program_and_advance_slot (
5680+ & mut bank_client,
5681+ bank_forks. as_ref ( ) ,
5682+ & mint_keypair,
5683+ & authority_keypair,
5684+ "solana_sbf_rust_efficient_panic" ,
5685+ ) ;
5686+
5687+ bank. freeze ( ) ;
5688+
5689+ let account_metas = vec ! [ AccountMeta :: new( mint_keypair. pubkey( ) , true ) ] ;
5690+ let instruction = Instruction :: new_with_bytes ( program_id, & [ 0 , 2 ] , account_metas. clone ( ) ) ;
5691+
5692+ let blockhash = bank. last_blockhash ( ) ;
5693+ let message = Message :: new ( & [ instruction] , Some ( & mint_keypair. pubkey ( ) ) ) ;
5694+ let transaction = Transaction :: new ( & [ & mint_keypair] , message, blockhash) ;
5695+ let sanitized_tx = RuntimeTransaction :: from_transaction_for_tests ( transaction) ;
5696+
5697+ let result = bank. simulate_transaction ( & sanitized_tx, false ) ;
5698+ assert ! ( result. logs. contains( & format!(
5699+ "Program {} \
5700+ failed: SBF program Panicked in rust/efficient_panic/src/lib.rs at 22:21",
5701+ program_id
5702+ ) ) ) ;
5703+
5704+ let instruction = Instruction :: new_with_bytes ( program_id, & [ 1 , 2 ] , account_metas) ;
5705+
5706+ let blockhash = bank. last_blockhash ( ) ;
5707+ let message = Message :: new ( & [ instruction] , Some ( & mint_keypair. pubkey ( ) ) ) ;
5708+ let transaction = Transaction :: new ( & [ & mint_keypair] , message, blockhash) ;
5709+ let sanitized_tx = RuntimeTransaction :: from_transaction_for_tests ( transaction) ;
5710+
5711+ let result = bank. simulate_transaction ( & sanitized_tx, false ) ;
5712+ assert ! ( result
5713+ . logs
5714+ . contains( & "Program log: called `Option::unwrap()` on a `None` value" . to_string( ) ) ) ;
5715+ assert ! ( result. logs. contains( & format!(
5716+ "Program {} \
5717+ failed: SBF program Panicked in rust/efficient_panic/src/lib.rs at 28:23",
5718+ program_id
5719+ ) ) ) ;
5720+ }
0 commit comments