Skip to content

Commit 23d6eed

Browse files
committed
refactor(contracts): improve custom error name of advanced contracts
1 parent c74c32d commit 23d6eed

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

packages/contracts/contracts/src/AdvancedChecker.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ abstract contract AdvancedChecker is IAdvancedChecker {
5656
/// @param evidence Validation data.
5757
/// @param checkType Check type to perform.
5858
/// @return checked Validation result.
59-
/// @custom:throws PreCheckSkipped If PRE check attempted when skipped.
60-
/// @custom:throws PostCheckSkipped If POST check attempted when skipped.
59+
/// @custom:throws CannotPreCheckWhenSkipped If PRE check attempted when skipped.
60+
/// @custom:throws CannotPostCheckWhenSkipped If POST check attempted when skipped.
6161
function _check(address subject, bytes memory evidence, Check checkType) internal view returns (bool checked) {
6262
// Validate skip conditions first.
63-
if (checkType == Check.PRE && SKIP_PRE) revert PreCheckSkipped();
64-
if (checkType == Check.POST && SKIP_POST) revert PostCheckSkipped();
63+
if (checkType == Check.PRE && SKIP_PRE) revert CannotPreCheckWhenSkipped();
64+
if (checkType == Check.POST && SKIP_POST) revert CannotPostCheckWhenSkipped();
6565

6666
// Route to appropriate check.
6767
return

packages/contracts/contracts/src/interfaces/IAdvancedChecker.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ enum Check {
1616
/// @notice Defines multi-phase validation system interface.
1717
/// @dev Implement this for custom validation logic with pre/main/post checks.
1818
interface IAdvancedChecker {
19-
/// @notice Thrown when pre-check validation attempted while disabled.
20-
error PreCheckSkipped();
19+
/// @notice Thrown when pre-check validation attempted while skipped.
20+
error CannotPreCheckWhenSkipped();
2121

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

2525
/// @notice Validates subject against specified check type.
2626
/// @param subject Address to validate.

packages/contracts/contracts/src/test/Advanced.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ contract AdvancedPolicy is Test {
380380

381381
vm.startPrank(target);
382382

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

386386
vm.stopPrank();
@@ -609,7 +609,7 @@ contract AdvancedPolicy is Test {
609609

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

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

615615
vm.stopPrank();
@@ -714,7 +714,7 @@ contract AdvancedPolicy is Test {
714714

715715
vm.startPrank(target);
716716

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

720720
vm.stopPrank();
@@ -943,7 +943,7 @@ contract AdvancedPolicy is Test {
943943

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

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

949949
vm.stopPrank();

packages/contracts/test/Advanced.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ describe("Advanced", () => {
464464

465465
await expect(
466466
policySkipped.connect(target).enforce(subjectAddress, validEncodedNFTId, 0)
467-
).to.be.revertedWithCustomError(checker, "PreCheckSkipped")
467+
).to.be.revertedWithCustomError(checker, "CannotPreCheckWhenSkipped")
468468
})
469469

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

670670
await expect(
671671
policySkipped.connect(target).enforce(subjectAddress, validEncodedNFTId, 2)
672-
).to.be.revertedWithCustomError(checker, "PostCheckSkipped")
672+
).to.be.revertedWithCustomError(checker, "CannotPostCheckWhenSkipped")
673673
})
674674

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

764764
await expect(
765765
policyHarnessSkipped.connect(target).exposed__enforce(subjectAddress, validEncodedNFTId, 0)
766-
).to.be.revertedWithCustomError(checker, "PreCheckSkipped")
766+
).to.be.revertedWithCustomError(checker, "CannotPreCheckWhenSkipped")
767767
})
768768

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

978978
await expect(
979979
policyHarnessSkipped.connect(target).exposed__enforce(subjectAddress, validEncodedNFTId, 2)
980-
).to.be.revertedWithCustomError(checker, "PostCheckSkipped")
980+
).to.be.revertedWithCustomError(checker, "CannotPostCheckWhenSkipped")
981981
})
982982

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

0 commit comments

Comments
 (0)