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