Skip to content

Commit

Permalink
Adding two additional custom errors
Browse files Browse the repository at this point in the history
Added NotMaintainer and NotStbtc to better understand the error if
occurs.
  • Loading branch information
dimpar committed Apr 10, 2024
1 parent 89585dc commit 7a2b52b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions core/contracts/MezoAllocator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,17 @@ contract MezoAllocator is IDispatcher, Ownable2Step {
/// @notice Reverts if the caller is not an authorized account.
error NotAuthorized();
/// @notice Reverts if the caller is not a maintainer.
error NotMaintainer();
/// @notice Reverts if the caller is not the stBTC contract.
error NotStbtc();
/// @notice Reverts if the caller is not a maintainer.
error MaintainerNotRegistered();
/// @notice Reverts if the caller is already a maintainer.
error MaintainerAlreadyRegistered();

modifier onlyMaintainer() {
if (!isMaintainer[msg.sender]) {
revert NotAuthorized();
revert NotMaintainer();
}
_;
}
Expand Down Expand Up @@ -171,7 +175,7 @@ contract MezoAllocator is IDispatcher, Ownable2Step {
/// MezoPortal for a given deposit id.
/// @param amount Amount of tBTC to withdraw.
function withdraw(uint256 amount) external {
if (msg.sender != address(stbtc)) revert NotAuthorized();
if (msg.sender != address(stbtc)) revert NotStbtc();

emit DepositWithdrawn(depositId, amount);
mezoPortal.withdraw(address(tbtc), depositId, uint96(amount));
Expand Down
4 changes: 2 additions & 2 deletions core/test/MezoAllocator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe("MezoAllocator", () => {
it("should revert", async () => {
await expect(
mezoAllocator.connect(thirdParty).allocate(),
).to.be.revertedWithCustomError(mezoAllocator, "NotAuthorized")
).to.be.revertedWithCustomError(mezoAllocator, "NotMaintainer")
})
})

Expand Down Expand Up @@ -153,7 +153,7 @@ describe("MezoAllocator", () => {
it("should revert", async () => {
await expect(
mezoAllocator.connect(thirdParty).withdraw(1n),
).to.be.revertedWithCustomError(mezoAllocator, "NotAuthorized")
).to.be.revertedWithCustomError(mezoAllocator, "NotStbtc")
})
})

Expand Down

0 comments on commit 7a2b52b

Please sign in to comment.