From ad151623ca212f1b8c9f352c7cb6319e11a8abae Mon Sep 17 00:00:00 2001 From: Thomas Clement Date: Mon, 11 Nov 2024 12:31:59 -0500 Subject: [PATCH 1/2] Init Helper functions in abstract Test Class I find myself rewriting this code across repos often. It would be nice if we supported in base FraxTest Class. We can add Test Coverage once we add a generic 1967Proxy to this repo --- src/FraxTest.sol | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/FraxTest.sol b/src/FraxTest.sol index a28014c..bc331e8 100644 --- a/src/FraxTest.sol +++ b/src/FraxTest.sol @@ -6,9 +6,14 @@ import { VmHelper } from "./VmHelper.sol"; import { Strings } from "./StringsHelper.sol"; abstract contract FraxTest is VmHelper, Test { + /// @notice Chain State Storage uint256[] internal snapShotIds; function()[] internal setupFunctions; + /// @notice EIP-1967 Slots + bytes32 internal IMPLEMENTATION_SLOT = bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1); + bytes32 internal ADMIN_SLOT = bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1); + // ======================================================================== // ~~~~~~~~~~~~~~~~~~ Different State Testing Helpers ~~~~~~~~~~~~~~~~~~~~~ // ======================================================================== @@ -34,6 +39,34 @@ abstract contract FraxTest is VmHelper, Test { } } + // ======================================================================== + // ~~~~~~~~~~~~~~~~~~~~~~~ EIP-1967 Proxy Helpers ~~~~~~~~~~~~~~~~~~~~~~~~~ + // ======================================================================== + + /// @notice Helper function to efficiently return the address type located at the implementation + /// and admin slot on an EIP-1967 Proxy + /// @param _proxyToCheck The proxy to fetch the implementation and admin of + /// @return implementation The Implmentation of the `_proxyToCheck` + /// @return admin The Admin of the `_proxyToCheck` + function get1967ProxyImplAndAdmin( + address _proxyToCheck + ) internal view returns (address implementation, address admin) { + implementation = address(uint160(uint(vm.load(_proxyToCheck, IMPLEMENTATION_SLOT)))); + admin = address(uint160(uint(vm.load(_proxyToCheck, ADMIN_SLOT)))); + } + + /// @notice Variant of the above function but the returns will be logged to the console + /// @param _proxyToCheck The proxy to fetch the implementation and admin of + /// @return implementation The Implmentation of the `_proxyToCheck` + /// @return admin The Admin of the `_proxyToCheck` + function get1967ProxyImplAndAdminWithLog( + address _proxyToCheck + ) internal view returns (address implementation, address admin) { + (implementation, admin) = get1967ProxyImplAndAdmin(_proxyToCheck); + console.log(" get1967ProxyImplAndAdminWithLog: Implementation - ", implementation); + console.log(" get1967ProxyImplAndAdminWithLog: ProxyAdmin - ", admin); + } + // ======================================================================== // ~~~~~~~~~~~~~~~~~~~~~~~ Storage Slot Helpers ~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ======================================================================== From c6354e826dc088926c23b8f339dfcf653fb6fb1a Mon Sep 17 00:00:00 2001 From: Thomas Clement Date: Wed, 13 Nov 2024 10:02:19 -0500 Subject: [PATCH 2/2] Update Comment --- src/FraxTest.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FraxTest.sol b/src/FraxTest.sol index bc331e8..2595bc8 100644 --- a/src/FraxTest.sol +++ b/src/FraxTest.sol @@ -6,7 +6,7 @@ import { VmHelper } from "./VmHelper.sol"; import { Strings } from "./StringsHelper.sol"; abstract contract FraxTest is VmHelper, Test { - /// @notice Chain State Storage + /// @notice Differential State Storage uint256[] internal snapShotIds; function()[] internal setupFunctions;