Forge-compatible ENS contracts, attempting to mirror mainnet as best as possible.
NOTE: If you are doing any time-based work, this pushes your chain aheah 91 days. This is to work with an internal check in BaseRegistrarImplementation.sol from ENS.
Install:
forge install me3-eth/forge-ensUse in your tests:
import { EnsSetup } from "forge-ens/EnsSetup.sol";
contract TestSomething is EnsSetup {
function setUp () public {
super.setUp();
// create yo.demo.eth with PublicResolver at a 1yr TTL
_ens.setSubnodeRecord(demoNode, labelhash("yo"), address(this), address(_defaultResolver), 86400);
// create someone.eth via prank
vm.prank(CONTROLLER_ADDR)
_baseRegistrar.register(uint256(labelhash("someone")), address(this), 86400);
// create somewhere.eth the standard way
bytes32 commitment = _defaultRegistrarController.commit(keccak256(bytes("whatever")));
vm.warp(block.timestamp + 60); // minimum commitment age
_defaultRegistrarController.register{value: 5000}("somewhere", address(this), 86400, commitment);
}
}EnsSetup inherits the Test contract from foundry-rs/forge-std so you have access to all assertions and the VM.
Please see https://docs.ens.domains/contract-api-reference/name-processing#hashing-names
Please see https://docs.ens.domains/contract-api-reference/name-processing#hashing-names
The controller of the base registrar
Matches the base .eth node hash from BulkRenewal.sol
During setUp(), this will be created as demo.eth
An implementation of the ENS registry, specifically ENSRegistryWithFallback.sol
Exposing BaseRegistrarImplementation.sol for doing additional ENS setup. For example:
// create someone.eth via prank, making the owner the calling contract
vm.prank(CONTROLLER_ADDR)
_baseRegistrar.register(uint256(labelhash("someone")), address(this), 86400);Simple price oracle used by the default registrar.
The registrar that users/contracts will interact with in production. For example:
// create somewhere.eth the standard way, calling contract becomes the owner
bytes32 commitment = _defaultRegistrarController.commit(keccak256(bytes("notimportant")));
vm.warp(block.timestamp + 60); // move forward in time for the minimum commitment age
uint256 cost = _priceOracle.price();
_defaultRegistrarController.register{value: cost}("somewhere", address(this), 86400, commitment);The process of setting up the entire ENS stack can be difficult. This contract provides all of the pieces to interact with ENS in tests.
You could also just fork mainnet.
The ENS repository doesn't exactly match the deployed contracts. We get close by going far enough back in history. It would be more accurate to use the deployed contracts as a basis for testing.
The ENS team is working on new contracts, a big one being NameWrapper.
Versioning individual contracts would allow for testing compatibility across a
variety of deployed contracts.
ENS contracts are covered under whatever license they have listed in the .sol files.
Shell script and setup contract are whatever LICENSE file says.