44pragma solidity ^ 0.8.22 ;
55
66import {Test} from "forge-std-1.9.6/src/Test.sol " ;
7+
8+ import {Create2} from "@openzeppelin-contracts-5.2.0/utils/Create2.sol " ;
9+
710import {InputBox} from "src/inputs/InputBox.sol " ;
811import {IInputBox} from "src/inputs/IInputBox.sol " ;
912import {CanonicalMachine} from "src/common/CanonicalMachine.sol " ;
@@ -14,6 +17,8 @@ import {LibMath} from "src/library/LibMath.sol";
1417
1518import {EvmAdvanceEncoder} from "../util/EvmAdvanceEncoder.sol " ;
1619
20+ contract MockApplication {}
21+
1722contract InputBoxTest is Test {
1823 using LibMath for uint256 ;
1924 using LibBinaryMerkleTree for bytes ;
@@ -34,8 +39,27 @@ contract InputBoxTest is Test {
3439 assertEq (_inputBox.getNumberOfInputs (appContract), 0 );
3540 }
3641
42+ function testAddInputNoContract (
43+ uint256 privateKey ,
44+ bytes32 salt ,
45+ bytes calldata payload
46+ ) external {
47+ privateKey = boundPrivateKey (privateKey);
48+
49+ _testAddInputNoContract (address (0 ), payload);
50+ _testAddInputNoContract (vm.addr (privateKey), payload);
51+
52+ bytes32 bytecodeHash = keccak256 (type (MockApplication).creationCode);
53+ address appContract = Create2.computeAddress (salt, bytecodeHash);
54+ _testAddInputNoContract (appContract, payload);
55+
56+ assertEq (appContract, address (new MockApplication {salt: salt}()));
57+ assertGt (appContract.code.length , 0 );
58+ _inputBox.addInput (appContract, payload);
59+ }
60+
3761 function testAddLargeInput () public {
38- address appContract = vm. addr ( 1 );
62+ address appContract = address ( new MockApplication () );
3963 uint256 max = _getMaxInputPayloadLength ();
4064
4165 _inputBox.addInput (appContract, new bytes (max));
@@ -55,9 +79,9 @@ contract InputBoxTest is Test {
5579 _inputBox.addInput (appContract, largePayload);
5680 }
5781
58- function testAddInput (uint64 chainId , address appContract , bytes [] calldata payloads )
59- public
60- {
82+ function testAddInput (uint64 chainId , bytes [] calldata payloads ) public {
83+ address appContract = address ( new MockApplication ());
84+
6185 vm.chainId (chainId); // foundry limits chain id to be less than 2^64 - 1
6286
6387 uint256 numPayloads = payloads.length ;
@@ -120,6 +144,18 @@ contract InputBoxTest is Test {
120144 }
121145 }
122146
147+ function _testAddInputNoContract (address appContract , bytes calldata payload )
148+ internal
149+ {
150+ assertEq (appContract.code.length , 0 , "expected account with no code " );
151+ vm.expectRevert (
152+ abi.encodeWithSelector (
153+ IInputBox.ApplicationContractNotDeployed.selector , appContract
154+ )
155+ );
156+ _inputBox.addInput (appContract, payload);
157+ }
158+
123159 function _prevrandao (uint256 blockNumber ) internal pure returns (uint256 ) {
124160 return uint256 (keccak256 (abi.encode ("prevrandao " , blockNumber)));
125161 }
0 commit comments