Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create IVersion interface #19

Merged
merged 16 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@stylistic/function-paren-newline": ["warn", "multiline-arguments"],
"@stylistic/indent": ["warn", 2],
"@stylistic/indent-binary-ops": ["warn", 2],
"@stylistic/linebreak-style": ["warn", "unix"],
"@stylistic/linebreak-style": "off",
"@stylistic/lines-around-comment": ["warn", {"beforeBlockComment": false}],
"@stylistic/max-len": ["warn", {"code": 120, "tabWidth": 2}],
"@stylistic/member-delimiter-style": [
Expand Down
4 changes: 3 additions & 1 deletion contracts/Cashier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ICashierHookable } from "./interfaces/ICashierHookable.sol";
import { IERC20Mintable } from "./interfaces/IERC20Mintable.sol";

import { CashierStorage } from "./CashierStorage.sol";
import { Versionable } from "./Versionable.sol";

/**
* @title Cashier contract
Expand All @@ -34,7 +35,8 @@ contract Cashier is
RescuableUpgradeable,
UUPSUpgradeable,
ICashier,
ICashierHookable
ICashierHookable,
Versionable
{
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.Bytes32Set;
Expand Down
3 changes: 2 additions & 1 deletion contracts/CashierShard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { ICashierShard } from "./interfaces/ICashierShard.sol";
import { ICashierShardPrimary } from "./interfaces/ICashierShard.sol";
import { ICashierShardConfiguration } from "./interfaces/ICashierShard.sol";
import { CashierShardStorage } from "./CashierShardStorage.sol";
import { Versionable } from "./Versionable.sol";

/**
* @title CashierShard contract
* @author CloudWalk Inc. (See https://www.cloudwalk.io)
* @dev The contract responsible for storing sharded cash-in and cash-out operations.
*/
contract CashierShard is CashierShardStorage, OwnableUpgradeable, UUPSUpgradeable, ICashierShard {
contract CashierShard is CashierShardStorage, OwnableUpgradeable, UUPSUpgradeable, ICashierShard, Versionable {
// ------------------ Initializers ---------------------------- //

/**
Expand Down
21 changes: 21 additions & 0 deletions contracts/Versionable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./interfaces/IVersion.sol";

/**
* @title Versionable contract
* @author CloudWalk Inc. (See https://cloudwalk.io)
* @dev Defines the contract version.
*/
abstract contract Versionable is IVersion {
// ------------------ Pure functions -------------------------- //

/**
* @inheritdoc IVersion
*/
function $__VERSION() external pure returns (Version memory) {
return Version(4, 0, 0);
}
}
4 changes: 3 additions & 1 deletion contracts/interfaces/ICashier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,6 @@ interface ICashier is
ICashierErrors, // Tools: this comment prevents Prettier from formatting into a single line.
ICashierPrimary,
ICashierConfiguration
{}
{

}
5 changes: 4 additions & 1 deletion contracts/interfaces/ICashierShard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface ICashierShardErrors {
/// @dev Thrown if the caller is not an admin.
error CashierShard_Unauthorized();
}

/**
* @title ICashierShardPrimary interface
* @author CloudWalk Inc. (See https://www.cloudwalk.io)
Expand Down Expand Up @@ -219,4 +220,6 @@ interface ICashierShard is
ICashierShardErrors, // Tools: this comment prevents Prettier from formatting into a single line.
ICashierShardPrimary,
ICashierShardConfiguration
{}
{

}
24 changes: 24 additions & 0 deletions contracts/interfaces/IVersion.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
* @title IVersion interface
* @author CloudWalk Inc. (See https://cloudwalk.io)
* @dev Defines the function to get the contract version.
*/
interface IVersion {
/**
* @dev The struct for the contract version.
*/
struct Version {
uint8 major; // -- The major version of contract
uint8 minor; // -- The minor version of contract
uint8 patch; // -- The patch version of contract
}

/**
* @dev Returns the version of the contract.
*/
function $__VERSION() external pure returns (Version memory);
}
24 changes: 24 additions & 0 deletions test/CashierSharded.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ interface HookConfig {
[key: string]: number | string; // Indexing signature to ensure that fields are iterated over in a key-value style
}

interface Version {
major: number;
minor: number;
patch: number;

[key: string]: number; // Indexing signature to ensure that fields are iterated over in a key-value style
}

function checkCashOutEquality(
actualOnChainCashOut: Record<string, unknown>,
expectedCashOut: TestCashOut,
Expand Down Expand Up @@ -200,6 +208,12 @@ describe("Contracts 'Cashier' and `CashierShard`", async () => {
(1 << HookIndex.CashOutReversalBefore) +
(1 << HookIndex.CashOutReversalAfter);

const EXPECTED_VERSION: Version = {
major: 4,
minor: 0,
patch: 0
};

// Errors of the lib contracts
const REVERT_ERROR_IF_CONTRACT_INITIALIZATION_IS_INVALID = "InvalidInitialization";
const REVERT_ERROR_IF_CONTRACT_IS_PAUSED = "EnforcedPause";
Expand Down Expand Up @@ -2520,6 +2534,16 @@ describe("Contracts 'Cashier' and `CashierShard`", async () => {
});
});

describe("Function '$__VERSION()'", async () => {
it("Returns expected values", async () => {
const { cashierRoot, cashierShards } = await setUpFixture(deployAndConfigureContracts);
const cashierRootVersion = await cashierRoot.$__VERSION();
const cashierShardVersion = await cashierShards[0].$__VERSION();
checkEquality(cashierRootVersion, EXPECTED_VERSION);
checkEquality(cashierShardVersion, EXPECTED_VERSION);
});
});

describe("Scenarios with configured hooks", async () => {
async function checkHookEvents(fixture: Fixture, props: {
tx: TransactionResponse;
Expand Down
Loading