|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity ^0.8.13; |
| 3 | + |
| 4 | +import {Assertion} from "../../Assertion.sol"; |
| 5 | +import {PhEvm} from "../../PhEvm.sol"; |
| 6 | +import {Target, TARGET} from "../common/Target.sol"; |
| 7 | + |
| 8 | +contract TestCallInputs is Assertion { |
| 9 | + constructor() payable {} |
| 10 | + |
| 11 | + function getCallInputs() external view { |
| 12 | + PhEvm.CallInputs[] memory callInputs = ph.getCallInputs(address(TARGET), Target.readStorage.selector); |
| 13 | + require(callInputs.length == 1, "callInputs.length != 1"); |
| 14 | + PhEvm.CallInputs memory callInput = callInputs[0]; |
| 15 | + |
| 16 | + require(callInput.target_address == address(TARGET), "callInput.target_address != target"); |
| 17 | + require(callInput.input.length == 0, "callInput.input.length != 0"); |
| 18 | + require(callInput.value == 0, "callInput.value != 0"); |
| 19 | + |
| 20 | + callInputs = ph.getCallInputs(address(TARGET), Target.writeStorage.selector); |
| 21 | + require(callInputs.length == 2, "callInputs.length != 2"); |
| 22 | + |
| 23 | + callInput = callInputs[0]; |
| 24 | + require(callInput.target_address == address(TARGET), "callInput.target_address != target"); |
| 25 | + require(callInput.input.length == 32, "callInput.input.length != 32"); |
| 26 | + uint256 param = abi.decode(callInput.input, (uint256)); |
| 27 | + require(param == 1, "First writeStorage param should be 1"); |
| 28 | + require(callInput.value == 0, "callInput.value != 0"); |
| 29 | + |
| 30 | + callInput = callInputs[1]; |
| 31 | + require(callInput.target_address == address(TARGET), "callInput.target_address != target"); |
| 32 | + require(callInput.input.length == 32, "callInput.input.length != 32"); |
| 33 | + param = abi.decode(callInput.input, (uint256)); |
| 34 | + require(param == 2, "Second writeStorage param should be 2"); |
| 35 | + require(callInput.value == 0, "callInput.value != 0"); |
| 36 | + } |
| 37 | + |
| 38 | + function callInputsWrongTarget() external view { |
| 39 | + PhEvm.CallInputs[] memory callInputs = |
| 40 | + ph.getCallInputs(address(0x000000000000000000000000000000000000dEaD), Target.readStorage.selector); |
| 41 | + require(callInputs.length == 1, "Wrong target: callInputs.length != 1"); |
| 42 | + } |
| 43 | + |
| 44 | + function callNoSelector() external view { |
| 45 | + PhEvm.CallInputs[] memory callInputs = ph.getCallInputs(address(TARGET), bytes4(0)); |
| 46 | + require(callInputs.length == 1, "No selector: callInputs.length != 1"); |
| 47 | + } |
| 48 | + |
| 49 | + function triggers() external view override { |
| 50 | + registerCallTrigger(this.getCallInputs.selector); |
| 51 | + registerCallTrigger(this.callInputsWrongTarget.selector); |
| 52 | + registerCallTrigger(this.callNoSelector.selector); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +contract TriggeringTx { |
| 57 | + constructor() payable { |
| 58 | + TARGET.writeStorage(1); |
| 59 | + TARGET.writeStorage(2); |
| 60 | + TARGET.readStorage(); |
| 61 | + |
| 62 | + address fallbackTarget = address(0x000000000000000000000000000000000000dEaD); |
| 63 | + (bool success,) = fallbackTarget.call(abi.encodeWithSelector(TARGET.readStorage.selector)); |
| 64 | + require(success, "call failed"); |
| 65 | + |
| 66 | + (success,) = address(TARGET).call(""); |
| 67 | + require(success, "call failed"); |
| 68 | + } |
| 69 | +} |
0 commit comments