Skip to content

Commit

Permalink
Init Helper functions in abstract Test Class
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tom2o17 committed Nov 11, 2024
1 parent c951978 commit ad15162
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/FraxTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 ~~~~~~~~~~~~~~~~~~~~~
// ========================================================================
Expand All @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ========================================================================
Expand Down

0 comments on commit ad15162

Please sign in to comment.