@@ -269,7 +269,7 @@ contract RecordAccountAccessesTest is DSTest {
269
269
);
270
270
string memory diffsJson = cheats.getStateDiffJson ();
271
271
assertEq (
272
- " { \ "0x5991a2df15a8f6a256d3ec51e99254cd3fb576a9 \ ":{ \ "label \ ":null, \ "contract \" : \ "default/cheats/RecordAccountAccesses.t.sol:StorageAccessor \" , \ "balanceDiff \ ":null, \ "nonceDiff \ ":null, \ "stateDiff \ ":{ \ "0x00000000000000000000000000000000000000000000000000000000000004d3 \ ":{ \ "previousValue \" : \ "0x0000000000000000000000000000000000000000000000000000000000000000 \" , \ "newValue \" : \ "0x000000000000000000000000000000000000000000000000000000000000162e \ "}}}, \ "0xc7183455a4c133ae270771860664b6b7ec320bb1 \ ":{ \ "label \ ":null, \ "contract \" : \ "default/cheats/RecordAccountAccesses.t.sol:StorageAccessor \" , \ "balanceDiff \ ":null, \ "nonceDiff \ ":null, \ "stateDiff \ ":{ \ "0x000000000000000000000000000000000000000000000000000000000000162e \ ":{ \ "previousValue \" : \ "0x0000000000000000000000000000000000000000000000000000000000000000 \" , \ "newValue \" : \ "0x00000000000000000000000000000000000000000000000000000000000004d2 \ "}}}} " ,
272
+ ' { "0x5991a2df15a8f6a256d3ec51e99254cd3fb576a9":{"label":null,"contract": "default/cheats/RecordAccountAccesses.t.sol:StorageAccessor", "balanceDiff":null,"nonceDiff":null,"stateDiff":{"0x00000000000000000000000000000000000000000000000000000000000004d3":{"previousValue": "0x0000000000000000000000000000000000000000000000000000000000000000", "newValue": "0x000000000000000000000000000000000000000000000000000000000000162e"}}},"0xc7183455a4c133ae270771860664b6b7ec320bb1":{"label":null,"contract": "default/cheats/RecordAccountAccesses.t.sol:StorageAccessor", "balanceDiff":null,"nonceDiff":null,"stateDiff":{"0x000000000000000000000000000000000000000000000000000000000000162e":{"previousValue": "0x0000000000000000000000000000000000000000000000000000000000000000", "newValue": "0x00000000000000000000000000000000000000000000000000000000000004d2"}}}}' ,
273
273
diffsJson
274
274
);
275
275
Vm.AccountAccess[] memory called = filterExtcodesizeForLegacyTests (cheats.stopAndReturnStateDiff ());
@@ -491,7 +491,7 @@ contract RecordAccountAccessesTest is DSTest {
491
491
cheats.getStateDiff ()
492
492
);
493
493
assertEq (
494
- " { \ "0x00000000000000000000000000000000000004d2 \ ":{ \ "label \ ":null, \ "contract \ ":null, \ "balanceDiff \ ":{ \ "previousValue \" : \ "0x0 \" , \ "newValue \" : \ "0x16345785d8a0000 \ "}, \ "nonceDiff \ ":null, \ "stateDiff \ ":{}}} " ,
494
+ ' { "0x00000000000000000000000000000000000004d2":{"label":null,"contract":null,"balanceDiff":{"previousValue": "0x0", "newValue": "0x16345785d8a0000"},"nonceDiff":null,"stateDiff":{}}}' ,
495
495
cheats.getStateDiffJson ()
496
496
);
497
497
Vm.AccountAccess[] memory called = filterExtcodesizeForLegacyTests (cheats.stopAndReturnStateDiff ());
@@ -837,7 +837,7 @@ contract RecordAccountAccessesTest is DSTest {
837
837
cheats.getStateDiff ()
838
838
);
839
839
assertEq (
840
- "{\"0x2e234dae75c793f67a35089c9d99245e1c58470b\":{\"label\":\"NestedStorer\",\"contract\":\"default/cheats/RecordAccountAccesses.t.sol:NestedStorer\",\"balanceDiff\":null,\"nonceDiff\":null,\"stateDiff\":{\"0x4566fa0cd03218c55bba914d793f5e6b9113172c1f684bb5f464c08c867e8977\":{\"previousValue\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"newValue\":\"0x0000000000000000000000000000000000000000000000000000000000000001\"},\"0xbf57896b60daefa2c41de2feffecfc11debd98ea8c913a5170f60e53959ac00a\":{\"previousValue\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"newValue\":\"0x0000000000000000000000000000000000000000000000000000000000000001\"},\"0xc664893a982d78bbeab379feef216ff517b7ea73626b280723be1ace370364cd\":{\"previousValue\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"newValue\":\"0x0000000000000000000000000000000000000000000000000000000000000001\"},\"0xdc5330afa9872081253545dca3f448752688ff1b098b38c1abe4c4cdff4b0b0e\":{\"previousValue\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"newValue\":\"0x0000000000000000000000000000000000000000000000000000000000000001\"}}}}",
840
+ '{"0x2e234dae75c793f67a35089c9d99245e1c58470b":{"label":"NestedStorer","contract":"default/cheats/RecordAccountAccesses.t.sol:NestedStorer","balanceDiff":null,"nonceDiff":null,"stateDiff":{"0x4566fa0cd03218c55bba914d793f5e6b9113172c1f684bb5f464c08c867e8977":{"previousValue":"0x0000000000000000000000000000000000000000000000000000000000000000","newValue":"0x0000000000000000000000000000000000000000000000000000000000000001"},"0xbf57896b60daefa2c41de2feffecfc11debd98ea8c913a5170f60e53959ac00a":{"previousValue":"0x0000000000000000000000000000000000000000000000000000000000000000","newValue":"0x0000000000000000000000000000000000000000000000000000000000000001"},"0xc664893a982d78bbeab379feef216ff517b7ea73626b280723be1ace370364cd":{"previousValue":"0x0000000000000000000000000000000000000000000000000000000000000000","newValue":"0x0000000000000000000000000000000000000000000000000000000000000001"},"0xdc5330afa9872081253545dca3f448752688ff1b098b38c1abe4c4cdff4b0b0e":{"previousValue":"0x0000000000000000000000000000000000000000000000000000000000000000","newValue":"0x0000000000000000000000000000000000000000000000000000000000000001"}}}}',
841
841
cheats.getStateDiffJson ()
842
842
);
843
843
Vm.AccountAccess[] memory called = filterExtcodesizeForLegacyTests (cheats.stopAndReturnStateDiff ());
@@ -1403,4 +1403,51 @@ contract RecordAccountAccessesTest is DSTest {
1403
1403
function deriveCreate2Address (address deployer , bytes32 salt , bytes32 codeHash ) internal pure returns (address ) {
1404
1404
return address (uint160 (uint256 (keccak256 (abi.encodePacked (bytes1 (0xff ), deployer, salt, codeHash)))));
1405
1405
}
1406
+
1407
+ /// @notice Simple test for getStorageAccesses() cheatcode
1408
+ function testGetStorageAccesses () public {
1409
+ StorageAccessor accessor = test1;
1410
+
1411
+ // Start recording to enable storage access tracking
1412
+ cheats.startStateDiffRecording ();
1413
+
1414
+ // Perform a read operation
1415
+ accessor.read (bytes32 (uint256 (789 )));
1416
+
1417
+ // Perform a write operation
1418
+ accessor.write (bytes32 (uint256 (123 )), bytes32 (uint256 (456 )));
1419
+
1420
+ // Perform another read operation after the write
1421
+ accessor.read (bytes32 (uint256 (123 )));
1422
+
1423
+ // Get all storage accesses
1424
+ Vm.StorageAccess[] memory accesses = cheats.getStorageAccesses ();
1425
+
1426
+ // Check we have 3 storage accesses (2 reads + 1 write)
1427
+ assertEq (accesses.length , 3 , "should have 3 storage accesses " );
1428
+
1429
+ // Check the first read access
1430
+ assertEq (accesses[0 ].account, address (accessor));
1431
+ assertEq (accesses[0 ].slot, bytes32 (uint256 (789 )));
1432
+ assertEq (accesses[0 ].isWrite, false );
1433
+ assertEq (accesses[0 ].previousValue, bytes32 (uint256 (0 )));
1434
+ assertEq (accesses[0 ].newValue, bytes32 (uint256 (0 )));
1435
+ assertEq (accesses[0 ].reverted, false );
1436
+
1437
+ // Check the write access
1438
+ assertEq (accesses[1 ].account, address (accessor));
1439
+ assertEq (accesses[1 ].slot, bytes32 (uint256 (123 )));
1440
+ assertEq (accesses[1 ].isWrite, true );
1441
+ assertEq (accesses[1 ].previousValue, bytes32 (uint256 (0 )));
1442
+ assertEq (accesses[1 ].newValue, bytes32 (uint256 (456 )));
1443
+ assertEq (accesses[1 ].reverted, false );
1444
+
1445
+ // Check the second read access (reading the value we just wrote)
1446
+ assertEq (accesses[2 ].account, address (accessor));
1447
+ assertEq (accesses[2 ].slot, bytes32 (uint256 (123 )));
1448
+ assertEq (accesses[2 ].isWrite, false );
1449
+ assertEq (accesses[2 ].previousValue, bytes32 (uint256 (456 )));
1450
+ assertEq (accesses[2 ].newValue, bytes32 (uint256 (456 )));
1451
+ assertEq (accesses[2 ].reverted, false );
1452
+ }
1406
1453
}
0 commit comments