@@ -3101,3 +3101,98 @@ contract FactoryScript is Script {
31013101 . expect( "no Counter contract" ) ;
31023102 assert_eq!( counter_contract. contract_name, Some ( "Counter" . to_string( ) ) ) ;
31033103} ) ;
3104+
3105+ // <https://github.com/foundry-rs/foundry/issues/11213>
3106+ forgetest_async ! ( call_to_non_contract_address_does_not_panic, |prj, cmd| {
3107+ foundry_test_utils:: util:: initialize( prj. root( ) ) ;
3108+
3109+ let endpoint = rpc:: next_http_archive_rpc_url( ) ;
3110+
3111+ prj. add_source(
3112+ "Counter.sol" ,
3113+ r#"
3114+ contract Counter {
3115+ uint256 public number;
3116+ function setNumber(uint256 newNumber) public {
3117+ number = newNumber;
3118+ }
3119+ function increment() public {
3120+ number++;
3121+ }
3122+ }
3123+ "# ,
3124+ )
3125+ . unwrap( ) ;
3126+
3127+ let deploy_script = prj
3128+ . add_script(
3129+ "Counter.s.sol" ,
3130+ & r#"
3131+ import "forge-std/Script.sol";
3132+ import {Counter} from "../src/Counter.sol";
3133+ contract CounterScript is Script {
3134+ Counter public counter;
3135+ function setUp() public {}
3136+ function run() public {
3137+ vm.createSelectFork("<url>");
3138+ vm.startBroadcast();
3139+ counter = new Counter();
3140+ vm.stopBroadcast();
3141+ vm.createSelectFork("<url>");
3142+ vm.startBroadcast();
3143+ counter.increment();
3144+ vm.stopBroadcast();
3145+ }
3146+ }
3147+ "#
3148+ . replace( "<url>" , & endpoint) ,
3149+ )
3150+ . unwrap( ) ;
3151+
3152+ let ( _api, handle) = spawn( NodeConfig :: test( ) ) . await ;
3153+ cmd. args( [
3154+ "script" ,
3155+ & deploy_script. display( ) . to_string( ) ,
3156+ "--root" ,
3157+ prj. root( ) . to_str( ) . unwrap( ) ,
3158+ "--fork-url" ,
3159+ & handle. http_endpoint( ) ,
3160+ "--slow" ,
3161+ "--broadcast" ,
3162+ "--private-key" ,
3163+ "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" ,
3164+ ] )
3165+ . assert_failure( )
3166+ . stdout_eq( str ![ [ r#"
3167+ [COMPILING_FILES] with [SOLC_VERSION]
3168+ [SOLC_VERSION] [ELAPSED]
3169+ Compiler run successful!
3170+ Traces:
3171+ [..] → new CounterScript@[..]
3172+ └─ ← [Return] 2200 bytes of code
3173+
3174+ [..] CounterScript::setUp()
3175+ └─ ← [Stop]
3176+
3177+ [..] CounterScript::run()
3178+ ├─ [..] VM::createSelectFork("<rpc url>")
3179+ │ └─ ← [Return] 1
3180+ ├─ [..] VM::startBroadcast()
3181+ │ └─ ← [Return]
3182+ ├─ [..] → new Counter@[..]
3183+ │ └─ ← [Return] 481 bytes of code
3184+ ├─ [..] VM::stopBroadcast()
3185+ │ └─ ← [Return]
3186+ ├─ [..] VM::createSelectFork("<rpc url>")
3187+ │ └─ ← [Return] 2
3188+ ├─ [..] VM::startBroadcast()
3189+ │ └─ ← [Return]
3190+ └─ ← [Revert] call to non-contract address [..]
3191+
3192+
3193+
3194+ "# ] ] )
3195+ . stderr_eq( str ![ [ r#"
3196+ Error: script failed: call to non-contract address [..]
3197+ "# ] ] ) ;
3198+ } ) ;
0 commit comments