-
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.
test(ens-domains): add integration test for 'reserve' method
- Loading branch information
1 parent
d1934aa
commit 6b26662
Showing
5 changed files
with
147 additions
and
2 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
96 changes: 96 additions & 0 deletions
96
test/integration/concrete/ens-domains/reserve/reserve.t.sol
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,96 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.26; | ||
|
||
import { Integration_Test } from "../../../Integration.t.sol"; | ||
import { Errors } from "../../../../utils/Errors.sol"; | ||
import { Events } from "../../../../utils/Events.sol"; | ||
|
||
contract Reserve_Integration_Concret_Test is Integration_Test { | ||
function setUp() public virtual override { | ||
Integration_Test.setUp(); | ||
} | ||
|
||
function test_RevertWhen_CallerNotContract() external { | ||
// Make Bob the caller in this test suite which is an EOA | ||
vm.startPrank({ msgSender: users.bob }); | ||
|
||
// Expect the call to revert with the {SpaceZeroCodeSize} error | ||
vm.expectRevert(Errors.SpaceZeroCodeSize.selector); | ||
|
||
// Run the test | ||
werkSubdomainRegistrar.reserve({ label: "name" }); | ||
} | ||
|
||
modifier whenCallerContract() { | ||
_; | ||
} | ||
|
||
function test_RevertWhen_NonCompliantSpace() external whenCallerContract { | ||
// Make Eve the caller in this test suite as she's the owner of the {Space} contract | ||
vm.startPrank({ msgSender: users.eve }); | ||
|
||
// Create the calldata for the reserve method execution | ||
bytes memory data = abi.encodeWithSignature("reserve(string)", "test"); | ||
|
||
// Expect the call to revert with the {SpaceUnsupportedInterface} error | ||
vm.expectRevert(Errors.SpaceUnsupportedInterface.selector); | ||
|
||
// Run the test | ||
mockNonCompliantSpace.execute({ module: address(werkSubdomainRegistrar), value: 0, data: data }); | ||
} | ||
|
||
modifier whenCompliantSpace() { | ||
_; | ||
} | ||
|
||
function test_RevertWhen_SubdomainAlreadyReserved() external whenCallerContract whenCompliantSpace { | ||
// Make Eve the caller in this test suite as she's the owner of the {Space} contract | ||
vm.startPrank({ msgSender: users.eve }); | ||
|
||
// Create the calldata for the reserve method execution | ||
bytes memory data = abi.encodeWithSignature("reserve(string)", "test"); | ||
|
||
// Compute the expiration timestamp | ||
uint40 expiresAt = uint40(block.timestamp + 30 minutes); | ||
|
||
// Reserve the subdomain | ||
space.execute({ module: address(werkSubdomainRegistrar), value: 0, data: data }); | ||
|
||
// Expect the call to revert with the {AlreadyReserved} error | ||
vm.expectRevert(abi.encodeWithSelector(Errors.AlreadyReserved.selector, expiresAt)); | ||
|
||
// Run the test | ||
space.execute({ module: address(werkSubdomainRegistrar), value: 0, data: data }); | ||
} | ||
|
||
modifier whenSubdomainNotReserved() { | ||
_; | ||
} | ||
|
||
function test_Reserve() external whenCallerContract whenCompliantSpace whenSubdomainNotReserved { | ||
// Make Eve the caller in this test suite as she's the owner of the {Space} contract | ||
vm.startPrank({ msgSender: users.eve }); | ||
|
||
// Create the calldata for the reserve method execution | ||
bytes memory data = abi.encodeWithSignature("reserve(string)", "test"); | ||
|
||
// Compute the expiration timestamp | ||
uint40 expectedExpiresAt = uint40(block.timestamp + 30 minutes); | ||
|
||
// Expect the reservation call to emit a {SubdomainReserved} event | ||
vm.expectEmit(); | ||
emit Events.SubdomainReserved({ label: "test", owner: address(space), expiresAt: expectedExpiresAt }); | ||
|
||
// Run the test | ||
space.execute({ module: address(werkSubdomainRegistrar), value: 0, data: data }); | ||
|
||
// Get the reservation | ||
(address owner, uint40 actualExpiresAt) = werkSubdomainRegistrar.reservations(keccak256(bytes("test"))); | ||
|
||
// Assert that actual and expected owner are the same | ||
assertEq(owner, address(space)); | ||
|
||
// Assert that actual and expected expiration timestamp are the same | ||
assertEq(actualExpiresAt, expectedExpiresAt); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
test/integration/concrete/ens-domains/reserve/reserve.tree
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,12 @@ | ||
reserve.t.sol | ||
├── when the caller IS NOT a contract | ||
│ └── it should revert with the {SpaceZeroCodeSize} error | ||
└── when the caller IS a contract | ||
├── when the caller is NOT a compliant Space | ||
│ └── it should revert with the {SpaceUnsupportedInterface} error | ||
└── when the caller is a compliant Space | ||
├── when subdomain is already reserved | ||
│ └── it should revert with the {AlreadyReserved} error | ||
└── when subdomain is NOT reserved | ||
├── it should emit a {SubdomainReserved} event | ||
└── it should create a new reservation for the label |
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