Skip to content

Commit

Permalink
feat: don't return from isCashierRoot and isCashierShard functions
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsenych-cw committed Oct 30, 2024
1 parent 5e7ff5b commit 55b448c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 42 deletions.
30 changes: 12 additions & 18 deletions contracts/Cashier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ contract Cashier is
/// @dev The mask of all bit flags that are used for the cash-out operations.
uint256 private constant ALL_CASH_OUT_HOOK_FLAGS =
(1 << uint256(HookIndex.CashOutRequestBefore)) +
(1 << uint256(HookIndex.CashOutRequestAfter)) +
(1 << uint256(HookIndex.CashOutConfirmationBefore)) +
(1 << uint256(HookIndex.CashOutConfirmationAfter)) +
(1 << uint256(HookIndex.CashOutReversalBefore)) +
(1 << uint256(HookIndex.CashOutReversalAfter));
(1 << uint256(HookIndex.CashOutRequestAfter)) +
(1 << uint256(HookIndex.CashOutConfirmationBefore)) +
(1 << uint256(HookIndex.CashOutConfirmationAfter)) +
(1 << uint256(HookIndex.CashOutReversalBefore)) +
(1 << uint256(HookIndex.CashOutReversalAfter));

// ------------------ Initializers ---------------------------- //

Expand Down Expand Up @@ -638,11 +638,9 @@ contract Cashier is
// ------------------ Pure functions -------------------------- //

/**
* @inheritdoc ICashierPrimary
*/
function isCashierRoot() external pure returns (bool) {
return true;
}
* @inheritdoc ICashierPrimary
*/
function isCashierRoot() external pure {}

// ------------------ Internal functions ---------------------- //

Expand Down Expand Up @@ -763,13 +761,9 @@ contract Cashier is
}

bool success;
try ICashierShard(shard).isCashierShard() returns (bool result) {
success = result;
try ICashierShard(shard).isCashierShard() {

} catch {
success = false;
}

if (!success) {
revert Cashier_ContractNotShard();
}
}
Expand All @@ -784,8 +778,8 @@ contract Cashier is
}

bool success;
try ICashier(root).isCashierRoot() returns (bool result) {
success = result;
try ICashier(root).isCashierRoot() {
success = true;
} catch {
success = false;
}
Expand Down
17 changes: 4 additions & 13 deletions contracts/CashierShard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,9 @@ contract CashierShard is CashierShardStorage, OwnableUpgradeable, UUPSUpgradeabl
// ------------------ Pure functions -------------------------- //

/**
* @inheritdoc ICashierShardPrimary
*/
function isCashierShard() external pure returns (bool) {
return true;
}
* @inheritdoc ICashierShardPrimary
*/
function isCashierShard() external pure {}

// ------------------ Internal functions ---------------------- //

Expand Down Expand Up @@ -350,14 +348,7 @@ contract CashierShard is CashierShardStorage, OwnableUpgradeable, UUPSUpgradeabl
* @param shard The cashier shard contract address.
*/
function _validateShardContract(address shard) internal pure {
bool success;
try ICashierShard(shard).isCashierShard() returns (bool result) {
success = result;
} catch {
success = false;
}

if (!success) {
try ICashierShard(shard).isCashierShard() {} catch {
revert CashierShard_ContractNotShard();
}
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/ICashier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ interface ICashierPrimary is ICashierTypes {
function underlyingToken() external view returns (address);

/**
* @dev Determines whether the contract is the cashier root contract.
* @dev Determines whether the contract is the cashier root contract.
*/
function isCashierRoot() external pure returns (bool);
function isCashierRoot() external pure;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/ICashierShard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ interface ICashierShardPrimary is ICashierTypes {
function getCashOuts(bytes32[] memory txIds) external view returns (CashOutOperation[] memory operations);

/**
* @dev Determines whether the contract is the cashier shard contract.
* @dev Determines whether the contract is the cashier shard contract.
*/
function isCashierShard() external pure returns (bool);
function isCashierShard() external pure;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions contracts/mocks/CashierShardMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,5 @@ contract CashierShardMock is ICashierTypes {
/**
* @dev Simulates real CashierShard contract.
*/
function isCashierShard() external pure returns (bool) {
return true;
}
function isCashierShard() external pure {}
}
8 changes: 4 additions & 4 deletions test/CashierSharded.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2410,16 +2410,16 @@ describe("Contracts 'Cashier' and `CashierShard`", async () => {
});

describe("Function 'isCashierRoot()'", async () => {
it("Returns expected value", async () => {
it("Executes as expected", async () => {
const { cashierRoot } = await setUpFixture(deployAndConfigureContracts);
expect(await cashierRoot.isCashierRoot()).to.equal(true);
await expect(cashierRoot.isCashierRoot()).to.not.be.reverted;
});
});

describe("Function 'isCashierShard()'", async () => {
it("Returns expected value", async () => {
it("Executes as expected", async () => {
const { cashierShards } = await setUpFixture(deployAndConfigureContracts);
expect(await cashierShards[0].isCashierShard()).to.equal(true);
await expect(cashierShards[0].isCashierShard()).to.not.be.reverted;
});
});

Expand Down

0 comments on commit 55b448c

Please sign in to comment.