-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d25eb6f
commit 0e65965
Showing
4 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
/// @notice Transient storage get/set helper. | ||
/// @author Soledge (https://github.com/vectorized/soledge/blob/main/src/utils/LibTransient.sol) | ||
library LibTransient { | ||
/// @dev Returns the value at `tSlot` in transient storage. | ||
function get(bytes32 tSlot) internal view returns (bytes32 result) { | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
result := tload(tSlot) | ||
} | ||
} | ||
|
||
/// @dev Sets the value at `tSlot` in transient storage to `value`. | ||
function set(bytes32 tSlot, bytes32 value) internal { | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
tstore(tSlot, value) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import "./utils/SoladyTest.sol"; | ||
import {LibTransient} from "../src/utils/LibTransient.sol"; | ||
|
||
contract LibTransientTest is SoladyTest { | ||
function testTransientSetAndGet(bytes32 s, uint256 i) public { | ||
unchecked { | ||
assertEq(LibTransient.get(s), bytes32(0)); | ||
LibTransient.set(s, bytes32(i)); | ||
assertEq(LibTransient.get(s), bytes32(i)); | ||
} | ||
} | ||
} |