Skip to content

Commit

Permalink
refactor: ♻️ modify storage instead of just reading it
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmauro committed Feb 27, 2025
1 parent 5708e71 commit c4ee7d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions test/contracts/src/StorageFiller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,29 @@ contract StorageFiller {
}
}

// Read a single storage slot
function readStorage(uint256 slot) public view returns (bytes memory) {
// Modify all existing slots with a small value
function modifyStorage(uint256 slot) public returns (bytes memory) {
for (uint256 i = 0; i < slot + 1; i++) {
if (largeStorage[i].length > 0) {
bytes memory data = largeStorage[i];
// Modify each byte in the existing data
for (uint256 j = 0; j < data.length; j++) {
data[j] = bytes1(uint8((i + j) % 256));
}
largeStorage[i] = data;
}
}
return largeStorage[slot];
}

// Read multiple storage slots in one transaction
function readStorageBatch(
// Modify multiple storage slots in one transaction
function modifyStorageBatch(
uint256 startSlot,
uint256 count
) public view returns (uint256) {
) external returns (uint256) {
uint256 totalSize = 0;
for (uint256 i = 0; i < count; i++) {
totalSize += readStorage(startSlot + i).length;
totalSize += modifyStorage(startSlot + i).length;
}
return totalSize;
}
Expand Down
4 changes: 2 additions & 2 deletions test/suites/dev/moonbase/test-pov/test-max-pov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describeSuite({
// This will force the inclusion of all storage proofs in the PoV
const readData = encodeFunctionData({
abi: storageFillerAbi,
functionName: "readStorageBatch",
functionName: "modifyStorageBatch",
args: [0, NUM_SLOTS],
});

Expand Down Expand Up @@ -101,7 +101,7 @@ describeSuite({
try {
const readData = encodeFunctionData({
abi: storageFillerAbi,
functionName: "readStorageBatch",
functionName: "modifyStorageBatch",
args: [0, count],
});

Expand Down

0 comments on commit c4ee7d2

Please sign in to comment.