Skip to content

Commit

Permalink
refactor(contracts): improve custom error name of advanced contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjei committed Dec 3, 2024
1 parent c74c32d commit 23d6eed
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions packages/contracts/contracts/src/AdvancedChecker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ abstract contract AdvancedChecker is IAdvancedChecker {
/// @param evidence Validation data.
/// @param checkType Check type to perform.
/// @return checked Validation result.
/// @custom:throws PreCheckSkipped If PRE check attempted when skipped.
/// @custom:throws PostCheckSkipped If POST check attempted when skipped.
/// @custom:throws CannotPreCheckWhenSkipped If PRE check attempted when skipped.
/// @custom:throws CannotPostCheckWhenSkipped If POST check attempted when skipped.
function _check(address subject, bytes memory evidence, Check checkType) internal view returns (bool checked) {
// Validate skip conditions first.
if (checkType == Check.PRE && SKIP_PRE) revert PreCheckSkipped();
if (checkType == Check.POST && SKIP_POST) revert PostCheckSkipped();
if (checkType == Check.PRE && SKIP_PRE) revert CannotPreCheckWhenSkipped();
if (checkType == Check.POST && SKIP_POST) revert CannotPostCheckWhenSkipped();

// Route to appropriate check.
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ enum Check {
/// @notice Defines multi-phase validation system interface.
/// @dev Implement this for custom validation logic with pre/main/post checks.
interface IAdvancedChecker {
/// @notice Thrown when pre-check validation attempted while disabled.
error PreCheckSkipped();
/// @notice Thrown when pre-check validation attempted while skipped.
error CannotPreCheckWhenSkipped();

/// @notice Thrown when post-check validation attempted while disabled.
error PostCheckSkipped();
/// @notice Thrown when post-check validation attempted while skipped.
error CannotPostCheckWhenSkipped();

/// @notice Validates subject against specified check type.
/// @param subject Address to validate.
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/contracts/src/test/Advanced.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ contract AdvancedPolicy is Test {

vm.startPrank(target);

vm.expectRevert(abi.encodeWithSelector(IAdvancedChecker.PreCheckSkipped.selector));
vm.expectRevert(abi.encodeWithSelector(IAdvancedChecker.CannotPreCheckWhenSkipped.selector));
policySkipped.enforce(subject, abi.encode(0x0), Check.PRE);

vm.stopPrank();
Expand Down Expand Up @@ -609,7 +609,7 @@ contract AdvancedPolicy is Test {

policySkipped.enforce(subject, abi.encode(0x0), Check.MAIN);

vm.expectRevert(abi.encodeWithSelector(IAdvancedChecker.PostCheckSkipped.selector));
vm.expectRevert(abi.encodeWithSelector(IAdvancedChecker.CannotPostCheckWhenSkipped.selector));
policySkipped.enforce(subject, abi.encode(0x0), Check.POST);

vm.stopPrank();
Expand Down Expand Up @@ -714,7 +714,7 @@ contract AdvancedPolicy is Test {

vm.startPrank(target);

vm.expectRevert(abi.encodeWithSelector(IAdvancedChecker.PreCheckSkipped.selector));
vm.expectRevert(abi.encodeWithSelector(IAdvancedChecker.CannotPreCheckWhenSkipped.selector));
policyHarnessSkipped.exposed__enforce(subject, abi.encode(0x0), Check.PRE);

vm.stopPrank();
Expand Down Expand Up @@ -943,7 +943,7 @@ contract AdvancedPolicy is Test {

policyHarnessSkipped.exposed__enforce(subject, abi.encode(0x0), Check.MAIN);

vm.expectRevert(abi.encodeWithSelector(IAdvancedChecker.PostCheckSkipped.selector));
vm.expectRevert(abi.encodeWithSelector(IAdvancedChecker.CannotPostCheckWhenSkipped.selector));
policyHarnessSkipped.exposed__enforce(subject, abi.encode(0x0), Check.POST);

vm.stopPrank();
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/test/Advanced.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ describe("Advanced", () => {

await expect(
policySkipped.connect(target).enforce(subjectAddress, validEncodedNFTId, 0)
).to.be.revertedWithCustomError(checker, "PreCheckSkipped")
).to.be.revertedWithCustomError(checker, "CannotPreCheckWhenSkipped")
})

it("reverts when check unsuccessful", async () => {
Expand Down Expand Up @@ -669,7 +669,7 @@ describe("Advanced", () => {

await expect(
policySkipped.connect(target).enforce(subjectAddress, validEncodedNFTId, 2)
).to.be.revertedWithCustomError(checker, "PostCheckSkipped")
).to.be.revertedWithCustomError(checker, "CannotPostCheckWhenSkipped")
})

it("reverts when check unsuccessful", async () => {
Expand Down Expand Up @@ -763,7 +763,7 @@ describe("Advanced", () => {

await expect(
policyHarnessSkipped.connect(target).exposed__enforce(subjectAddress, validEncodedNFTId, 0)
).to.be.revertedWithCustomError(checker, "PreCheckSkipped")
).to.be.revertedWithCustomError(checker, "CannotPreCheckWhenSkipped")
})

it("reverts when check unsuccessful", async () => {
Expand Down Expand Up @@ -977,7 +977,7 @@ describe("Advanced", () => {

await expect(
policyHarnessSkipped.connect(target).exposed__enforce(subjectAddress, validEncodedNFTId, 2)
).to.be.revertedWithCustomError(checker, "PostCheckSkipped")
).to.be.revertedWithCustomError(checker, "CannotPostCheckWhenSkipped")
})

it("reverts when check unsuccessful", async () => {
Expand Down

0 comments on commit 23d6eed

Please sign in to comment.