-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
115 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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,70 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import {SystemTest} from "../System.t.sol"; | ||
import {RegistrarController} from "src/registrar/Registrar.sol"; | ||
|
||
/// @notice this contract tests the RegistrarController, but only whitelisting tests | ||
/// separated for clarity and organisation | ||
contract FreeWhitelistRegistrarTest is SystemTest { | ||
function test_whitelist_free_register() public { | ||
// set launch time in 10 days | ||
vm.prank(registrarAdmin); | ||
registrar.setLaunchTime(block.timestamp + 10 days); | ||
vm.stopPrank(); | ||
|
||
// mint with success | ||
vm.startPrank(alice); | ||
deal(address(alice), 1000 ether); | ||
|
||
string memory nameToMint = unicode"alice🐻❄️-free-whitelisted"; | ||
RegistrarController.RegisterRequest memory request = RegistrarController.RegisterRequest({ | ||
name: nameToMint, | ||
owner: alice, | ||
duration: 365 days, | ||
resolver: address(resolver), | ||
data: new bytes[](0), | ||
reverseRecord: true, | ||
referrer: address(0) | ||
}); | ||
|
||
bytes memory payload = abi.encode(request.owner); | ||
bytes32 payloadHash = keccak256(payload); | ||
bytes memory prefix = "\x19Ethereum Signed Message:\n32"; | ||
bytes32 prefixedHash = keccak256(abi.encodePacked(prefix, payloadHash)); | ||
|
||
(uint8 v, bytes32 r, bytes32 s) = vm.sign(signerPk, prefixedHash); | ||
|
||
bytes memory signature = abi.encodePacked(r, s, v); | ||
|
||
registrar.whitelistFreeRegister(request, signature); | ||
|
||
assertEq(baseRegistrar.ownerOf(uint256(keccak256(bytes(nameToMint)))), alice); | ||
|
||
// second time fails because the signature has already been used | ||
vm.expectRevert(abi.encodeWithSelector(RegistrarController.FreeMintSignatureAlreadyUsed.selector)); | ||
registrar.whitelistFreeRegister(request, signature); | ||
|
||
// also if you change the name, it fails, because signature is used | ||
request = RegistrarController.RegisterRequest({ | ||
name: "foooooobar", | ||
owner: alice, | ||
duration: 365 days, | ||
resolver: address(resolver), | ||
data: new bytes[](0), | ||
reverseRecord: true, | ||
referrer: address(0) | ||
}); | ||
payload = abi.encode(request.owner); | ||
payloadHash = keccak256(payload); | ||
prefix = "\x19Ethereum Signed Message:\n32"; | ||
prefixedHash = keccak256(abi.encodePacked(prefix, payloadHash)); | ||
|
||
(v, r, s) = vm.sign(signerPk, prefixedHash); | ||
|
||
signature = abi.encodePacked(r, s, v); | ||
|
||
vm.expectRevert(abi.encodeWithSelector(RegistrarController.FreeMintSignatureAlreadyUsed.selector)); | ||
registrar.whitelistFreeRegister(request, signature); | ||
} | ||
} |