Skip to content

Commit

Permalink
add comments to transient storage test file with test information
Browse files Browse the repository at this point in the history
  • Loading branch information
snissn committed Dec 14, 2024
1 parent 260f401 commit a2e4b37
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions actors/evm/tests/contracts/TransientStorageTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ contract TransientStorageTest {
_runTests();
}

// Test 0: Initial Constructor Test
function runTests() public returns (bool) {
_runTests();
}
Expand Down Expand Up @@ -61,13 +62,14 @@ contract TransientStorageTest {
require(retrievedValue == value, "TLOAD did not retrieve stored value within transaction");
}

// Test 2.2: Verify transient storage clears in subsequent transactions
function testLifecycleValidationSubsequentTransaction() public {
// Test clearing by re-calling as a new transaction
uint256 slot = 3;
bool cleared = isStorageCleared(slot);
require(cleared, "Transient storage was not cleared after transaction");
}

// Utility Function: Check if transient storage is cleared
function isStorageCleared(uint256 slot) public view returns (bool) {
uint256 retrievedValue;
assembly {
Expand All @@ -76,7 +78,7 @@ contract TransientStorageTest {
return retrievedValue == 0; // True if cleared
}

// Test 2.2: Verify nested contract independence
// Test 3: Verify nested contract independence
function testNestedContracts(address other) public returns (bool) {
uint256 slot = 4;
uint256 value = 88;
Expand Down Expand Up @@ -104,7 +106,7 @@ contract TransientStorageTest {
return true;
}

// New function to test reentry scenario
// Test 4: Reentry scenario
function testReentry(address otherContract) public returns (bool) {
uint256 slot = 5;
uint256 value = 123;
Expand All @@ -127,6 +129,7 @@ contract TransientStorageTest {
return true;
}

// Utility Function for Test 4: Reentry callback
function reentryCallback() public {
uint256 slot = 6;
uint256 value = 456;
Expand All @@ -145,12 +148,14 @@ contract TransientStorageTest {
require(retrievedValue == value, "Reentry callback failed to store correct value");
}

// Utility Function for Test 3: Write to transient storage
function writeTransientData(uint256 slot, uint256 value) external {
assembly {
tstore(slot, value)
}
}

// Utility Function for Test 3: Read from transient storage
function readTransientData(uint256 slot) external view returns (uint256) {
uint256 value;
assembly {
Expand Down

0 comments on commit a2e4b37

Please sign in to comment.