-
Notifications
You must be signed in to change notification settings - Fork 106
ENSIP-19 Fork tests for Base Mainnet #144
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,119 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.23; | ||
|
|
||
| import {Test} from "forge-std/Test.sol"; | ||
| import {ENS} from "ens-contracts/registry/ENS.sol"; | ||
| import {NameResolver} from "ens-contracts/resolvers/profiles/NameResolver.sol"; | ||
|
|
||
| import {RegistrarController} from "src/L2/RegistrarController.sol"; | ||
| import {UpgradeableRegistrarController} from "src/L2/UpgradeableRegistrarController.sol"; | ||
| import {IL2ReverseRegistrar} from "src/L2/interface/IL2ReverseRegistrar.sol"; | ||
| import {IReverseRegistrar} from "src/L2/interface/IReverseRegistrar.sol"; | ||
| import {Sha3} from "src/lib/Sha3.sol"; | ||
| import {BASE_ETH_NODE} from "src/util/Constants.sol"; | ||
|
|
||
| abstract contract AbstractForkSuite is Test { | ||
| // Network configuration hooks | ||
| function forkAlias() internal pure virtual returns (string memory); | ||
|
|
||
| function registry() internal pure virtual returns (address); | ||
| function baseRegistrar() internal pure virtual returns (address); | ||
| function legacyGaController() internal pure virtual returns (address); | ||
| function legacyL2Resolver() internal pure virtual returns (address); | ||
| function legacyReverseRegistrar() internal pure virtual returns (address); | ||
|
|
||
| function upgradeableControllerProxy() internal pure virtual returns (address); | ||
| function upgradeableL2ResolverProxy() internal pure virtual returns (address); | ||
|
|
||
| function ensL2ReverseRegistrar() internal pure virtual returns (address); | ||
| function l2Owner() internal pure virtual returns (address); | ||
| function migrationController() internal pure virtual returns (address); | ||
|
|
||
| function baseCoinType() internal pure virtual returns (uint256); | ||
| function baseReverseParentNode() internal pure virtual returns (bytes32); | ||
|
|
||
| // Actors | ||
| uint256 internal userPk; | ||
| address internal user; | ||
|
|
||
| // Interfaces | ||
| RegistrarController internal legacyController; | ||
| UpgradeableRegistrarController internal upgradeableController; | ||
| NameResolver internal legacyResolver; | ||
| IL2ReverseRegistrar internal l2ReverseRegistrar; | ||
|
|
||
| // Aliased constants for readability in scenarios | ||
| address internal REGISTRY; | ||
| address internal BASE_REGISTRAR; | ||
| address internal LEGACY_GA_CONTROLLER; | ||
| address internal LEGACY_L2_RESOLVER; | ||
| address internal LEGACY_REVERSE_REGISTRAR; | ||
| address internal UPGRADEABLE_CONTROLLER_PROXY; | ||
| address internal UPGRADEABLE_L2_RESOLVER_PROXY; | ||
| address internal ENS_L2_REVERSE_REGISTRAR; | ||
| address internal L2_OWNER; | ||
| address internal MIGRATION_CONTROLLER; | ||
|
|
||
| function setUp() public virtual { | ||
| vm.createSelectFork(forkAlias()); | ||
|
|
||
| // Bind constants | ||
| REGISTRY = registry(); | ||
| BASE_REGISTRAR = baseRegistrar(); | ||
| LEGACY_GA_CONTROLLER = legacyGaController(); | ||
| LEGACY_L2_RESOLVER = legacyL2Resolver(); | ||
| LEGACY_REVERSE_REGISTRAR = legacyReverseRegistrar(); | ||
| UPGRADEABLE_CONTROLLER_PROXY = upgradeableControllerProxy(); | ||
| UPGRADEABLE_L2_RESOLVER_PROXY = upgradeableL2ResolverProxy(); | ||
| ENS_L2_REVERSE_REGISTRAR = ensL2ReverseRegistrar(); | ||
| L2_OWNER = l2Owner(); | ||
| MIGRATION_CONTROLLER = migrationController(); | ||
|
|
||
| // Create a deterministic EOA we control for signing | ||
| userPk = uint256(keccak256("basenames.fork.user")); | ||
| user = vm.addr(userPk); | ||
|
|
||
| legacyController = RegistrarController(LEGACY_GA_CONTROLLER); | ||
| upgradeableController = UpgradeableRegistrarController(UPGRADEABLE_CONTROLLER_PROXY); | ||
| legacyResolver = NameResolver(LEGACY_L2_RESOLVER); | ||
| l2ReverseRegistrar = IL2ReverseRegistrar(ENS_L2_REVERSE_REGISTRAR); | ||
| } | ||
|
|
||
| function _labelFor(string memory name) internal pure returns (bytes32) { | ||
| return keccak256(bytes(name)); | ||
| } | ||
|
|
||
| function _nodeFor(string memory name) internal pure returns (bytes32) { | ||
| return keccak256(abi.encodePacked(BASE_ETH_NODE, _labelFor(name))); | ||
| } | ||
|
|
||
| function _fullName(string memory name) internal view returns (string memory) { | ||
| // Use controller-provided root name to avoid hardcoding suffixes | ||
| return string.concat(name, legacyController.rootName()); | ||
| } | ||
|
|
||
| function _baseReverseNode(address addr, bytes32 baseReverseParent) internal pure returns (bytes32) { | ||
| return keccak256(abi.encodePacked(baseReverseParent, Sha3.hexAddress(addr))); | ||
| } | ||
|
|
||
| // Build a signature for ENS L2 Reverse Registrar setNameForAddrWithSignature, EIP-191 style | ||
| function _buildL2ReverseSignature(string memory fullName, uint256[] memory coinTypes, uint256 expiry) | ||
| internal | ||
| view | ||
| returns (bytes memory) | ||
| { | ||
| bytes4 selector = IL2ReverseRegistrar.setNameForAddrWithSignature.selector; | ||
| bytes32 inner = | ||
| keccak256(abi.encodePacked(ENS_L2_REVERSE_REGISTRAR, selector, user, expiry, fullName, coinTypes)); | ||
| bytes32 digest = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", inner)); | ||
| (uint8 v, bytes32 r, bytes32 s) = vm.sign(userPk, digest); | ||
| return abi.encodePacked(r, s, v); | ||
| } | ||
|
|
||
| function _addressToBytes(address a) internal pure returns (bytes memory b) { | ||
| b = new bytes(20); | ||
| assembly { | ||
| mstore(add(b, 32), mul(a, exp(256, 12))) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why start prank for only one call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's because the single prank is consumed by the call to
_fullNamethat's happening during argument evaluation (since prank is only good for one external call), hence wrapping the whole expression in startPrank/stopPrank. Otherwise fails with unauthorized error bc caller isn't user.