Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1967 Proxy Helper functions in abstract Test Class #24

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Differential 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
Loading