forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecord.t.sol
More file actions
56 lines (43 loc) · 1.79 KB
/
Copy pathRecord.t.sol
File metadata and controls
56 lines (43 loc) · 1.79 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 OR Apache-2.0
pragma solidity ^0.8.18;
import "ds-test/test.sol";
import "cheats/Vm.sol";
contract RecordAccess {
function record() public returns (NestedRecordAccess) {
assembly {
sstore(1, add(sload(1), 1))
}
NestedRecordAccess inner = new NestedRecordAccess();
inner.record();
return inner;
}
}
contract NestedRecordAccess {
function record() public {
assembly {
sstore(2, add(sload(2), 1))
}
}
}
contract RecordTest is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);
function testRecordAccess() public {
RecordAccess target = new RecordAccess();
// Start recording
vm.record();
NestedRecordAccess inner = target.record();
// Verify Records
(bytes32[] memory reads, bytes32[] memory writes) = vm.accesses(address(target));
(bytes32[] memory innerReads, bytes32[] memory innerWrites) = vm.accesses(address(inner));
assertEq(reads.length, 2, "number of reads is incorrect");
assertEq(reads[0], bytes32(uint256(1)), "key for read 0 is incorrect");
assertEq(reads[1], bytes32(uint256(1)), "key for read 1 is incorrect");
assertEq(writes.length, 1, "number of writes is incorrect");
assertEq(writes[0], bytes32(uint256(1)), "key for write is incorrect");
assertEq(innerReads.length, 2, "number of nested reads is incorrect");
assertEq(innerReads[0], bytes32(uint256(2)), "key for nested read 0 is incorrect");
assertEq(innerReads[1], bytes32(uint256(2)), "key for nested read 1 is incorrect");
assertEq(innerWrites.length, 1, "number of nested writes is incorrect");
assertEq(innerWrites[0], bytes32(uint256(2)), "key for nested write is incorrect");
}
}