|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.13; |
| 3 | + |
| 4 | +import {Assertion} from "../../Assertion.sol"; |
| 5 | +import {PhEvm} from "../../PhEvm.sol"; |
| 6 | + |
| 7 | +contract MappingTarget { |
| 8 | + // slot 0 |
| 9 | + mapping(address => uint256) public balances; |
| 10 | + |
| 11 | + function setBalance(address user, uint256 amount) external { |
| 12 | + balances[user] = amount; |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +MappingTarget constant MAPPING_TARGET = MappingTarget(0xdCCf1eEB153eF28fdc3CF97d33f60576cF092e9c); |
| 17 | + |
| 18 | +contract TestChangedMappingKeys is Assertion { |
| 19 | + constructor() payable {} |
| 20 | + |
| 21 | + function checkChangedKeys() external view { |
| 22 | + bytes[] memory keys = ph.changedMappingKeys(address(MAPPING_TARGET), bytes32(uint256(0))); |
| 23 | + require(keys.length == 2, "expected 2 changed keys"); |
| 24 | + } |
| 25 | + |
| 26 | + function triggers() external view override { |
| 27 | + registerCallTrigger(this.checkChangedKeys.selector); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +contract TestMappingValueDiff is Assertion { |
| 32 | + constructor() payable {} |
| 33 | + |
| 34 | + function checkValueDiff() external view { |
| 35 | + address user = address(0xBEEF); |
| 36 | + bytes memory key = abi.encode(user); |
| 37 | + |
| 38 | + (bytes32 pre, bytes32 post, bool changed) = |
| 39 | + ph.mappingValueDiff(address(MAPPING_TARGET), bytes32(uint256(0)), key, 0); |
| 40 | + |
| 41 | + require(changed, "value should have changed"); |
| 42 | + require(pre == bytes32(uint256(0)), "pre should be zero"); |
| 43 | + require(post == bytes32(uint256(100)), "post should be 100"); |
| 44 | + } |
| 45 | + |
| 46 | + function triggers() external view override { |
| 47 | + registerCallTrigger(this.checkValueDiff.selector); |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +contract MappingTriggeringTx { |
| 52 | + constructor() payable { |
| 53 | + MAPPING_TARGET.setBalance(address(0xBEEF), 100); |
| 54 | + MAPPING_TARGET.setBalance(address(0xCAFE), 200); |
| 55 | + } |
| 56 | +} |
0 commit comments