@@ -41,8 +41,8 @@ use crate::{
4141 tracing:: trace,
4242 weights:: WeightInfo ,
4343 AccountInfo , AccountInfoOf , BalanceWithDust , Code , Combinator , Config , ContractInfo ,
44- DeletionQueueCounter , Error , ExecConfig , HoldReason , Origin , Pallet , PristineCode ,
45- StorageDeposit , H160 ,
44+ DebugSettings , DeletionQueueCounter , Error , ExecConfig , HoldReason , Origin , Pallet ,
45+ PristineCode , StorageDeposit , H160 ,
4646} ;
4747use assert_matches:: assert_matches;
4848use codec:: Encode ;
@@ -4973,7 +4973,7 @@ fn eip3607_reject_tx_from_contract_or_precompile() {
49734973 assert_err ! ( result, DispatchError :: BadOrigin ) ;
49744974
49754975 let result = builder:: eth_call ( BOB_ADDR )
4976- . origin ( RuntimeOrigin :: signed ( origin. clone ( ) ) )
4976+ . origin ( Origin :: EthTransaction ( origin. clone ( ) ) . into ( ) )
49774977 . build ( ) ;
49784978 assert_err ! ( result, DispatchError :: BadOrigin ) ;
49794979
@@ -4983,7 +4983,7 @@ fn eip3607_reject_tx_from_contract_or_precompile() {
49834983 assert_err ! ( result, DispatchError :: BadOrigin ) ;
49844984
49854985 let result = builder:: eth_instantiate_with_code ( Default :: default ( ) )
4986- . origin ( RuntimeOrigin :: signed ( origin. clone ( ) ) )
4986+ . origin ( Origin :: EthTransaction ( origin. clone ( ) ) . into ( ) )
49874987 . build ( ) ;
49884988 assert_err ! ( result, DispatchError :: BadOrigin ) ;
49894989
@@ -5011,6 +5011,77 @@ fn eip3607_reject_tx_from_contract_or_precompile() {
50115011 } ) ;
50125012}
50135013
5014+ #[ test]
5015+ fn eip3607_allow_tx_from_contract_or_precompile_if_debug_setting_configured ( ) {
5016+ let ( binary, code_hash) = compile_module ( "dummy" ) . unwrap ( ) ;
5017+
5018+ let genesis_config = GenesisConfig :: < Test > {
5019+ debug_settings : Some ( DebugSettings :: new ( false , true ) ) ,
5020+ ..Default :: default ( )
5021+ } ;
5022+
5023+ ExtBuilder :: default ( )
5024+ . genesis_config ( Some ( genesis_config) )
5025+ . existential_deposit ( 200 )
5026+ . build ( )
5027+ . execute_with ( || {
5028+ DebugFlag :: set ( true ) ;
5029+
5030+ let _ = <Test as Config >:: Currency :: set_balance ( & ALICE , 1_000_000 ) ;
5031+
5032+ // the origins from which we try to call a dispatchable
5033+ let Contract { addr : contract_addr, .. } =
5034+ builder:: bare_instantiate ( Code :: Upload ( binary. clone ( ) ) ) . build_and_unwrap_contract ( ) ;
5035+
5036+ assert ! ( <AccountInfo <Test >>:: is_contract( & contract_addr) ) ;
5037+
5038+ let blake2_addr = H160 :: from_low_u64_be ( 9 ) ;
5039+ let system_addr = H160 :: from_low_u64_be ( 0x900 ) ;
5040+ let addresses = [ contract_addr, blake2_addr, system_addr] ;
5041+
5042+ for address in addresses {
5043+ let origin = <Test as Config >:: AddressMapper :: to_fallback_account_id ( & address) ;
5044+
5045+ let _ = <Test as Config >:: Currency :: set_balance ( & origin, 10_000_000_000_000 ) ;
5046+
5047+ let result =
5048+ builder:: call ( BOB_ADDR ) . origin ( RuntimeOrigin :: signed ( origin. clone ( ) ) ) . build ( ) ;
5049+ assert_ok ! ( result) ;
5050+
5051+ let result = builder:: eth_call ( BOB_ADDR )
5052+ . origin ( Origin :: EthTransaction ( origin. clone ( ) ) . into ( ) )
5053+ . build ( ) ;
5054+ assert_ok ! ( result) ;
5055+
5056+ let result = builder:: instantiate ( code_hash)
5057+ . origin ( RuntimeOrigin :: signed ( origin. clone ( ) ) )
5058+ . build ( ) ;
5059+ assert_ok ! ( result) ;
5060+
5061+ let result = builder:: eth_instantiate_with_code ( binary. clone ( ) )
5062+ . origin ( Origin :: EthTransaction ( origin. clone ( ) ) . into ( ) )
5063+ . build ( ) ;
5064+ assert_ok ! ( result) ;
5065+
5066+ let result = <Pallet < Test > >:: dispatch_as_fallback_account (
5067+ RuntimeOrigin :: signed ( origin. clone ( ) ) ,
5068+ Box :: new ( RuntimeCall :: Balances ( pallet_balances:: Call :: transfer_all {
5069+ dest : EVE ,
5070+ keep_alive : false ,
5071+ } ) ) ,
5072+ ) ;
5073+ assert_ok ! ( result) ;
5074+
5075+ let result = <Pallet < Test > >:: upload_code (
5076+ RuntimeOrigin :: signed ( origin. clone ( ) ) ,
5077+ binary. clone ( ) ,
5078+ <BalanceOf < Test > >:: MAX ,
5079+ ) ;
5080+ assert_ok ! ( result) ;
5081+ }
5082+ } ) ;
5083+ }
5084+
50145085#[ test]
50155086fn get_set_storage_key_works ( ) {
50165087 let ( code, _code_hash) = compile_module ( "dummy" ) . unwrap ( ) ;
0 commit comments