diff --git a/.gitmodules b/.gitmodules index a577129..2a425ea 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "lib/openzeppelin-contracts"] path = lib/openzeppelin-contracts url = https://github.com/OpenZeppelin/openzeppelin-contracts +[submodule "lib/RuleEngine"] + path = lib/RuleEngine + url = https://github.com/CMTA/RuleEngine diff --git a/classDiagram.png b/classDiagram.png deleted file mode 100644 index 1675c99..0000000 Binary files a/classDiagram.png and /dev/null differ diff --git a/classDiagram.svg b/classDiagram.svg deleted file mode 100644 index 424d1c2..0000000 --- a/classDiagram.svg +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - -UmlClassDiagram - - - -0 - -DebtVault -src/DebtVault.sol - -Internal: -   POINTS_MULTIPLIER: uint128 -Public: -   CMTAT_TOKEN: CMTAT_BASE -   ERC20TokenPayment: IERC20 -   claimedDividend: mapping(address=>mapping(uint256=>bool)) -   segragatedDividend: mapping(uint256=>uint256) -   segragatedClaim: mapping(uint256=>bool) - -Internal: -    _msgSender(): (sender: address) -    _msgData(): bytes -    _contextSuffixLength(): uint256 -Public: -    constructor(admin: address, forwarderIrrevocable: address, ERC20TokenPayment_: IERC20, cmtat_token: CMTAT_BASE) -    claimDividend(time: uint256) <<nonReentrant>> -    deposit(time: uint256, amount: uint256) <<onlyRole>> -    withdraw(time: uint256, amount: uint256, withdrawAddress: address) <<onlyRole>> -    withdrawAll(amount: uint256, withdrawAddress: address) <<onlyRole>> -    setStatusClaim(time: uint256, status: bool) <<onlyRole>> - - - -1 - -<<Abstract>> -DebtVaultInvariantStorage -src/invariantStorage/DebtVaultInvariantStorage.sol - -Public: -   DEBT_VAULT_OPERATOR_ROLE: bytes32 -   DEBT_VAULT_DEPOSIT_ROLE: bytes32 -   DEBT_VAULT_WITHDRAW_ROLE: bytes32 - -Public: -    <<event>> newDeposit(time: uint256, sender: address, dividend: uint256) -    <<event>> DividendClaimed(time: uint256, sender: address, dividend: uint256) - - - -0->1 - - - - - -2 - -<<Abstract>> -AuthorizationModuleStandalone -src/modules/AuthorizationModuleStandalone.sol - -Public: -    hasRole(role: bytes32, account: address): bool - - - -0->2 - - - - - -3 - -<<Abstract>> -MetaTxModuleStandalone -src/modules/MetaTxModuleStandalone.sol - -Public: -    constructor(trustedForwarder: address) - - - -0->3 - - - - - diff --git a/doc/accessControl/access-control-RuleEngine.png b/doc/accessControl/access-control-RuleEngine.png deleted file mode 100644 index a711397..0000000 Binary files a/doc/accessControl/access-control-RuleEngine.png and /dev/null differ diff --git a/doc/accessControl/access-control-RuleSanctionList.drawio.png b/doc/accessControl/access-control-RuleSanctionList.drawio.png deleted file mode 100644 index 056590f..0000000 Binary files a/doc/accessControl/access-control-RuleSanctionList.drawio.png and /dev/null differ diff --git a/doc/accessControl/access-control-RuleWhitelist.png b/doc/accessControl/access-control-RuleWhitelist.png deleted file mode 100644 index 607d0d2..0000000 Binary files a/doc/accessControl/access-control-RuleWhitelist.png and /dev/null differ diff --git a/doc/schema/Debt b/doc/schema/Debt index 5dfd10f..1911f8c 100644 --- a/doc/schema/Debt +++ b/doc/schema/Debt @@ -1 +1 @@ -3Vpbk6I4FP41Vu0+aAEhKo/epme2eka3dXtnnrrSEjVbQCyIt/n1GyAgSfDSiq6z/dLkEHI55zvfuXTXQM/fPoVoufhKXezVLMPd1kC/Zll2y2jyX7Fkl0qctpEK5iFxU5G5F4zJTyyE2bQVcXEkTWSUeowsZeGUBgGeMkmGwpBu5Gkz6sm7LtEca4LxFHm69G/iskUqtQBo7l98xmS+yLZuQjt946NstrhKtEAu3RREYFADvZBSlj752x72Yu1likm/+3TgbX6yEAfsnA9c+58XEsDh6/DrcOGu4Wj856hupauskbcSN+7jJY0IE2dmu0wTOHA7sUL5aOqhKCLTGugumO9xgckfQ7oKXBzvZfARP1O4+84HdaNhGCCT/IhfN4y2nQn62+IH/Z0YRQyFLNsuoAHOZoxwSHzMcCgmzmjABGpMyMe6UoSeIroKp/iIJkxHwAuFc8yOqQykE7ErQUco/QlTfr5wxyc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ngHhT8oNDoQQx4MBycvcLqw7tb35rPj6vx7afiQpCUU90KRp7zHgLRrwB3G0QlFn6oQcy5oYFQMTgWNY4EFueDSoLFagOa9zE8gZkh5nwOXOMNrJ3525/Xct0LESdvxzKEFiBMcu8cA4XnQ12ENtq2v+yYYyYd14a522UF6cuFXDw7d4B97Q2g4wE96WOSz9Wr0X0R3pcHu0KmI4OwtOjfGRzMsi9Llpvnz4N7/Lhxbz9tmxS7uKh92x7KGy80sdnaLv4zy3toGnftlIp4av2DpK0Mq8doO/KbLXlYqcqThqy6QE7oLQ3qy0lMYOiZTOT2glHA6XBscWP4Ll1J8WClpnXHAlQSv5bbtwx7NT/fffCu6779AaN//Bw==dZHBDoIwDIafZnfckMQzol48cfC80MqWDErGDOjTC9kQFzTZofv+v+vaMpE349nKTl0J0DCewMjEkXG+Szln80ng6ckh23lQWw3BtIJSvzDAJNCHBuwjoyMyTncxrKhtsXIRk9bSENvuZOKqnaxxA8pKmi29aXDKUy5EtgoX1LVaSmf71CuNXNyhlV5JoOELiYKJ3BI5HzVjjmae3jIYn3f6o35+ZrF1PxKmYH17ukQrEsUb \ No newline at end of file diff --git a/doc/schema/classDiagram.png b/doc/schema/classDiagram.png new file mode 100644 index 0000000..248fe06 Binary files /dev/null and b/doc/schema/classDiagram.png differ diff --git a/doc/schema/classDiagram.svg b/doc/schema/classDiagram.svg new file mode 100644 index 0000000..b0db9bf --- /dev/null +++ b/doc/schema/classDiagram.svg @@ -0,0 +1,71 @@ + + + + + + +UmlClassDiagram + + + +0 + +DebtVault +src/DebtVault.sol + +Internal: +   POINTS_MULTIPLIER: uint128 +Public: +   CMTAT_TOKEN: ICMTATSnapshot +   ERC20TokenPayment: IERC20 +   claimedDividend: mapping(address=>mapping(uint256=>bool)) +   segragatedDividend: mapping(uint256=>uint256) +   segragatedClaim: mapping(uint256=>bool) + +Internal: +    __DebtVault_init(admin: address, ERC20TokenPayment_: IERC20, cmtat_token: ICMTATSnapshot, ruleEngine_: IRuleEngine, authorizationEngineIrrevocable: IAuthorizationEngine) <<onlyInitializing>> +    _computeDividendBatch(time: uint256, tokenHolders: address[], tokenHoldersBalance: uint256[], tokenTotalSupply: uint256): (tokenHolderDividend: uint256[]) +    _computeDividend(time: uint256, senderBalance: uint256, tokenTotalSupply: uint256): (tokenHolderDividend: uint256) +    _transferDividend(time: uint256, tokenHolder: address, tokenHolderDividend: uint256) +    _msgSender(): (sender: address) +    _msgData(): bytes +    _contextSuffixLength(): uint256 +Public: +    constructor(forwarderIrrevocable: address) +    initialize(admin: address, ERC20TokenPayment_: IERC20, cmtat_token: ICMTATSnapshot, ruleEngine_: IRuleEngine, authorizationEngineIrrevocable: IAuthorizationEngine) <<initializer>> +    claimDividend(time: uint256) <<nonReentrant>> +    deposit(time: uint256, amount: uint256) <<onlyRole>> +    withdraw(time: uint256, amount: uint256, withdrawAddress: address) <<onlyRole>> +    withdrawAll(amount: uint256, withdrawAddress: address) <<onlyRole>> +    distributeDividend(addresses: address[], time: uint256) <<onlyRole>> +    setStatusClaim(time: uint256, status: bool) <<onlyRole>> + + + +1 + +<<Abstract>> +DebtVaultInvariantStorage +src/invariantStorage/DebtVaultInvariantStorage.sol + +Public: +   DEBT_VAULT_OPERATOR_ROLE: bytes32 +   DEBT_VAULT_DEPOSIT_ROLE: bytes32 +   DEBT_VAULT_DISTRIBUTE_ROLE: bytes32 +   DEBT_VAULT_WITHDRAW_ROLE: bytes32 + +Public: +    <<event>> newDeposit(time: uint256, sender: address, dividend: uint256) +    <<event>> DividendClaimed(time: uint256, sender: address, dividend: uint256) + + + +0->1 + + + + + diff --git a/doc/solidityAPI/MetaTxStandalone.md b/doc/solidityAPI/MetaTxStandalone.md deleted file mode 100644 index cc5f318..0000000 --- a/doc/solidityAPI/MetaTxStandalone.md +++ /dev/null @@ -1,31 +0,0 @@ -# MetaTxModuleStandalone - -[TOC] - -_Meta transaction (gasless) module._ - -### constructor - -```solidity -constructor(address trustedForwarder) internal -``` - -### _msgSender - -```solidity -function _msgSender() internal view virtual returns (address sender) -``` - -_Override for `msg.sender`. Defaults to the original `msg.sender` whenever -a call is not performed by the trusted forwarder or the calldata length is less than -20 bytes (an address length)._ - -### _msgData - -```solidity -function _msgData() internal view virtual returns (bytes) -``` - -_Override for `msg.data`. Defaults to the original `msg.data` whenever -a call is not performed by the trusted forwarder or the calldata length is less than -20 bytes (an address length)._ diff --git a/doc/solidityAPI/RuleEngine.md b/doc/solidityAPI/RuleEngine.md deleted file mode 100644 index 6bb6559..0000000 --- a/doc/solidityAPI/RuleEngine.md +++ /dev/null @@ -1,283 +0,0 @@ -# RuleEngine - -[TOC] - - - -### RuleEngine_RuleAddressZeroNotAllowed - -```solidity -error RuleEngine_RuleAddressZeroNotAllowed() -``` - -### RuleEngine_RuleAlreadyExists - -```solidity -error RuleEngine_RuleAlreadyExists() -``` - -### RuleEngine_RuleDoNotMatch - -```solidity -error RuleEngine_RuleDoNotMatch() -``` - -### RuleEngine_AdminWithAddressZeroNotAllowed - -```solidity -error RuleEngine_AdminWithAddressZeroNotAllowed() -``` - -### RuleEngine_ArrayIsEmpty - -```solidity -error RuleEngine_ArrayIsEmpty() -``` - -### RULE_ENGINE_ROLE - -```solidity -bytes32 RULE_ENGINE_ROLE -``` - -_Role to manage the ruleEngine_ - -### _ruleIsPresent - -```solidity -mapping(contract IRule => bool) _ruleIsPresent -``` - -_Indicate if a rule already exists_ - -### _rules - -```solidity -contract IRule[] _rules -``` - -_Array of rules_ - -### AddRule - -```solidity -event AddRule(contract IRule rule) -``` - -Generate when a rule is added - -### RemoveRule - -```solidity -event RemoveRule(contract IRule rule) -``` - -Generate when a rule is removed - -### ClearRules - -```solidity -event ClearRules(contract IRule[] rulesRemoved) -``` - -Generate when all the rules are cleared - -### constructor - -```solidity -constructor(address admin, address forwarderIrrevocable) public -``` - -#### Parameters - -| Name | Type | Description | -| -------------------- | ------- | ---------------------------------------------------------- | -| admin | address | Address of the contract (Access Control) | -| forwarderIrrevocable | address | Address of the forwarder, required for the gasless support | - -### setRules - -```solidity -function setRules(contract IRule[] rules_) external -``` - -Set all the rules, will overwrite all the previous rules. \n -Revert if one rule is a zero address or if the rule is already present - -### clearRules - -```solidity -function clearRules() public -``` - -Clear all the rules of the array of rules - -### addRule - -```solidity -function addRule(contract IRule rule_) public -``` - -Add a rule to the array of rules -Revert if one rule is a zero address or if the rule is already present - -### removeRule - -```solidity -function removeRule(contract IRule rule_, uint256 index) public -``` - -Remove a rule from the array of rules -Revert if the rule found at the specified index does not match the rule in argument - -_To reduce the array size, the last rule is moved to the location occupied -by the rule to remove_ - -#### Parameters - -| Name | Type | Description | -| ----- | -------------- | ------------------------------------- | -| rule_ | contract IRule | address of the target rule | -| index | uint256 | the position inside the array of rule | - -### rulesCount - -```solidity -function rulesCount() external view returns (uint256) -``` - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | ------------------------------------ | -| [0] | uint256 | The number of rules inside the array | - -### getRuleIndex - -```solidity -function getRuleIndex(contract IRule rule_) external view returns (uint256 index) -``` - -Get the index of a rule inside the list - -#### Return Values - -| Name | Type | Description | -| ----- | ------- | --------------------------------------------- | -| index | uint256 | if the rule is found, _rules.length otherwise | - -### rule - -```solidity -function rule(uint256 ruleId) external view returns (contract IRule) -``` - -Get the rule at the position specified by ruleId - -#### Parameters - -| Name | Type | Description | -| ------ | ------- | ----------------- | -| ruleId | uint256 | index of the rule | - -#### Return Values - -| Name | Type | Description | -| ---- | -------------- | -------------- | -| [0] | contract IRule | a rule address | - -### rules - -```solidity -function rules() external view returns (contract IRule[]) -``` - -Get all the rules - -#### Return Values - -| Name | Type | Description | -| ---- | ---------------- | ----------------- | -| [0] | contract IRule[] | An array of rules | - -### detectTransferRestriction - -```solidity -function detectTransferRestriction(address _from, address _to, uint256 _amount) public view returns (uint8) -``` - -Go through all the rule to know if a restriction exists on the transfer - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | ----------------------- | -| _from | address | the origin address | -| _to | address | the destination address | -| _amount | uint256 | to transfer | - -#### Return Values - -| Name | Type | Description | -| ---- | ----- | ----------------------------------------------------- | -| [0] | uint8 | The restricion code or REJECTED_CODE_BASE.TRANSFER_OK | - -### validateTransfer - -```solidity -function validateTransfer(address _from, address _to, uint256 _amount) public view returns (bool) -``` - -Validate a transfer - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | ----------------------- | -| _from | address | the origin address | -| _to | address | the destination address | -| _amount | uint256 | to transfer | - -#### Return Values - -| Name | Type | Description | -| ---- | ---- | ---------------------------------------------- | -| [0] | bool | True if the transfer is valid, false otherwise | - -### messageForTransferRestriction - -```solidity -function messageForTransferRestriction(uint8 _restrictionCode) external view returns (string) -``` - -Return the message corresponding to the code - -#### Parameters - -| Name | Type | Description | -| ---------------- | ----- | --------------------------- | -| _restrictionCode | uint8 | The target restriction code | - -#### Return Values - -| Name | Type | Description | -| ---- | ------ | ---------------------------------------------- | -| [0] | string | True if the transfer is valid, false otherwise | - -### _msgSender - -```solidity -function _msgSender() internal view returns (address sender) -``` - -_This surcharge is not necessary if you do not use the MetaTxModule_ - -### _msgData - -```solidity -function _msgData() internal view returns (bytes) -``` - -_This surcharge is not necessary if you do not use the MetaTxModule_ - -## diff --git a/doc/solidityAPI/RuleSanctionList.md b/doc/solidityAPI/RuleSanctionList.md deleted file mode 100644 index 65bcadd..0000000 --- a/doc/solidityAPI/RuleSanctionList.md +++ /dev/null @@ -1,152 +0,0 @@ -# RuleSanctionList - -[TOC] - - - -## SanctionsList - -### isSanctioned - -```solidity -function isSanctioned(address addr) external view returns (bool) -``` - -## RuleSanctionList - -### sanctionsList - -```solidity -contract SanctionsList sanctionsList -``` - -### constructor - -```solidity -constructor(address admin, address forwarderIrrevocable) public -``` - -#### Parameters - -| Name | Type | Description | -| -------------------- | ------- | ---------------------------------------------------------- | -| admin | address | Address of the contract (Access Control) | -| forwarderIrrevocable | address | Address of the forwarder, required for the gasless support | - -### setSanctionListOracle - -```solidity -function setSanctionListOracle(address sanctionContractOracle_) public -``` - -Set the oracle contract - -_zero address is authorized to authorize all transfers_ - -#### Parameters - -| Name | Type | Description | -| ----------------------- | ------- | ------------------------------- | -| sanctionContractOracle_ | address | address of your oracle contract | - -### validateTransfer - -```solidity -function validateTransfer(address _from, address _to, uint256 _amount) public view returns (bool isValid) -``` - -Validate a transfer - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | ----------------------- | -| _from | address | the origin address | -| _to | address | the destination address | -| _amount | uint256 | to transfer | - -#### Return Values - -| Name | Type | Description | -| ------- | ---- | ------------------------------------------------- | -| isValid | bool | => true if the transfer is valid, false otherwise | - -### detectTransferRestriction - -```solidity -function detectTransferRestriction(address _from, address _to, uint256) public view returns (uint8) -``` - -Check if an addres is in the whitelist or not - -#### Parameters - -| Name | Type | Description | -| ----- | ------- | ----------------------- | -| _from | address | the origin address | -| _to | address | the destination address | -| | uint256 | | - -#### Return Values - -| Name | Type | Description | -| ---- | ----- | ----------------------------------------------------- | -| [0] | uint8 | The restricion code or REJECTED_CODE_BASE.TRANSFER_OK | - -### canReturnTransferRestrictionCode - -```solidity -function canReturnTransferRestrictionCode(uint8 _restrictionCode) external pure returns (bool) -``` - -To know if the restriction code is valid for this rule or not. - -#### Parameters - -| Name | Type | Description | -| ---------------- | ----- | --------------------------- | -| _restrictionCode | uint8 | The target restriction code | - -#### Return Values - -| Name | Type | Description | -| ---- | ---- | ------------------------------------------------------ | -| [0] | bool | true if the restriction code is known, false otherwise | - -### messageForTransferRestriction - -```solidity -function messageForTransferRestriction(uint8 _restrictionCode) external pure returns (string) -``` - -Return the corresponding message - -#### Parameters - -| Name | Type | Description | -| ---------------- | ----- | --------------------------- | -| _restrictionCode | uint8 | The target restriction code | - -#### Return Values - -| Name | Type | Description | -| ---- | ------ | ---------------------------------------------- | -| [0] | string | true if the transfer is valid, false otherwise | - -### _msgSender - -```solidity -function _msgSender() internal view returns (address sender) -``` - -_This surcharge is not necessary if you do not use the MetaTxModule_ - -### _msgData - -```solidity -function _msgData() internal view returns (bytes) -``` - -_This surcharge is not necessary if you do not use the MetaTxModule_ - -## diff --git a/doc/solidityAPI/RuleWhitelist.md b/doc/solidityAPI/RuleWhitelist.md deleted file mode 100644 index 7367f8a..0000000 --- a/doc/solidityAPI/RuleWhitelist.md +++ /dev/null @@ -1,219 +0,0 @@ -# RuleWhitelist - -[TOC] - - - -### whitelist - -```solidity -mapping(address => bool) whitelist -``` - -### constructor - -```solidity -constructor(address admin, address forwarderIrrevocable) public -``` - -#### Parameters - -| Name | Type | Description | -| -------------------- | ------- | ---------------------------------------------------------- | -| admin | address | Address of the contract (Access Control) | -| forwarderIrrevocable | address | Address of the forwarder, required for the gasless support | - -### addAddressesToTheWhitelist - -```solidity -function addAddressesToTheWhitelist(address[] listWhitelistedAddress) public -``` - -Add addresses to the whitelist -If one of addresses already exist, there is no change for this address. The transaction remains valid (no revert). - -#### Parameters - -| Name | Type | Description | -| ---------------------- | --------- | ---------------------------------------- | -| listWhitelistedAddress | address[] | an array with the addresses to whitelist | - -### removeAddressesFromTheWhitelist - -```solidity -function removeAddressesFromTheWhitelist(address[] listWhitelistedAddress) public -``` - -Remove addresses from the whitelist -If the address does not exist in the whitelist, there is no change for this address. -The transaction remains valid (no revert). - -#### Parameters - -| Name | Type | Description | -| ---------------------- | --------- | ------------------------------------- | -| listWhitelistedAddress | address[] | an array with the addresses to remove | - -### addAddressToTheWhitelist - -```solidity -function addAddressToTheWhitelist(address _newWhitelistAddress) public -``` - -Add one address to the whitelist -If the address already exists, the transaction is reverted to save gas. - -#### Parameters - -| Name | Type | Description | -| -------------------- | ------- | ------------------------ | -| _newWhitelistAddress | address | The address to whitelist | - -### removeAddressFromTheWhitelist - -```solidity -function removeAddressFromTheWhitelist(address _removeWhitelistAddress) public -``` - -Remove one address from the whitelist -If the address does not exist in the whitelist, the transaction is reverted to save gas. - -#### Parameters - -| Name | Type | Description | -| ----------------------- | ------- | --------------------- | -| _removeWhitelistAddress | address | The address to remove | - -### numberWhitelistedAddress - -```solidity -function numberWhitelistedAddress() external view returns (uint256) -``` - -Get the number of whitelisted addresses - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | ------------------------------- | -| [0] | uint256 | Number of whitelisted addresses | - -### addressIsWhitelisted - -```solidity -function addressIsWhitelisted(address _targetAddress) external view returns (bool) -``` - -Know if an address is whitelisted or not - -#### Parameters - -| Name | Type | Description | -| -------------- | ------- | --------------------- | -| _targetAddress | address | The concerned address | - -#### Return Values - -| Name | Type | Description | -| ---- | ---- | --------------------------------------------------- | -| [0] | bool | True if the address is whitelisted, false otherwise | - -### validateTransfer - -```solidity -function validateTransfer(address _from, address _to, uint256 _amount) public view returns (bool isValid) -``` - -Validate a transfer - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | ----------------------- | -| _from | address | the origin address | -| _to | address | the destination address | -| _amount | uint256 | to transfer | - -#### Return Values - -| Name | Type | Description | -| ------- | ---- | ------------------------------------------------- | -| isValid | bool | => true if the transfer is valid, false otherwise | - -### detectTransferRestriction - -```solidity -function detectTransferRestriction(address _from, address _to, uint256) public view returns (uint8) -``` - -Check if an addres is in the whitelist or not - -#### Parameters - -| Name | Type | Description | -| ----- | ------- | ----------------------- | -| _from | address | the origin address | -| _to | address | the destination address | -| | uint256 | | - -#### Return Values - -| Name | Type | Description | -| ---- | ----- | ----------------------------------------------------- | -| [0] | uint8 | The restricion code or REJECTED_CODE_BASE.TRANSFER_OK | - -### canReturnTransferRestrictionCode - -```solidity -function canReturnTransferRestrictionCode(uint8 _restrictionCode) external pure returns (bool) -``` - -To know if the restriction code is valid for this rule or not. - -#### Parameters - -| Name | Type | Description | -| ---------------- | ----- | --------------------------- | -| _restrictionCode | uint8 | The target restriction code | - -#### Return Values - -| Name | Type | Description | -| ---- | ---- | ------------------------------------------------------ | -| [0] | bool | true if the restriction code is known, false otherwise | - -### messageForTransferRestriction - -```solidity -function messageForTransferRestriction(uint8 _restrictionCode) external pure returns (string) -``` - -Return the corresponding message - -#### Parameters - -| Name | Type | Description | -| ---------------- | ----- | --------------------------- | -| _restrictionCode | uint8 | The target restriction code | - -#### Return Values - -| Name | Type | Description | -| ---- | ------ | ---------------------------------------------- | -| [0] | string | true if the transfer is valid, false otherwise | - -### _msgSender - -```solidity -function _msgSender() internal view returns (address sender) -``` - -_This surcharge is not necessary if you do not use the MetaTxModule_ - -### _msgData - -```solidity -function _msgData() internal view returns (bytes) -``` - -_This surcharge is not necessary if you do not use the MetaTxModule_ diff --git a/doc/surya/surya_graph_DebtVault.png b/doc/surya/surya_graph_DebtVault.png new file mode 100644 index 0000000..760737e Binary files /dev/null and b/doc/surya/surya_graph_DebtVault.png differ diff --git a/doc/surya/surya_report_ruleEngine.md b/doc/surya/surya_report_ruleEngine.md deleted file mode 100644 index 9c57d22..0000000 --- a/doc/surya/surya_report_ruleEngine.md +++ /dev/null @@ -1,40 +0,0 @@ -## Sūrya's Description Report - -### Files Description Table - - -| File Name | SHA-1 Hash | -|-------------|--------------| -| src/RuleEngine.sol | 4b956daef08af2a9e4285f4775f7f459d672c684 | - - -### Contracts Description Table - - -| Contract | Type | Bases | | | -|:----------:|:-------------------:|:----------------:|:----------------:|:---------------:| -| └ | **Function Name** | **Visibility** | **Mutability** | **Modifiers** | -|||||| -| **RuleEngine** | Implementation | IRuleEngine, AccessControl, MetaTxModuleStandalone ||| -| └ | | Public ❗️ | 🛑 | MetaTxModuleStandalone | -| └ | setRules | External ❗️ | 🛑 | onlyRole | -| └ | clearRules | Public ❗️ | 🛑 | onlyRole | -| └ | addRule | Public ❗️ | 🛑 | onlyRole | -| └ | removeRule | Public ❗️ | 🛑 | onlyRole | -| └ | rulesCount | External ❗️ | |NO❗️ | -| └ | getRuleIndex | External ❗️ | |NO❗️ | -| └ | rule | External ❗️ | |NO❗️ | -| └ | rules | External ❗️ | |NO❗️ | -| └ | detectTransferRestriction | Public ❗️ | |NO❗️ | -| └ | validateTransfer | Public ❗️ | |NO❗️ | -| └ | messageForTransferRestriction | External ❗️ | |NO❗️ | -| └ | _msgSender | Internal 🔒 | | | -| └ | _msgData | Internal 🔒 | | | - - -### Legend - -| Symbol | Meaning | -|:--------:|-----------| -| 🛑 | Function can modify state | -| 💵 | Function is payable | diff --git a/doc/surya/surya_report_ruleWhitelist.md b/doc/surya/surya_report_ruleWhitelist.md deleted file mode 100644 index 4c78665..0000000 --- a/doc/surya/surya_report_ruleWhitelist.md +++ /dev/null @@ -1,39 +0,0 @@ -## Sūrya's Description Report - -### Files Description Table - - -| File Name | SHA-1 Hash | -|-------------|--------------| -| src/RuleWhitelist.sol | d2514418c3f9a7255fcabba400edfb8a85d7c076 | - - -### Contracts Description Table - - -| Contract | Type | Bases | | | -|:----------:|:-------------------:|:----------------:|:----------------:|:---------------:| -| └ | **Function Name** | **Visibility** | **Mutability** | **Modifiers** | -|||||| -| **RuleWhitelist** | Implementation | IRule, AccessControl, MetaTxModuleStandalone ||| -| └ | | Public ❗️ | 🛑 | MetaTxModuleStandalone | -| └ | addAddressesToTheWhitelist | Public ❗️ | 🛑 | onlyRole | -| └ | removeAddressesFromTheWhitelist | Public ❗️ | 🛑 | onlyRole | -| └ | addAddressToTheWhitelist | Public ❗️ | 🛑 | onlyRole | -| └ | removeAddressFromTheWhitelist | Public ❗️ | 🛑 | onlyRole | -| └ | numberWhitelistedAddress | External ❗️ | |NO❗️ | -| └ | addressIsWhitelisted | External ❗️ | |NO❗️ | -| └ | validateTransfer | Public ❗️ | |NO❗️ | -| └ | detectTransferRestriction | Public ❗️ | |NO❗️ | -| └ | canReturnTransferRestrictionCode | External ❗️ | |NO❗️ | -| └ | messageForTransferRestriction | External ❗️ | |NO❗️ | -| └ | _msgSender | Internal 🔒 | | | -| └ | _msgData | Internal 🔒 | | | - - -### Legend - -| Symbol | Meaning | -|:--------:|-----------| -| 🛑 | Function can modify state | -| 💵 | Function is payable | diff --git a/doc/technical/general.md b/doc/technical/general.md index 09e0510..09dd066 100644 --- a/doc/technical/general.md +++ b/doc/technical/general.md @@ -6,7 +6,7 @@ ### UML -![uml](../schema/classDiagram1.0.3.svg) +![uml](../schema/classDiagram.svg) diff --git a/doc/test/test/CMTATIntegration.t.sol b/doc/test/test/CMTATIntegration.t.sol deleted file mode 100644 index 2f85b06..0000000 --- a/doc/test/test/CMTATIntegration.t.sol +++ /dev/null @@ -1,241 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "CMTAT/CMTAT_STANDALONE.sol"; -import "./HelperContract.sol"; -import "src/RuleEngine.sol"; - -/** -@title Integration test with the CMTAT -*/ -contract CMTATIntegration is Test, HelperContract { - // Defined in CMTAT.sol - uint8 constant TRANSFER_OK = 0; - string constant TEXT_TRANSFER_OK = "No restriction"; - - RuleEngine ruleEngineMock; - uint256 resUint256; - bool resBool; - - uint256 ADDRESS1_BALANCE_INIT = 31; - uint256 ADDRESS2_BALANCE_INIT = 32; - uint256 ADDRESS3_BALANCE_INIT = 33; - - uint256 FLAG = 5; - - // Arrange - function setUp() public { - vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleWhitelist = new RuleWhitelist(DEFAULT_ADMIN_ADDRESS, ZERO_ADDRESS); - // global arrange - uint48 initialDelay = 0; - uint8 decimals = 0; - vm.prank(DEFAULT_ADMIN_ADDRESS); - CMTAT_CONTRACT = new CMTAT_STANDALONE( - ZERO_ADDRESS, - DEFAULT_ADMIN_ADDRESS, - initialDelay, - "CMTA Token", - "CMTAT", - decimals, - "CMTAT_ISIN", - "https://cmta.ch", - IRuleEngine(address(0)), - "CMTAT_info", - FLAG - ); - - // specific arrange - vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleEngineMock = new RuleEngine(DEFAULT_ADMIN_ADDRESS, ZERO_ADDRESS); - vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleEngineMock.addRule(ruleWhitelist); - vm.prank(DEFAULT_ADMIN_ADDRESS); - CMTAT_CONTRACT.mint(ADDRESS1, ADDRESS1_BALANCE_INIT); - vm.prank(DEFAULT_ADMIN_ADDRESS); - CMTAT_CONTRACT.mint(ADDRESS2, ADDRESS2_BALANCE_INIT); - vm.prank(DEFAULT_ADMIN_ADDRESS); - CMTAT_CONTRACT.mint(ADDRESS3, ADDRESS3_BALANCE_INIT); - vm.prank(DEFAULT_ADMIN_ADDRESS); - // We set the Rule Engine - CMTAT_CONTRACT.setRuleEngine(ruleEngineMock); - } - - /******* Transfer *******/ - function testCannotTransferWithoutAddressWhitelisted() public { - // Arrange - vm.prank(ADDRESS1); - vm.expectRevert( - abi.encodeWithSelector(Errors.CMTAT_InvalidTransfer.selector, ADDRESS1, ADDRESS2, 21)); - // Act - CMTAT_CONTRACT.transfer(ADDRESS2, 21); - } - - function testCannotTransferWithoutFromAddressWhitelisted() public { - // Arrange - uint256 amount = 21; - vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS2); - - vm.prank(ADDRESS1); - vm.expectRevert( - abi.encodeWithSelector(Errors.CMTAT_InvalidTransfer.selector, ADDRESS1, ADDRESS2, amount)); - // Act - CMTAT_CONTRACT.transfer(ADDRESS2, amount); - } - - function testCannotTransferWithoutToAddressWhitelisted() public { - // Arrange - uint256 amount = 21; - vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); - - vm.prank(ADDRESS1); - vm.expectRevert( - abi.encodeWithSelector(Errors.CMTAT_InvalidTransfer.selector, ADDRESS1, ADDRESS2, amount)); - // Act - CMTAT_CONTRACT.transfer(ADDRESS2, amount); - } - - function testCanMakeATransfer() public { - // Arrange - address[] memory whitelist = new address[](2); - whitelist[0] = ADDRESS1; - whitelist[1] = ADDRESS2; - vm.prank(DEFAULT_ADMIN_ADDRESS); - (bool success, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", - whitelist - ) - ); - require(success); - vm.prank(ADDRESS1); - - // Act - CMTAT_CONTRACT.transfer(ADDRESS2, 11); - - // Assert - resUint256 = CMTAT_CONTRACT.balanceOf(ADDRESS1); - assertEq(resUint256, 20); - resUint256 = CMTAT_CONTRACT.balanceOf(ADDRESS2); - assertEq(resUint256, 43); - resUint256 = CMTAT_CONTRACT.balanceOf(ADDRESS3); - assertEq(resUint256, 33); - } - - /******* detectTransferRestriction & messageForTransferRestriction *******/ - function testDetectAndMessageWithFromNotWhitelisted() public { - vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS2); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - // Assert - assertEq(resBool, true); - uint8 res1 = CMTAT_CONTRACT.detectTransferRestriction( - ADDRESS1, - ADDRESS2, - 11 - ); - // Assert - assertEq(res1, CODE_ADDRESS_FROM_NOT_WHITELISTED); - string memory message1 = CMTAT_CONTRACT.messageForTransferRestriction( - res1 - ); - // Assert - assertEq(message1, TEXT_ADDRESS_FROM_NOT_WHITELISTED); - } - - function testDetectAndMessageWithToNotWhitelisted() public { - // Arrange - // We add the sender to the whitelist - vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); - // Arrange - Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - // Act - uint8 res1 = CMTAT_CONTRACT.detectTransferRestriction( - ADDRESS1, - ADDRESS2, - 11 - ); - // Assert - assertEq(res1, CODE_ADDRESS_TO_NOT_WHITELISTED); - // Act - string memory message1 = CMTAT_CONTRACT.messageForTransferRestriction( - res1 - ); - // Assert - assertEq(message1, TEXT_ADDRESS_TO_NOT_WHITELISTED); - } - - function testDetectAndMessageWithFromAndToNotWhitelisted() public { - // Act - uint8 res1 = CMTAT_CONTRACT.detectTransferRestriction( - ADDRESS1, - ADDRESS2, - 11 - ); - - // Assert - assertEq(res1, CODE_ADDRESS_FROM_NOT_WHITELISTED); - // Act - string memory message1 = CMTAT_CONTRACT.messageForTransferRestriction( - res1 - ); - - // Assert - assertEq(message1, TEXT_ADDRESS_FROM_NOT_WHITELISTED); - } - - function testDetectAndMessageWithAValidTransfer() public { - // Arrange - // We add the sender and the recipient to the whitelist. - address[] memory whitelist = new address[](2); - whitelist[0] = ADDRESS1; - whitelist[1] = ADDRESS2; - vm.prank(DEFAULT_ADMIN_ADDRESS); - (bool success, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", - whitelist - ) - ); - require(success); - // Act - uint8 res1 = CMTAT_CONTRACT.detectTransferRestriction( - ADDRESS1, - ADDRESS2, - 11 - ); - // Assert - assertEq(res1, TRANSFER_OK); - // Act - string memory message1 = CMTAT_CONTRACT.messageForTransferRestriction( - res1 - ); - // Assert - assertEq(message1, TEXT_TRANSFER_OK); - } - - function testCanMint() public { - // Arrange - // Add address zero to the whitelist - vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ZERO_ADDRESS); - vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); - // Arrange - Assert - resBool = ruleWhitelist.addressIsWhitelisted(ZERO_ADDRESS); - assertEq(resBool, true); - - // Act - vm.prank(DEFAULT_ADMIN_ADDRESS); - CMTAT_CONTRACT.mint(ADDRESS1, 11); - - // Assert - resUint256 = CMTAT_CONTRACT.balanceOf(ADDRESS1); - assertEq(resUint256, ADDRESS1_BALANCE_INIT + 11); - } -} diff --git a/doc/test/test/HelperContract.sol b/doc/test/test/HelperContract.sol deleted file mode 100644 index a0a43c4..0000000 --- a/doc/test/test/HelperContract.sol +++ /dev/null @@ -1,56 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "CMTAT/CMTAT_STANDALONE.sol"; -import "src/rules/RuleWhitelist.sol"; -import "src/rules/abstract/RuleWhitelistInvariantStorage.sol"; -import "src/rules/abstract/RuleSanctionListInvariantStorage.sol"; -/** -@title Constants used by the tests -*/ -abstract contract HelperContract is RuleWhitelistInvariantStorage,RuleSanctionlistInvariantStorage { - // EOA to perform tests - address constant ZERO_ADDRESS = address(0); - address constant DEFAULT_ADMIN_ADDRESS = address(1); - address constant WHITELIST_OPERATOR_ADDRESS = address(2); - address constant RULE_ENGINE_OPERATOR_ADDRESS = address(3); - address constant SANCTIONLIST_OPERATOR_ADDRESS = address(8); - address constant ATTACKER = address(4); - address constant ADDRESS1 = address(5); - address constant ADDRESS2 = address(6); - address constant ADDRESS3 = address(7); - // role string - string constant RULE_ENGINE_ROLE_HASH = - "0x774b3c5f4a8b37a7da21d72b7f2429e4a6d49c4de0ac5f2b831a1a539d0f0fd2"; - string constant WHITELIST_ROLE_HASH = - "0xdc72ed553f2544c34465af23b847953efeb813428162d767f9ba5f4013be6760"; - string constant DEFAULT_ADMIN_ROLE_HASH = - "0x0000000000000000000000000000000000000000000000000000000000000000"; - - // contract - RuleWhitelist ruleWhitelist; - CMTAT_STANDALONE CMTAT_CONTRACT; - - bytes32 public constant RULE_ENGINE_ROLE = keccak256("RULE_ENGINE_ROLE"); - - uint8 constant NO_ERROR = 0; - - // Forwarder - string ERC2771ForwarderDomain = 'ERC2771ForwarderDomain'; - - // RuleEngine event - event AddRule(IRule indexed rule); - event RemoveRule(IRule indexed rule); - event ClearRules(IRule[] rulesRemoved); - - // Custom error RuleEngine - error RuleEngine_RuleAddressZeroNotAllowed(); - error RuleEngine_RuleAlreadyExists(); - error RuleEngine_RuleDoNotMatch(); - error RuleEngine_AdminWithAddressZeroNotAllowed(); - error RuleEngine_ArrayIsEmpty(); - - - constructor() {} -} diff --git a/doc/test/test/RuleEngine/AccessControl/RuleEngineAccessControl.sol b/doc/test/test/RuleEngine/AccessControl/RuleEngineAccessControl.sol deleted file mode 100644 index 2700af1..0000000 --- a/doc/test/test/RuleEngine/AccessControl/RuleEngineAccessControl.sol +++ /dev/null @@ -1,106 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../../HelperContract.sol"; -import "src/RuleEngine.sol"; - -/** -@title Tests on the Access Control -*/ -contract RuleEngineAccessControlTest is Test, HelperContract { - // Custom error openZeppelin - error AccessControlUnauthorizedAccount(address account, bytes32 neededRole); - RuleEngine ruleEngineMock; - uint8 resUint8; - uint256 resUint256; - bool resBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - - // Arrange - function setUp() public { - ruleWhitelist = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock = new RuleEngine( - RULE_ENGINE_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - resUint256 = ruleEngineMock.rulesCount(); - - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.addRule(ruleWhitelist); - // Arrange - Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } - - function testCannotAttackerSetRules() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - RuleWhitelist ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - vm.prank(WHITELIST_OPERATOR_ADDRESS); - RuleWhitelist ruleWhitelist2 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - IRule[] memory ruleWhitelistTab = new IRule[](2); - ruleWhitelistTab[0] = IRule(ruleWhitelist1); - ruleWhitelistTab[1] = IRule(ruleWhitelist2); - - // Act - vm.prank(ATTACKER); - vm.expectRevert( - abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, ATTACKER, RULE_ENGINE_ROLE)); - (bool success, ) = address(ruleEngineMock).call( - abi.encodeCall(RuleEngine.setRules, ruleWhitelistTab) - ); - - // Assert - assertEq(success, true); - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } - - function testCannnotAttackerClearRules() public { - // Act - vm.prank(ATTACKER); - vm.expectRevert( - abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, ATTACKER, RULE_ENGINE_ROLE)); - ruleEngineMock.clearRules(); - - // Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } - - function testCannotAttackerAddRule() public { - // Act - vm.prank(ATTACKER); - vm.expectRevert( - abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, ATTACKER, RULE_ENGINE_ROLE)); - ruleEngineMock.addRule(ruleWhitelist); - - // Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } - - function testCannotAttackerRemoveRule() public { - // Act - vm.prank(ATTACKER); - vm.expectRevert( - abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, ATTACKER, RULE_ENGINE_ROLE)); - ruleEngineMock.removeRule(ruleWhitelist, 0); - - // Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } -} diff --git a/doc/test/test/RuleEngine/AccessControl/RuleEngineAccessControlOZ.t.sol b/doc/test/test/RuleEngine/AccessControl/RuleEngineAccessControlOZ.t.sol deleted file mode 100644 index 640a494..0000000 --- a/doc/test/test/RuleEngine/AccessControl/RuleEngineAccessControlOZ.t.sol +++ /dev/null @@ -1,114 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../../../lib/openzeppelin-contracts/contracts/access/AccessControl.sol"; -import "../../HelperContract.sol"; -import "src/RuleEngine.sol"; - -/** -@title Tests on the provided functions by OpenZeppelin -*/ -contract RuleEngineAccessControlTest is Test, HelperContract, AccessControl { - RuleEngine ruleEngineMock; - uint8 resUint8; - uint256 resUint256; - bool resBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - - // Arrange - function setUp() public { - ruleWhitelist = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock = new RuleEngine( - RULE_ENGINE_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - resUint256 = ruleEngineMock.rulesCount(); - - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.addRule(ruleWhitelist); - // Arrange - Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } - - function testCanGrantRoleAsAdmin() public { - // Act - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - vm.expectEmit(true, true, false, true); - emit RoleGranted( - RULE_ENGINE_ROLE, - ADDRESS1, - RULE_ENGINE_OPERATOR_ADDRESS - ); - ruleEngineMock.grantRole(RULE_ENGINE_ROLE, ADDRESS1); - // Assert - bool res1 = ruleEngineMock.hasRole(RULE_ENGINE_ROLE, ADDRESS1); - assertEq(res1, true); - } - - function testRevokeRoleAsAdmin() public { - // Arrange - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.grantRole(RULE_ENGINE_ROLE, ADDRESS1); - // Arrange - Assert - bool res1 = ruleEngineMock.hasRole(RULE_ENGINE_ROLE, ADDRESS1); - assertEq(res1, true); - - // Act - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - vm.expectEmit(true, true, false, true); - emit RoleRevoked( - RULE_ENGINE_ROLE, - ADDRESS1, - RULE_ENGINE_OPERATOR_ADDRESS - ); - ruleEngineMock.revokeRole(RULE_ENGINE_ROLE, ADDRESS1); - // Assert - bool res2 = ruleEngineMock.hasRole(RULE_ENGINE_ROLE, ADDRESS1); - assertFalse(res2); - } - - function testCannotGrantFromNonAdmin() public { - // Arrange - Assert - bool res1 = ruleEngineMock.hasRole(RULE_ENGINE_ROLE, ADDRESS1); - assertFalse(res1); - - // Act - vm.expectRevert( - abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, ADDRESS2, DEFAULT_ADMIN_ROLE)); - vm.prank(ADDRESS2); - ruleEngineMock.grantRole(RULE_ENGINE_ROLE, ADDRESS2); - // Assert - bool res2 = ruleEngineMock.hasRole(RULE_ENGINE_ROLE, ADDRESS1); - assertFalse(res2); - } - - function testCannotRevokeFromNonAdmin() public { - // Arrange - Assert - bool res1 = ruleEngineMock.hasRole(RULE_ENGINE_ROLE, ADDRESS1); - assertFalse(res1); - - // Arrange - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.grantRole(RULE_ENGINE_ROLE, ADDRESS1); - // Arrange - Assert - bool res2 = ruleEngineMock.hasRole(RULE_ENGINE_ROLE, ADDRESS1); - assertEq(res2, true); - - // Act - vm.prank(ADDRESS2); - vm.expectRevert( - abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, ADDRESS2, DEFAULT_ADMIN_ROLE)); - ruleEngineMock.revokeRole(RULE_ENGINE_ROLE, ADDRESS1); - - // Assert - bool res3 = ruleEngineMock.hasRole(RULE_ENGINE_ROLE, ADDRESS1); - assertEq(res3, true); - } -} diff --git a/doc/test/test/RuleEngine/RuleEngine.t.sol b/doc/test/test/RuleEngine/RuleEngine.t.sol deleted file mode 100644 index ac219fc..0000000 --- a/doc/test/test/RuleEngine/RuleEngine.t.sol +++ /dev/null @@ -1,454 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../HelperContract.sol"; -import "src/RuleEngine.sol"; - -/** -@title General functions of the RuleEngine -*/ -contract RuleEngineTest is Test, HelperContract { - RuleEngine ruleEngineMock; - uint8 resUint8; - uint256 resUint256; - bool resBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - - // Arrange - function setUp() public { - ruleWhitelist = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock = new RuleEngine( - RULE_ENGINE_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.addRule(ruleWhitelist); - // Arrange - Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } - - function testCanSetRules() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - RuleWhitelist ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - vm.prank(WHITELIST_OPERATOR_ADDRESS); - RuleWhitelist ruleWhitelist2 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - IRule[] memory ruleWhitelistTab = new IRule[](2); - ruleWhitelistTab[0] = IRule(ruleWhitelist1); - ruleWhitelistTab[1] = IRule(ruleWhitelist2); - - // Act - vm.expectEmit(true, false, false, false); - emit AddRule(ruleWhitelist1); - vm.expectEmit(true, false, false, false); - emit AddRule(ruleWhitelist2); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - (bool resCallBool, ) = address(ruleEngineMock).call( - abi.encodeCall(RuleEngine.setRules, ruleWhitelistTab) - ); - - // Assert - assertEq(resCallBool, true); - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 2); - } - - function testCannotSetRuleIfARuleIsAlreadyPresent() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - RuleWhitelist ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - IRule[] memory ruleWhitelistTab = new IRule[](2); - ruleWhitelistTab[0] = IRule(ruleWhitelist1); - ruleWhitelistTab[1] = IRule(ruleWhitelist1); - - // Act - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - vm.expectRevert(RuleEngine_RuleAlreadyExists.selector); - (bool resCallBool, ) = address(ruleEngineMock).call( - abi.encodeCall(RuleEngine.setRules, ruleWhitelistTab) - ); - - // Assert - // I do not know why but the function call return true - // if the call is reverted with the message indicated in expectRevert - // assertFalse(resCallBool); - assertEq(resCallBool, true); - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } - - function testCannotSetEmptyRulesT1() public { - // Arrange - IRule[] memory ruleWhitelistTab = new IRule[](0); - - // Act - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - (bool resCallBool, ) = address(ruleEngineMock).call( - abi.encodeCall(RuleEngine.setRules, ruleWhitelistTab) - ); - - // Assert - assertFalse(resCallBool); - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - - // Assert2 - // The call has not to throw an error. - resBool = ruleEngineMock.validateTransfer(ADDRESS1, ADDRESS2, 20); - assertFalse(resBool); - } - - function testCannotSetEmptyRulesT2() public { - // Arrange - IRule[] memory ruleWhitelistTab = new IRule[](2); - - // Act - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - vm.expectRevert("The array is empty2"); - - (bool resCallBool, ) = address(ruleEngineMock).call( - abi.encodeCall(RuleEngine.setRules, ruleWhitelistTab) - ); - - resBool = ruleEngineMock.validateTransfer(ADDRESS1, ADDRESS2, 20); - - // Assert1 - assertFalse(resCallBool); - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - - // Assert2 - // The call has not to throw an error. - resBool = ruleEngineMock.validateTransfer(ADDRESS1, ADDRESS2, 20); - assertFalse(resBool); - } - - function testCanClearRules() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - RuleWhitelist ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - vm.prank(WHITELIST_OPERATOR_ADDRESS); - RuleWhitelist ruleWhitelist2 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - IRule[] memory ruleWhitelistTab = new IRule[](2); - ruleWhitelistTab[0] = IRule(ruleWhitelist1); - ruleWhitelistTab[1] = IRule(ruleWhitelist2); - - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - (bool resCallBool, ) = address(ruleEngineMock).call( - abi.encodeCall(RuleEngine.setRules, ruleWhitelistTab) - ); - - // Assert - Arrange - assertEq(resCallBool, true); - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 2); - - // Act - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.clearRules(); - - // Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 0); - } - - function testCanAddRule() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - RuleWhitelist ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - - // Act - vm.expectEmit(true, false, false, false); - emit AddRule(ruleWhitelist1); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.addRule(ruleWhitelist1); - - // Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 2); - } - - function testCannotAddRuleZeroAddress() public { - // Act - vm.expectRevert(RuleEngine_RuleAddressZeroNotAllowed.selector); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.addRule(IRule(address(0x0))); - - // Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } - - function testCannotAddARuleAlreadyPresent() public { - // Act - vm.expectRevert(RuleEngine_RuleAlreadyExists.selector); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.addRule(ruleWhitelist); - - // Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } - - function testCanAddARuleAfterThisRuleWasRemoved() public { - // Arrange - Assert - IRule[] memory _rules = ruleEngineMock.rules(); - assertEq(address(_rules[0]), address(ruleWhitelist)); - - // Arrange - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.removeRule(ruleWhitelist, 0); - - // Act - vm.expectEmit(true, false, false, false); - emit AddRule(ruleWhitelist); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.addRule(ruleWhitelist); - - // Assert - _rules = ruleEngineMock.rules(); - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } - - function testCanRemoveNonExistantRule() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - RuleWhitelist ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - - // Act - vm.expectRevert(RuleEngine_RuleDoNotMatch.selector); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.removeRule(ruleWhitelist1, 0); - - // Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } - - function testCanRemoveLatestRule() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - RuleWhitelist ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.addRule(ruleWhitelist1); - - // Act - vm.expectEmit(true, false, false, false); - emit RemoveRule(ruleWhitelist1); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.removeRule(ruleWhitelist1, 1); - - // Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } - - function testCanRemoveFirstRule() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - RuleWhitelist ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.addRule(ruleWhitelist1); - - // Act - vm.expectEmit(true, false, false, false); - emit RemoveRule(ruleWhitelist); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.removeRule(ruleWhitelist, 0); - - // Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - } - - function testCanRemoveRule() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - RuleWhitelist ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.addRule(ruleWhitelist1); - vm.prank(WHITELIST_OPERATOR_ADDRESS); - RuleWhitelist ruleWhitelist2 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.addRule(ruleWhitelist2); - - // Act - vm.expectEmit(true, false, false, false); - emit RemoveRule(ruleWhitelist1); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.removeRule(ruleWhitelist1, 1); - - // Assert - IRule[] memory _rules = ruleEngineMock.rules(); - assertEq(address(_rules[0]), address(ruleWhitelist)); - assertEq(address(_rules[1]), address(ruleWhitelist2)); - - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 2); - } - - function testRuleLength() public { - // Act - resUint256 = ruleEngineMock.rulesCount(); - - // Assert - assertEq(resUint256, 1); - - // Arrange - RuleWhitelist ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - RuleWhitelist ruleWhitelist2 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - IRule[] memory ruleWhitelistTab = new IRule[](2); - ruleWhitelistTab[0] = IRule(ruleWhitelist1); - ruleWhitelistTab[1] = IRule(ruleWhitelist2); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - (bool resCallBool, ) = address(ruleEngineMock).call( - abi.encodeCall(RuleEngine.setRules, ruleWhitelistTab) - ); - - // Arrange - Assert - assertEq(resCallBool, true); - - // Act - resUint256 = ruleEngineMock.rulesCount(); - - // Assert - assertEq(resUint256, 2); - } - - function testGetRule() public { - // Arrange - RuleWhitelist ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - RuleWhitelist ruleWhitelist2 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - IRule[] memory ruleWhitelistTab = new IRule[](2); - ruleWhitelistTab[0] = IRule(ruleWhitelist1); - ruleWhitelistTab[1] = IRule(ruleWhitelist2); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - (bool resCallBool, ) = address(ruleEngineMock).call( - abi.encodeCall(RuleEngine.setRules, ruleWhitelistTab) - ); - // Arrange - Assert - assertEq(resCallBool, true); - - // Act - IRule rule = ruleEngineMock.rule(0); - - // Assert - assertEq(address(rule), address(ruleWhitelist1)); - } - - function testGetRules() public { - // Arrange - RuleWhitelist ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - RuleWhitelist ruleWhitelist2 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - IRule[] memory ruleWhitelistTab = new IRule[](2); - ruleWhitelistTab[0] = IRule(ruleWhitelist1); - ruleWhitelistTab[1] = IRule(ruleWhitelist2); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - (bool resCallBool, ) = address(ruleEngineMock).call( - abi.encodeCall(RuleEngine.setRules, ruleWhitelistTab) - ); - // Arrange - Assert - assertEq(resCallBool, true); - - // Act - IRule[] memory rules = ruleEngineMock.rules(); - - // Assert - assertEq(ruleWhitelistTab.length, rules.length); - for (uint256 i = 0; i < rules.length; ++i) { - assertEq(address(ruleWhitelistTab[i]), address(rules[i])); - } - } - - function testCanGetRuleIndex() public { - // Arrange - RuleWhitelist ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - RuleWhitelist ruleWhitelist2 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - IRule[] memory ruleWhitelistTab = new IRule[](2); - ruleWhitelistTab[0] = IRule(ruleWhitelist1); - ruleWhitelistTab[1] = IRule(ruleWhitelist2); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - (bool resCallBool, ) = address(ruleEngineMock).call( - abi.encodeCall(RuleEngine.setRules, ruleWhitelistTab) - ); - // Arrange - Assert - assertEq(resCallBool, true); - - // Act - uint256 index1 = ruleEngineMock.getRuleIndex(ruleWhitelist1); - uint256 index2 = ruleEngineMock.getRuleIndex(ruleWhitelist2); - // Length of the list because ruleWhitelist is not in the list - uint256 index3 = ruleEngineMock.getRuleIndex(ruleWhitelist); - - // Assert - assertEq(index1, 0); - assertEq(index2, 1); - assertEq(index3, ruleWhitelistTab.length); - } -} diff --git a/doc/test/test/RuleEngine/RuleEngineDeployment.t.sol b/doc/test/test/RuleEngine/RuleEngineDeployment.t.sol deleted file mode 100644 index da68dbc..0000000 --- a/doc/test/test/RuleEngine/RuleEngineDeployment.t.sol +++ /dev/null @@ -1,58 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../HelperContract.sol"; -import "CMTAT/mocks/MinimalForwarderMock.sol"; -import "src/RuleEngine.sol"; -import "src/RuleEngine.sol"; -/** -@title General functions of the RuleEngine -*/ -contract RuleEngineTest is Test, HelperContract { - RuleEngine ruleEngineMock; - uint8 resUint8; - uint256 resUint256; - bool resBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - - // Arrange - function setUp() public { - - } - - function testRightDeployment() public { - // Arrange - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - MinimalForwarderMock forwarder = new MinimalForwarderMock( - ); - forwarder.initialize(ERC2771ForwarderDomain); - - // Act - ruleEngineMock = new RuleEngine( - RULE_ENGINE_OPERATOR_ADDRESS, - address(forwarder) - ); - - // assert - resBool = ruleEngineMock.hasRole(RULE_ENGINE_ROLE, RULE_ENGINE_OPERATOR_ADDRESS); - assertEq(resBool, true); - resBool = ruleEngineMock.isTrustedForwarder(address(forwarder)); - assertEq(resBool, true); - } - - function testCannotDeployContractifAdminAddressIsZero() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - MinimalForwarderMock forwarder = new MinimalForwarderMock( - ); - forwarder.initialize(ERC2771ForwarderDomain); - vm.expectRevert(RuleEngine_AdminWithAddressZeroNotAllowed.selector); - // Act - ruleEngineMock = new RuleEngine( - address(0x0), - address(forwarder) - ); - } -} diff --git a/doc/test/test/RuleEngine/RuleEngineRestriction.t.sol b/doc/test/test/RuleEngine/RuleEngineRestriction.t.sol deleted file mode 100644 index 94c98ec..0000000 --- a/doc/test/test/RuleEngine/RuleEngineRestriction.t.sol +++ /dev/null @@ -1,152 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../HelperContract.sol"; -import "src/RuleEngine.sol"; - -/** -@title tests concerning the restrictions and validation for the transfers -*/ -contract RuleEngineRestrictionTest is Test, HelperContract { - RuleEngine ruleEngineMock; - uint8 resUint8; - uint256 resUint256; - bool resBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - RuleWhitelist ruleWhitelist1; - - // Arrange - function setUp() public { - ruleWhitelist = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock = new RuleEngine( - RULE_ENGINE_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.addRule(ruleWhitelist); - // Arrange - Assert - resUint256 = ruleEngineMock.rulesCount(); - assertEq(resUint256, 1); - - // Arrange - ruleWhitelist1 = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - IRule[] memory ruleWhitelistTab = new IRule[](1); - ruleWhitelistTab[0] = ruleWhitelist1; - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - (bool success, ) = address(ruleEngineMock).call( - abi.encodeCall(RuleEngine.setRules, ruleWhitelistTab) - ); - - // Arrange - Assert - assertEq(success, true); - } - - function testCanDetectTransferRestrictionOK() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist1.addAddressToTheWhitelist(ADDRESS1); - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist1.addAddressToTheWhitelist(ADDRESS2); - - // Act - resUint8 = ruleEngineMock.detectTransferRestriction( - ADDRESS1, - ADDRESS2, - 20 - ); - - // Assert - assertEq(resUint8, 0); - } - - function testCanDetectTransferRestrictionWithFrom() public { - // Act - resUint8 = ruleEngineMock.detectTransferRestriction( - ADDRESS1, - ADDRESS2, - 20 - ); - - // Assert - assertEq(resUint8, CODE_ADDRESS_FROM_NOT_WHITELISTED); - } - - function testCanDetectTransferRestrictionWithTo() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist1.addAddressToTheWhitelist(ADDRESS1); - - // Act - resUint8 = ruleEngineMock.detectTransferRestriction( - ADDRESS1, - ADDRESS2, - 20 - ); - - // Assert - assertEq(resUint8, CODE_ADDRESS_TO_NOT_WHITELISTED); - } - - function testMessageForTransferRestrictionWithValidRC() public { - // Act - resString = ruleEngineMock.messageForTransferRestriction( - CODE_ADDRESS_FROM_NOT_WHITELISTED - ); - - // Assert - assertEq(resString, TEXT_ADDRESS_FROM_NOT_WHITELISTED); - } - - function testMessageForTransferRestrictionNoRule() public { - // Arrange - vm.prank(RULE_ENGINE_OPERATOR_ADDRESS); - ruleEngineMock.clearRules(); - - // Act - resString = ruleEngineMock.messageForTransferRestriction(50); - - // Assert - assertEq(resString, "Unknown restriction code"); - } - - function testMessageForTransferRestrictionWithUnknownRestrictionCode() - public - { - // Act - resString = ruleEngineMock.messageForTransferRestriction(50); - - // Assert - assertEq(resString, "Unknown restriction code"); - } - - function testValidateTransferOK() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist1.addAddressToTheWhitelist(ADDRESS1); - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist1.addAddressToTheWhitelist(ADDRESS2); - - // Act - resBool = ruleEngineMock.validateTransfer(ADDRESS1, ADDRESS2, 20); - - // Assert - assertEq(resBool, true); - } - - function testValidateTransferRestricted() public { - // Act - resBool = ruleEngineMock.validateTransfer(ADDRESS1, ADDRESS2, 20); - - // Assert - assertFalse(resBool); - } -} diff --git a/doc/test/test/RuleSanctionList/RuleSanctionListAdd.t.sol b/doc/test/test/RuleSanctionList/RuleSanctionListAdd.t.sol deleted file mode 100644 index 1965762..0000000 --- a/doc/test/test/RuleSanctionList/RuleSanctionListAdd.t.sol +++ /dev/null @@ -1,47 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../HelperContract.sol"; -import "src/RuleEngine.sol"; -import "src/rules/RuleSanctionList.sol"; -import "../utils/SanctionListOracle.sol"; -/** -@title General functions of the ruleSanctionList -*/ -contract RuleSanctionlistTest is Test, HelperContract { - // Custom error openZeppelin - error AccessControlUnauthorizedAccount(address account, bytes32 neededRole); - - uint256 resUint256; - uint8 resUint8; - bool resBool; - bool resCallBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - SanctionListOracle sanctionlistOracle; - RuleSanctionList ruleSanctionList; - // Arrange - function setUp() public { - vm.prank(SANCTIONLIST_OPERATOR_ADDRESS); - sanctionlistOracle = new SanctionListOracle(); - sanctionlistOracle.addToSanctionsList(ATTACKER); - ruleSanctionList = new RuleSanctionList( - SANCTIONLIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - - } - - function testCanSetOracle() public { - vm.prank(SANCTIONLIST_OPERATOR_ADDRESS); - ruleSanctionList.setSanctionListOracle(address(sanctionlistOracle)); - } - - function testCannotAttackerSetOracle() public { - vm.prank(ATTACKER); - vm.expectRevert( - abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, ATTACKER, SANCTIONLIST_ROLE)); - ruleSanctionList.setSanctionListOracle(address(sanctionlistOracle)); - } -} diff --git a/doc/test/test/RuleSanctionList/RuleSanctionListDeployment.t.sol b/doc/test/test/RuleSanctionList/RuleSanctionListDeployment.t.sol deleted file mode 100644 index e7c870a..0000000 --- a/doc/test/test/RuleSanctionList/RuleSanctionListDeployment.t.sol +++ /dev/null @@ -1,56 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../HelperContract.sol"; -import "src/rules/RuleSanctionList.sol"; -import "CMTAT/mocks/MinimalForwarderMock.sol"; -/** -@title General functions of the ruleSanctionList -*/ -contract RuleSanctionListDeploymentTest is Test, HelperContract { - uint256 resUint256; - uint8 resUint8; - bool resBool; - bool resCallBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - RuleSanctionList ruleSanctionList; - // Arrange - function setUp() public { - - } - - function testRightDeployment() public { - // Arrange - vm.prank(SANCTIONLIST_OPERATOR_ADDRESS); - MinimalForwarderMock forwarder = new MinimalForwarderMock( - ); - forwarder.initialize(ERC2771ForwarderDomain); - vm.prank(SANCTIONLIST_OPERATOR_ADDRESS); - ruleSanctionList = new RuleSanctionList( - SANCTIONLIST_OPERATOR_ADDRESS, - address(forwarder) - ); - - // assert - resBool = ruleSanctionList.hasRole(SANCTIONLIST_ROLE, SANCTIONLIST_OPERATOR_ADDRESS); - assertEq(resBool, true); - resBool = ruleSanctionList.isTrustedForwarder(address(forwarder)); - assertEq(resBool, true); - } - - function testCannotDeployContractIfAdminAddressIsZero() public { - // Arrange - vm.prank(SANCTIONLIST_OPERATOR_ADDRESS); - MinimalForwarderMock forwarder = new MinimalForwarderMock( - ); - forwarder.initialize(ERC2771ForwarderDomain); - vm.expectRevert(RuleSanctionList_AdminWithAddressZeroNotAllowed.selector); - vm.prank(SANCTIONLIST_OPERATOR_ADDRESS); - ruleSanctionList = new RuleSanctionList( - address(0), - address(forwarder) - ); - } -} diff --git a/doc/test/test/RuleSanctionList/RuleSanctionListTest.t.sol b/doc/test/test/RuleSanctionList/RuleSanctionListTest.t.sol deleted file mode 100644 index b55a6a9..0000000 --- a/doc/test/test/RuleSanctionList/RuleSanctionListTest.t.sol +++ /dev/null @@ -1,132 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../HelperContract.sol"; -import "src/RuleEngine.sol"; -import "src/rules/RuleSanctionList.sol"; -import "../utils/SanctionListOracle.sol"; -/** -@title General functions of the ruleSanctionList -*/ -contract RuleSanctionlistTest is Test, HelperContract { - uint256 resUint256; - uint8 resUint8; - bool resBool; - bool resCallBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - SanctionListOracle sanctionlistOracle; - RuleSanctionList ruleSanctionList; - // Arrange - function setUp() public { - vm.prank(SANCTIONLIST_OPERATOR_ADDRESS); - sanctionlistOracle = new SanctionListOracle(); - sanctionlistOracle.addToSanctionsList(ATTACKER); - ruleSanctionList = new RuleSanctionList( - SANCTIONLIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - vm.prank(SANCTIONLIST_OPERATOR_ADDRESS); - ruleSanctionList.setSanctionListOracle(address(sanctionlistOracle)); - } - - function testCanReturnTransferRestrictionCode() public { - // Act - resBool = ruleSanctionList.canReturnTransferRestrictionCode( - CODE_ADDRESS_FROM_IS_SANCTIONED - ); - // Assert - assertEq(resBool, true); - // Act - resBool = ruleSanctionList.canReturnTransferRestrictionCode( - CODE_ADDRESS_TO_IS_SANCTIONED - ); - // Assert - assertEq(resBool, true); - // Act - resBool = ruleSanctionList.canReturnTransferRestrictionCode( - CODE_NONEXISTENT - ); - // Assert - assertFalse(resBool); - } - - function testReturnTheRightMessageForAGivenCode() public { - // Assert - resString = ruleSanctionList.messageForTransferRestriction( - CODE_ADDRESS_FROM_IS_SANCTIONED - ); - // Assert - assertEq(resString, TEXT_ADDRESS_FROM_IS_SANCTIONED); - // Act - resString = ruleSanctionList.messageForTransferRestriction( - CODE_ADDRESS_TO_IS_SANCTIONED - ); - // Assert - assertEq(resString, TEXT_ADDRESS_TO_IS_SANCTIONED); - // Act - resString = ruleSanctionList.messageForTransferRestriction( - CODE_NONEXISTENT - ); - // Assert - assertEq(resString, TEXT_CODE_NOT_FOUND); - } - - function testValidateTransfer() public { - // Act - // ADDRESS1 -> ADDRESS2 - resBool = ruleSanctionList.validateTransfer(ADDRESS1, ADDRESS2, 20); - assertEq(resBool, true); - // ADDRESS2 -> ADDRESS1 - resBool = ruleSanctionList.validateTransfer(ADDRESS2, ADDRESS1, 20); - assertEq(resBool, true); - } - - function testTransferFromDetectedAsInvalid() public { - // Act - resBool = ruleSanctionList.validateTransfer(ATTACKER, ADDRESS2, 20); - // Assert - assertFalse(resBool); - } - - function testTransferToDetectedAsInvalid() public { - // Act - resBool = ruleSanctionList.validateTransfer(ADDRESS1, ATTACKER, 20); - // Assert - assertFalse(resBool); - } - - function testDetectTransferRestrictionFrom() public { - // Act - resUint8 = ruleSanctionList.detectTransferRestriction( - ATTACKER, - ADDRESS2, - 20 - ); - // Assert - assertEq(resUint8, CODE_ADDRESS_FROM_IS_SANCTIONED); - } - - function testDetectTransferRestrictionTo() public { - // Act - resUint8 = ruleSanctionList.detectTransferRestriction( - ADDRESS1, - ATTACKER, - 20 - ); - // Assert - assertEq(resUint8, CODE_ADDRESS_TO_IS_SANCTIONED); - } - - function testDetectTransferRestrictionOk() public { - // Act - resUint8 = ruleSanctionList.detectTransferRestriction( - ADDRESS1, - ADDRESS2, - 20 - ); - // Assert - assertEq(resUint8, NO_ERROR); - } -} diff --git a/doc/test/test/RuleWhitelist/AccessControl/RuleWhitelistAccessControl.t.sol b/doc/test/test/RuleWhitelist/AccessControl/RuleWhitelistAccessControl.t.sol deleted file mode 100644 index 27087ab..0000000 --- a/doc/test/test/RuleWhitelist/AccessControl/RuleWhitelistAccessControl.t.sol +++ /dev/null @@ -1,137 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../../HelperContract.sol"; -import "src/RuleEngine.sol"; - -/** -@title Tests on the Access Control -*/ -contract RuleWhitelistAccessControl is Test, HelperContract { - // Custom error openZeppelin - error AccessControlUnauthorizedAccount(address account, bytes32 neededRole); - // Defined in CMTAT.sol - uint8 constant TRANSFER_OK = 0; - string constant TEXT_TRANSFER_OK = "No restriction"; - uint256 resUint256; - uint8 resUint8; - bool resBool; - bool resCallBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - - // Arrange - function setUp() public { - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - } - - function testCannotAttackerAddAddressToTheWhitelist() public { - vm.expectRevert( - abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, ATTACKER, WHITELIST_ROLE)); - vm.prank(ATTACKER); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); - - // Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, false); - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 0); - } - - function testCannotAttackerAddAddressesToTheWhitelist() public { - // Arrange - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 0); - address[] memory whitelist = new address[](2); - whitelist[0] = ADDRESS1; - whitelist[1] = ADDRESS2; - - // Act - vm.expectRevert( - abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, ATTACKER, WHITELIST_ROLE)); - vm.prank(ATTACKER); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", - whitelist - ) - ); - - // Assert - assertEq(resCallBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, false); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - assertEq(resBool, false); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS3); - assertFalse(resBool); - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 0); - } - - function testCannotAttackerRemoveAddressFromTheWhitelist() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); - - // Arrange - Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - - // Act - vm.expectRevert( - abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, ATTACKER, WHITELIST_ROLE)); - vm.prank(ATTACKER); - ruleWhitelist.removeAddressFromTheWhitelist(ADDRESS1); - - // Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 1); - } - - function testCannotAttackerRemoveAddressesFromTheWhitelist() public { - // Arrange - address[] memory whitelist = new address[](2); - whitelist[0] = ADDRESS1; - whitelist[1] = ADDRESS2; - vm.prank(WHITELIST_OPERATOR_ADDRESS); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", - whitelist - ) - ); - assertEq(resCallBool, true); - // Arrange - Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - assertEq(resBool, true); - - // Act - vm.expectRevert( - abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, ATTACKER, WHITELIST_ROLE)); - vm.prank(ATTACKER); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "removeAddressesFromTheWhitelist(address[])", - whitelist - ) - ); - // Assert - assertEq(resCallBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - assertEq(resBool, true); - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 2); - } -} diff --git a/doc/test/test/RuleWhitelist/AccessControl/RuleWhitelistAccessControlOZ.t.sol b/doc/test/test/RuleWhitelist/AccessControl/RuleWhitelistAccessControlOZ.t.sol deleted file mode 100644 index 8859337..0000000 --- a/doc/test/test/RuleWhitelist/AccessControl/RuleWhitelistAccessControlOZ.t.sol +++ /dev/null @@ -1,98 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../../HelperContract.sol"; -import "../../../lib/openzeppelin-contracts/contracts/access/AccessControl.sol"; -import "src/RuleEngine.sol"; - -/** -@title Tests on the provided functions by OpenZeppelin -*/ -contract RuleWhitelistAccessControlOZ is Test, HelperContract, AccessControl { - // Defined in CMTAT.sol - uint8 constant TRANSFER_OK = 0; - string constant TEXT_TRANSFER_OK = "No restriction"; - uint256 resUint256; - uint8 resUint8; - bool resBool; - bool resCallBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - - // Arrange - function setUp() public { - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - } - - function testCanGrantRoleAsAdmin() public { - // Act - vm.prank(WHITELIST_OPERATOR_ADDRESS); - vm.expectEmit(true, true, false, true); - emit RoleGranted(WHITELIST_ROLE, ADDRESS1, WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.grantRole(WHITELIST_ROLE, ADDRESS1); - // Assert - bool res1 = ruleWhitelist.hasRole(WHITELIST_ROLE, ADDRESS1); - assertEq(res1, true); - } - - function testRevokeRoleAsAdmin() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.grantRole(WHITELIST_ROLE, ADDRESS1); - // Arrange - Assert - bool res1 = ruleWhitelist.hasRole(WHITELIST_ROLE, ADDRESS1); - assertEq(res1, true); - - // Act - vm.prank(WHITELIST_OPERATOR_ADDRESS); - vm.expectEmit(true, true, false, true); - emit RoleRevoked(WHITELIST_ROLE, ADDRESS1, WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.revokeRole(WHITELIST_ROLE, ADDRESS1); - // Assert - bool res2 = ruleWhitelist.hasRole(WHITELIST_ROLE, ADDRESS1); - assertFalse(res2); - } - - function testCannotGrantFromNonAdmin() public { - // Arrange - Assert - bool res1 = ruleWhitelist.hasRole(WHITELIST_ROLE, ADDRESS1); - assertFalse(res1); - - // Act - vm.expectRevert( - abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, ADDRESS2, DEFAULT_ADMIN_ROLE)); - vm.prank(ADDRESS2); - ruleWhitelist.grantRole(WHITELIST_ROLE, ADDRESS1); - // Assert - bool res2 = ruleWhitelist.hasRole(WHITELIST_ROLE, ADDRESS1); - assertFalse(res2); - } - - function testCannotRevokeFromNonAdmin() public { - // Arrange - Assert - bool res1 = ruleWhitelist.hasRole(WHITELIST_ROLE, ADDRESS1); - assertFalse(res1); - - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.grantRole(WHITELIST_ROLE, ADDRESS1); - // Arrange - Assert - bool res2 = ruleWhitelist.hasRole(WHITELIST_ROLE, ADDRESS1); - assertEq(res2, true); - - // Act - vm.prank(ADDRESS2); - vm.expectRevert( - abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, ADDRESS2, DEFAULT_ADMIN_ROLE)); - ruleWhitelist.revokeRole(WHITELIST_ROLE, ADDRESS1); - - // Assert - bool res3 = ruleWhitelist.hasRole(WHITELIST_ROLE, ADDRESS1); - assertEq(res3, true); - } -} diff --git a/doc/test/test/RuleWhitelist/RuleWhitelist.t.sol b/doc/test/test/RuleWhitelist/RuleWhitelist.t.sol deleted file mode 100644 index 575b01d..0000000 --- a/doc/test/test/RuleWhitelist/RuleWhitelist.t.sol +++ /dev/null @@ -1,243 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../HelperContract.sol"; -import "src/RuleEngine.sol"; - -/** -@title General functions of the RuleWhitelist -*/ -contract RuleWhitelistTest is Test, HelperContract { - uint256 resUint256; - uint8 resUint8; - bool resBool; - bool resCallBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - - // Arrange - function setUp() public { - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - } - - function testReturnFalseIfAddressNotWhitelisted() public { - // Act - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - // Assert - assertFalse(resBool); - // Act - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - // Assert - assertFalse(resBool); - // Act - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS3); - // Assert - assertFalse(resBool); - // Act - resBool = ruleWhitelist.addressIsWhitelisted(address(0x0)); - // Assert - assertFalse(resBool); - } - - function testAddressIsIndicatedAsWhitelisted() public { - // Arrange - Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertFalse(resBool); - - // Act - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); - - // Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - } - - function testAddressesIsIndicatedAsWhitelisted() public { - // Arrange - address[] memory whitelist = new address[](2); - whitelist[0] = ADDRESS1; - whitelist[1] = ADDRESS2; - vm.prank(WHITELIST_OPERATOR_ADDRESS); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", - whitelist - ) - ); - assertEq(resCallBool, true); - // Act - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - // Assert - assertEq(resBool, true); - // Act - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - // Assert - assertEq(resBool, true); - // Act - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS3); - // Assert - assertFalse(resBool); - } - - function testCanReturnTransferRestrictionCode() public { - // Act - resBool = ruleWhitelist.canReturnTransferRestrictionCode( - CODE_ADDRESS_FROM_NOT_WHITELISTED - ); - // Assert - assertEq(resBool, true); - // Act - resBool = ruleWhitelist.canReturnTransferRestrictionCode( - CODE_ADDRESS_TO_NOT_WHITELISTED - ); - // Assert - assertEq(resBool, true); - // Act - resBool = ruleWhitelist.canReturnTransferRestrictionCode( - CODE_NONEXISTENT - ); - // Assert - assertFalse(resBool); - } - - function testReturnTheRightMessageForAGivenCode() public { - // Assert - resString = ruleWhitelist.messageForTransferRestriction( - CODE_ADDRESS_FROM_NOT_WHITELISTED - ); - // Assert - assertEq(resString, TEXT_ADDRESS_FROM_NOT_WHITELISTED); - // Act - resString = ruleWhitelist.messageForTransferRestriction( - CODE_ADDRESS_TO_NOT_WHITELISTED - ); - // Assert - assertEq(resString, TEXT_ADDRESS_TO_NOT_WHITELISTED); - // Act - resString = ruleWhitelist.messageForTransferRestriction( - CODE_NONEXISTENT - ); - // Assert - assertEq(resString, TEXT_CODE_NOT_FOUND); - } - - function testValidateTransfer() public { - // Arrange - address[] memory whitelist = new address[](2); - whitelist[0] = ADDRESS1; - whitelist[1] = ADDRESS2; - vm.prank(WHITELIST_OPERATOR_ADDRESS); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", - whitelist - ) - ); - assertEq(resCallBool, true); - // Arrange - Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - assertEq(resBool, true); - - // Act - // ADDRESS1 -> ADDRESS2 - resBool = ruleWhitelist.validateTransfer(ADDRESS1, ADDRESS2, 20); - assertEq(resBool, true); - // ADDRESS2 -> ADDRESS1 - resBool = ruleWhitelist.validateTransfer(ADDRESS2, ADDRESS1, 20); - assertEq(resBool, true); - } - - function testTransferDetectedAsInvalid() public { - // Act - resBool = ruleWhitelist.validateTransfer(ADDRESS1, ADDRESS2, 20); - // Assert - assertFalse(resBool); - } - - function testNumberWhitelistedAddress() public { - // Act - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - // Assert - assertEq(resUint256, 0); - - // Arrange - address[] memory whitelist = new address[](2); - whitelist[0] = ADDRESS1; - whitelist[1] = ADDRESS2; - vm.prank(WHITELIST_OPERATOR_ADDRESS); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", - whitelist - ) - ); - assertEq(resCallBool, true); - // Act - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - // Assert - assertEq(resUint256, 2); - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "removeAddressesFromTheWhitelist(address[])", - whitelist - ) - ); - // Arrange - Assert - assertEq(resCallBool, true); - // Act - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - // Assert - assertEq(resUint256, 0); - } - - function testDetectTransferRestrictionFrom() public { - // Act - resUint8 = ruleWhitelist.detectTransferRestriction( - ADDRESS1, - ADDRESS2, - 20 - ); - // Assert - assertEq(resUint8, CODE_ADDRESS_FROM_NOT_WHITELISTED); - } - - function testDetectTransferRestrictionTo() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); - // Act - resUint8 = ruleWhitelist.detectTransferRestriction( - ADDRESS1, - ADDRESS2, - 20 - ); - // Assert - assertEq(resUint8, CODE_ADDRESS_TO_NOT_WHITELISTED); - } - - function testDetectTransferRestrictionOk() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS2); - // Act - resUint8 = ruleWhitelist.detectTransferRestriction( - ADDRESS1, - ADDRESS2, - 20 - ); - // Assert - assertEq(resUint8, NO_ERROR); - } -} diff --git a/doc/test/test/RuleWhitelist/RuleWhitelistAdd.t.sol b/doc/test/test/RuleWhitelist/RuleWhitelistAdd.t.sol deleted file mode 100644 index 48bae33..0000000 --- a/doc/test/test/RuleWhitelist/RuleWhitelistAdd.t.sol +++ /dev/null @@ -1,185 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../HelperContract.sol"; -import "src/RuleEngine.sol"; - -/** -@title Tests the functions to add addresses to the whitelist -*/ -contract RuleWhitelistAddTest is Test, HelperContract { - // Defined in CMTAT.sol - uint8 constant TRANSFER_OK = 0; - string constant TEXT_TRANSFER_OK = "No restriction"; - uint256 resUint256; - uint8 resUint8; - bool resBool; - bool resCallBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - - // Arrange - function setUp() public { - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - } - - function testAddAddressToTheWhitelist() public { - // Act - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); - - // Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 1); - } - - function testAddAddressesToTheWhitelist() public { - // Arrange - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 0); - address[] memory whitelist = new address[](2); - whitelist[0] = ADDRESS1; - whitelist[1] = ADDRESS2; - - // Act - vm.prank(WHITELIST_OPERATOR_ADDRESS); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", - whitelist - ) - ); - - // Assert - assertEq(resCallBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - assertEq(resBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS3); - assertFalse(resBool); - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 2); - } - - function testCanAddAddressZeroToTheWhitelist() public { - // Arrange - Assert - resBool = ruleWhitelist.addressIsWhitelisted(address(0x0)); - assertEq(resBool, false); - - // Act - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(address(0x0)); - - // Assert - resBool = ruleWhitelist.addressIsWhitelisted(address(0x0)); - assertEq(resBool, true); - } - - function testCanAddAddressesZeroToTheWhitelist() public { - // Arrange - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 0); - address[] memory whitelist = new address[](3); - whitelist[0] = ADDRESS1; - whitelist[1] = ADDRESS2; - // our target address - whitelist[2] = address(0x0); - - // Act - vm.prank(WHITELIST_OPERATOR_ADDRESS); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", - whitelist - ) - ); - - // Assert - Main - // Seem that call returns true even if the function is reverted - // TODO : check the return value of call - resBool = ruleWhitelist.addressIsWhitelisted(address(0x0)); - assertEq(resBool, true); - - // Assert - Secondary - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - assertEq(resBool, true); - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 3); - } - - function testAddAddressTwiceToTheWhitelist() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); - // Arrange - Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - /// Arrange - vm.expectRevert(RuleWhitelist_AddressAlreadyWhitelisted.selector); - // Act - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); - // no change - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 1); - } - - function testAddAddressesTwiceToTheWhitelist() public { - // Arrange - // Arrange - first addition - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 0); - address[] memory whitelist = new address[](2); - whitelist[0] = ADDRESS1; - whitelist[1] = ADDRESS2; - vm.prank(WHITELIST_OPERATOR_ADDRESS); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", - whitelist - ) - ); - // Arrange - Assert - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 2); - // Arrange - second addition - address[] memory whitelistDuplicate = new address[](3); - // Duplicate address - whitelistDuplicate[0] = ADDRESS1; - whitelistDuplicate[1] = ADDRESS2; - // new address in the whitelist - whitelistDuplicate[2] = ADDRESS3; - // Act - vm.prank(WHITELIST_OPERATOR_ADDRESS); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", - whitelistDuplicate - ) - ); - // Assert - // no change - assertEq(resCallBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - assertEq(resBool, true); - // ADDRESS3 is whitelisted - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS3); - assertEq(resBool, true); - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 3); - } -} diff --git a/doc/test/test/RuleWhitelist/RuleWhitelistDeployment.t.sol b/doc/test/test/RuleWhitelist/RuleWhitelistDeployment.t.sol deleted file mode 100644 index 93aa49f..0000000 --- a/doc/test/test/RuleWhitelist/RuleWhitelistDeployment.t.sol +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../HelperContract.sol"; -import "src/RuleEngine.sol"; -import "CMTAT/mocks/MinimalForwarderMock.sol"; -/** -@title General functions of the RuleWhitelist -*/ -contract RuleWhitelistTest is Test, HelperContract { - uint256 resUint256; - uint8 resUint8; - bool resBool; - bool resCallBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - - // Arrange - function setUp() public { - } - - function testRightDeployment() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - MinimalForwarderMock forwarder = new MinimalForwarderMock( - ); - forwarder.initialize(ERC2771ForwarderDomain); - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - address(forwarder) - ); - - // assert - resBool = ruleWhitelist.hasRole(WHITELIST_ROLE, WHITELIST_OPERATOR_ADDRESS); - assertEq(resBool, true); - resBool = ruleWhitelist.isTrustedForwarder(address(forwarder)); - assertEq(resBool, true); - } - - function testCannotDeployContractIfAdminAddressIsZero() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - MinimalForwarderMock forwarder = new MinimalForwarderMock( - ); - forwarder.initialize(ERC2771ForwarderDomain); - vm.expectRevert(RuleWhitelist_AdminWithAddressZeroNotAllowed.selector); - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist = new RuleWhitelist( - address(0), - address(forwarder) - ); - } -} diff --git a/doc/test/test/RuleWhitelist/RuleWhitelistRemove.t.sol b/doc/test/test/RuleWhitelist/RuleWhitelistRemove.t.sol deleted file mode 100644 index 85aaa8e..0000000 --- a/doc/test/test/RuleWhitelist/RuleWhitelistRemove.t.sol +++ /dev/null @@ -1,149 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -import "forge-std/Test.sol"; -import "../HelperContract.sol"; -import "src/RuleEngine.sol"; - -/** -@title Tests the functions to remove addresses from the whitelist -*/ -contract RuleWhitelistRemoveTest is Test, HelperContract { - // Defined in CMTAT.sol - uint8 constant TRANSFER_OK = 0; - string constant TEXT_TRANSFER_OK = "No restriction"; - - uint256 resUint256; - uint8 resUint8; - bool resBool; - bool resCallBool; - string resString; - uint8 CODE_NONEXISTENT = 255; - - // Arrange - function setUp() public { - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist = new RuleWhitelist( - WHITELIST_OPERATOR_ADDRESS, - ZERO_ADDRESS - ); - } - - function testRemoveAddressFromTheWhitelist() public { - // Arrange - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); - - // Arrange - Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - - // Act - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.removeAddressFromTheWhitelist(ADDRESS1); - - // Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertFalse(resBool); - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 0); - } - - function testRemoveAddressesFromTheWhitelist() public { - // Arrange - address[] memory whitelist = new address[](2); - whitelist[0] = ADDRESS1; - whitelist[1] = ADDRESS2; - vm.prank(WHITELIST_OPERATOR_ADDRESS); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", - whitelist - ) - ); - assertEq(resCallBool, true); - // Arrange - Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - assertEq(resBool, true); - - // Act - vm.prank(WHITELIST_OPERATOR_ADDRESS); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "removeAddressesFromTheWhitelist(address[])", - whitelist - ) - ); - // Assert - assertEq(resCallBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertFalse(resBool); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - assertFalse(resBool); - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 0); - } - - function testRemoveAddressNotPresentFromTheWhitelist() public { - // Arrange - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertFalse(resBool); - vm.expectRevert(RuleWhitelist_AddressNotPresent.selector); - - // Act - vm.prank(WHITELIST_OPERATOR_ADDRESS); - ruleWhitelist.removeAddressFromTheWhitelist(ADDRESS1); - - // Assert - // no change - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertFalse(resBool); - } - - function testRemoveAddressesNotPresentFromTheWhitelist() public { - // Arrange - address[] memory whitelist = new address[](2); - whitelist[0] = ADDRESS1; - whitelist[1] = ADDRESS2; - vm.prank(WHITELIST_OPERATOR_ADDRESS); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", - whitelist - ) - ); - assertEq(resCallBool, true); - - // Arrange - Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertEq(resBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - assertEq(resBool, true); - - // Arrange - address[] memory whitelistRemove = new address[](3); - whitelistRemove[0] = ADDRESS1; - whitelistRemove[1] = ADDRESS2; - // Target Address - Not Present in the whitelist - whitelistRemove[2] = ADDRESS3; - - // Act - vm.prank(WHITELIST_OPERATOR_ADDRESS); - (resCallBool, ) = address(ruleWhitelist).call( - abi.encodeWithSignature( - "removeAddressesFromTheWhitelist(address[])", - whitelistRemove - ) - ); - // Assert - assertEq(resCallBool, true); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); - assertFalse(resBool); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); - assertFalse(resBool); - resUint256 = ruleWhitelist.numberWhitelistedAddress(); - assertEq(resUint256, 0); - } -} diff --git a/doc/test/test/utils/SanctionListOracle.sol b/doc/test/test/utils/SanctionListOracle.sol deleted file mode 100644 index bbae931..0000000 --- a/doc/test/test/utils/SanctionListOracle.sol +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -pragma solidity ^0.8.20; - -/** -* @notice Test contract from -https://etherscan.io/address/0x40c57923924b5c5c5455c48d93317139addac8fb#code -*/ -contract SanctionListOracle { - - constructor() {} - - mapping(address => bool) private sanctionedAddresses; - - - function addToSanctionsList(address newSanction) public{ - sanctionedAddresses[newSanction] = true; - } - - function removeFromSanctionsList(address removeSanction) public{ - sanctionedAddresses[removeSanction] = true; - } - - function isSanctioned(address addr) public view returns (bool) { - return sanctionedAddresses[addr] == true ; - } -} \ No newline at end of file diff --git a/doc/test/v1.0.2/UML-test.svg b/doc/test/v1.0.2/UML-test.svg deleted file mode 100644 index 7e69a0d..0000000 --- a/doc/test/v1.0.2/UML-test.svg +++ /dev/null @@ -1,423 +0,0 @@ - - - - - - -UmlClassDiagram - - - -0 - -CMTATIntegration -test/CMTATIntegration.t.sol - -Public: -   TRANSFER_OK: uint8 -   TEXT_TRANSFER_OK: string -   ruleEngineMock: RuleEngine -   resUint256: uint256 -   resBool: bool -   ADDRESS1_BALANCE_INIT: uint256 -   ADDRESS2_BALANCE_INIT: uint256 -   ADDRESS3_BALANCE_INIT: uint256 -   FLAG: uint256 - -Public: -    setUp() -    testCannotTransferWithoutAddressWhitelisted() -    testCannotTransferWithoutFromAddressWhitelisted() -    testCannotTransferWithoutToAddressWhitelisted() -    testCanMakeATransfer() -    testDetectAndMessageWithFromNotWhitelisted() -    testDetectAndMessageWithToNotWhitelisted() -    testDetectAndMessageWithFromAndToNotWhitelisted() -    testDetectAndMessageWithAValidTransfer() -    testCanMint() - - - -1 - -<<Abstract>> -HelperContract -test/HelperContract.sol - -Public: -   ZERO_ADDRESS: address -   DEFAULT_ADMIN_ADDRESS: address -   WHITELIST_OPERATOR_ADDRESS: address -   RULE_ENGINE_OPERATOR_ADDRESS: address -   ATTACKER: address -   ADDRESS1: address -   ADDRESS2: address -   ADDRESS3: address -   RULE_ENGINE_ROLE_HASH: string -   WHITELIST_ROLE_HASH: string -   DEFAULT_ADMIN_ROLE_HASH: string -   ruleWhitelist: RuleWhitelist -   CMTAT_CONTRACT: CMTAT_STANDALONE -   RULE_ENGINE_ROLE: bytes32 -   TEXT_CODE_NOT_FOUND: string -   TEXT_ADDRESS_FROM_NOT_WHITELISTED: string -   TEXT_ADDRESS_TO_NOT_WHITELISTED: string -   CODE_ADDRESS_FROM_NOT_WHITELISTED: uint8 -   CODE_ADDRESS_TO_NOT_WHITELISTED: uint8 -   NO_ERROR: uint8 -   WHITELIST_ROLE: bytes32 - -Public: -    <<event>> AddRule(rule: IRule) -    <<event>> RemoveRule(rule: IRule) -    <<event>> ClearRules(rulesRemoved: IRule[]) -    constructor() - - - -0->1 - - - - - -9 - -RuleEngineAccessControlTest -test/RuleEngine/AccessControl/RuleEngineAccessControl.sol - -Public: -   ruleEngineMock: RuleEngine -   resUint8: uint8 -   resUint256: uint256 -   resBool: bool -   resString: string -   CODE_NONEXISTENT: uint8 - -Public: -    setUp() -    testCannnotAttackerSetRules() -    testCannnotAttackerClearRules() -    testCannotAttackerAddRule() -    testCannotAttackerRemoveRule() - - - -9->1 - - - - - -10 - -RuleEngineAccessControlTest -test/RuleEngine/AccessControl/RuleEngineAccessControlOZ.t.sol - -Public: -   ruleEngineMock: RuleEngine -   resUint8: uint8 -   resUint256: uint256 -   resBool: bool -   resString: string -   CODE_NONEXISTENT: uint8 - -Public: -    setUp() -    testCanGrantRoleAsAdmin() -    testRevokeRoleAsAdmin() -    testCannotGrantFromNonAdmin() -    testCannotRevokeFromNonAdmin() - - - -10->1 - - - - - -2 - -RuleEngineTest -test/RuleEngine/RuleEngine.t.sol - -Public: -   ruleEngineMock: RuleEngine -   resUint8: uint8 -   resUint256: uint256 -   resBool: bool -   resString: string -   CODE_NONEXISTENT: uint8 - -Public: -    setUp() -    testCanSetRules() -    testCannotSetRuleIfARuleIsAlreadyPresent() -    testCannotSetEmptyRulesT1() -    testCannotSetEmptyRulesT2() -    testCanClearRules() -    testCanAddRule() -    testCannotAddRuleZeroAddress() -    testCannotAddARuleAlreadyPresent() -    testCanAddARuleAfterThisRuleWasRemoved() -    testCanRemoveNonExistantRule() -    testCanRemoveLatestRule() -    testCanRemoveFirstRule() -    testCanRemoveRule() -    testRuleLength() -    testGetRule() -    testGetRules() -    testCanGetRuleIndex() - - - -2->1 - - - - - -3 - -RuleEngineTest -test/RuleEngine/RuleEngineDeployment.t.sol - -Public: -   ruleEngineMock: RuleEngine -   resUint8: uint8 -   resUint256: uint256 -   resBool: bool -   resString: string -   CODE_NONEXISTENT: uint8 - -Public: -    setUp() -    testRightDeployment() - - - -3->1 - - - - - -4 - -RuleEngineRestrictionTest -test/RuleEngine/RuleEngineRestriction.t.sol - -Public: -   ruleEngineMock: RuleEngine -   resUint8: uint8 -   resUint256: uint256 -   resBool: bool -   resString: string -   CODE_NONEXISTENT: uint8 -   ruleWhitelist1: RuleWhitelist - -Public: -    setUp() -    testCanDetectTransferRestrictionOK() -    testCanDetectTransferRestrictionWithFrom() -    testCanDetectTransferRestrictionWithTo() -    testMessageForTransferRestrictionWithValidRC() -    testMessageForTransferRestrictionNoRule() -    testMessageForTransferRestrictionWithUnknownRestrictionCode() -    testValidateTransferOK() -    testValidateTransferRestricted() - - - -4->1 - - - - - -11 - -RuleWhitelistAccessControl -test/RuleWhitelist/AccessControl/RuleWhitelistAccessControl.t.sol - -Public: -   TRANSFER_OK: uint8 -   TEXT_TRANSFER_OK: string -   resUint256: uint256 -   resUint8: uint8 -   resBool: bool -   resCallBool: bool -   resString: string -   CODE_NONEXISTENT: uint8 - -Public: -    setUp() -    testCannotAttackerAddAddressToTheWhitelist() -    testCannotAttackerAddAddressesToTheWhitelist() -    testCannotAttackerRemoveAddressFromTheWhitelist() -    testCannotAttackerRemoveAddressesFromTheWhitelist() - - - -11->1 - - - - - -12 - -RuleWhitelistAccessControlOZ -test/RuleWhitelist/AccessControl/RuleWhitelistAccessControlOZ.t.sol - -Public: -   TRANSFER_OK: uint8 -   TEXT_TRANSFER_OK: string -   resUint256: uint256 -   resUint8: uint8 -   resBool: bool -   resCallBool: bool -   resString: string -   CODE_NONEXISTENT: uint8 - -Public: -    setUp() -    testCanGrantRoleAsAdmin() -    testRevokeRoleAsAdmin() -    testCannotGrantFromNonAdmin() -    testCannotRevokeFromNonAdmin() - - - -12->1 - - - - - -5 - -RuleWhitelistAddTest -test/RuleWhitelist/RuleWhitelistAdd.t.sol - -Public: -   TRANSFER_OK: uint8 -   TEXT_TRANSFER_OK: string -   resUint256: uint256 -   resUint8: uint8 -   resBool: bool -   resCallBool: bool -   resString: string -   CODE_NONEXISTENT: uint8 - -Public: -    setUp() -    testAddAddressToTheWhitelist() -    testAddAddressesToTheWhitelist() -    testCanAddAddressZeroToTheWhitelist() -    testCanAddAddressesZeroToTheWhitelist() -    testAddAddressTwiceToTheWhitelist() -    testAddAddressesTwiceToTheWhitelist() - - - -5->1 - - - - - -6 - -RuleWhitelistRemoveTest -test/RuleWhitelist/RuleWhitelistRemove.t.sol - -Public: -   TRANSFER_OK: uint8 -   TEXT_TRANSFER_OK: string -   resUint256: uint256 -   resUint8: uint8 -   resBool: bool -   resCallBool: bool -   resString: string -   CODE_NONEXISTENT: uint8 - -Public: -    setUp() -    testRemoveAddressFromTheWhitelist() -    testRemoveAddressesFromTheWhitelist() -    testRemoveAddressNotPresentFromTheWhitelist() -    testRemoveAddressesNotPresentFromTheWhitelist() - - - -6->1 - - - - - -7 - -RuleWhitelistTest -test/RuleWhitelist/Rulewhitelist.t.sol - -Public: -   resUint256: uint256 -   resUint8: uint8 -   resBool: bool -   resCallBool: bool -   resString: string -   CODE_NONEXISTENT: uint8 - -Public: -    setUp() -    testReturnFalseIfAddressNotWhitelisted() -    testAddressIsIndicatedAsWhitelisted() -    testAddressesIsIndicatedAsWhitelisted() -    testCanReturnTransferRestrictionCode() -    testReturnTheRightMessageForAGivenCode() -    testValidateTransfer() -    testTransferDetectedAsInvalid() -    testNumberWhitelistedAddress() -    testDetectTransferRestrictionFrom() -    testDetectTransferRestrictionTo() -    testDetectTransferRestrictionOk() - - - -7->1 - - - - - -8 - -RuleWhitelistTest -test/RuleWhitelist/RulewhitelistDeployment.t.sol - -Public: -   resUint256: uint256 -   resUint8: uint8 -   resBool: bool -   resCallBool: bool -   resString: string -   CODE_NONEXISTENT: uint8 - -Public: -    setUp() -    testRightDeployment() - - - -8->1 - - - - - diff --git a/doc/test/v1.0.2/coverage-2023-05-23.png b/doc/test/v1.0.2/coverage-2023-05-23.png deleted file mode 100644 index fd893ad..0000000 Binary files a/doc/test/v1.0.2/coverage-2023-05-23.png and /dev/null differ diff --git a/doc/test/v1.0.2/lcov-2023-22.05.info b/doc/test/v1.0.2/lcov-2023-22.05.info deleted file mode 100644 index ec07d75..0000000 --- a/doc/test/v1.0.2/lcov-2023-22.05.info +++ /dev/null @@ -1,248 +0,0 @@ -TN: -SF:script/CMTATWithRuleEngineScript.s.sol -FN:14,CMTATWithRuleEngineScript.run -FNDA:0,CMTATWithRuleEngineScript.run -DA:16,0 -DA:17,0 -DA:18,0 -DA:19,0 -DA:20,0 -DA:22,0 -DA:33,0 -DA:35,0 -DA:39,0 -DA:41,0 -DA:42,0 -DA:43,0 -DA:44,0 -DA:46,0 -FNF:1 -FNH:0 -LF:14 -LH:0 -BRF:0 -BRH:0 -end_of_record -TN: -SF:script/RuleEngineScript.s.sol -FN:16,RuleEngineScript.run -FNDA:0,RuleEngineScript.run -DA:18,0 -DA:19,0 -DA:20,0 -DA:21,0 -DA:23,0 -DA:24,0 -DA:26,0 -DA:27,0 -DA:28,0 -DA:30,0 -DA:33,0 -BRDA:33,0,0,- -BRDA:33,0,1,- -DA:34,0 -FNF:1 -FNH:0 -LF:12 -LH:0 -BRF:2 -BRH:0 -end_of_record -TN: -SF:src/RuleEngine.sol -FN:43,RuleEngine.setRules -FNDA:10,RuleEngine.setRules -DA:46,9 -BRDA:46,0,0,1 -BRDA:46,0,1,8 -DA:47,8 -DA:48,15 -BRDA:48,1,0,1 -BRDA:48,1,1,14 -DA:52,14 -BRDA:52,2,0,1 -BRDA:52,2,1,13 -DA:53,13 -DA:54,13 -DA:56,13 -DA:59,6 -FN:66,RuleEngine.clearRules -FNDA:3,RuleEngine.clearRules -DA:67,2 -DA:68,2 -FN:76,RuleEngine.addRule -FNDA:9,RuleEngine.addRule -DA:77,8 -BRDA:77,3,0,1 -BRDA:77,3,1,7 -DA:81,7 -BRDA:81,4,0,1 -BRDA:81,4,1,6 -DA:82,6 -DA:83,6 -DA:84,6 -FN:97,RuleEngine.removeRule -FNDA:6,RuleEngine.removeRule -DA:101,5 -BRDA:101,5,0,1 -BRDA:101,5,1,4 -DA:102,4 -BRDA:102,6,0,- -BRDA:102,6,1,2 -DA:103,2 -DA:105,4 -DA:106,4 -DA:107,4 -FN:113,RuleEngine.rulesCount -FNDA:20,RuleEngine.rulesCount -DA:114,20 -FN:121,RuleEngine.getRuleIndex -FNDA:3,RuleEngine.getRuleIndex -DA:122,0 -DA:123,5 -BRDA:123,7,0,3 -BRDA:123,7,1,3 -DA:124,5 -DA:127,3 -DA:130,1 -FN:138,RuleEngine.rule -FNDA:1,RuleEngine.rule -DA:139,1 -FN:146,RuleEngine.rules -FNDA:4,RuleEngine.rules -DA:147,4 -FN:157,RuleEngine.detectTransferRestriction -FNDA:7,RuleEngine.detectTransferRestriction -DA:162,17 -DA:163,17 -DA:168,17 -BRDA:168,8,0,12 -BRDA:168,8,1,5 -DA:169,12 -DA:172,5 -DA:175,5 -FN:185,RuleEngine.validateTransfer -FNDA:10,RuleEngine.validateTransfer -DA:190,10 -FN:198,RuleEngine.messageForTransferRestriction -FNDA:6,RuleEngine.messageForTransferRestriction -DA:201,6 -DA:202,5 -BRDA:202,9,0,- -BRDA:202,9,1,4 -DA:203,4 -DA:207,1 -DA:210,2 -FN:216,RuleEngine._msgSender -FNDA:38,RuleEngine._msgSender -DA:222,38 -FN:228,RuleEngine._msgData -FNDA:0,RuleEngine._msgData -DA:234,0 -FNF:13 -FNH:12 -LF:43 -LH:41 -BRF:20 -BRH:18 -end_of_record -TN: -SF:src/RuleWhitelist.sol -FN:49,RuleWhitelist.addAddressesToTheWhitelist -FNDA:13,RuleWhitelist.addAddressesToTheWhitelist -DA:52,12 -DA:53,12 -DA:54,26 -BRDA:54,0,0,- -BRDA:54,0,1,24 -DA:55,24 -DA:56,24 -DA:59,26 -DA:62,12 -FN:71,RuleWhitelist.removeAddressesFromTheWhitelist -FNDA:4,RuleWhitelist.removeAddressesFromTheWhitelist -DA:74,3 -DA:75,3 -DA:76,7 -BRDA:76,1,0,- -BRDA:76,1,1,6 -DA:77,6 -DA:78,6 -DA:81,7 -DA:84,3 -FN:92,RuleWhitelist.addAddressToTheWhitelist -FNDA:22,RuleWhitelist.addAddressToTheWhitelist -DA:95,21 -BRDA:95,2,0,1 -BRDA:95,2,1,20 -DA:99,20 -DA:100,20 -FN:109,RuleWhitelist.removeAddressFromTheWhitelist -FNDA:3,RuleWhitelist.removeAddressFromTheWhitelist -DA:112,2 -BRDA:112,3,0,1 -BRDA:112,3,1,1 -DA:116,1 -DA:117,1 -FN:125,RuleWhitelist.numberWhitelistedAddress -FNDA:20,RuleWhitelist.numberWhitelistedAddress -DA:126,20 -FN:135,RuleWhitelist.addressIsWhitelisted -FNDA:50,RuleWhitelist.addressIsWhitelisted -DA:138,50 -FN:148,RuleWhitelist.validateTransfer -FNDA:3,RuleWhitelist.validateTransfer -DA:153,3 -FN:164,RuleWhitelist.detectTransferRestriction -FNDA:20,RuleWhitelist.detectTransferRestriction -DA:169,23 -BRDA:169,4,0,11 -BRDA:169,4,1,12 -DA:170,11 -DA:171,12 -BRDA:171,5,0,4 -BRDA:171,5,1,8 -DA:172,4 -DA:174,8 -FN:183,RuleWhitelist.canReturnTransferRestrictionCode -FNDA:8,RuleWhitelist.canReturnTransferRestrictionCode -DA:186,8 -FN:196,RuleWhitelist.messageForTransferRestriction -FNDA:7,RuleWhitelist.messageForTransferRestriction -DA:199,7 -BRDA:199,6,0,4 -BRDA:199,6,1,3 -DA:200,4 -DA:201,3 -BRDA:201,7,0,2 -BRDA:201,7,1,1 -DA:202,2 -DA:204,1 -FN:211,RuleWhitelist._msgSender -FNDA:52,RuleWhitelist._msgSender -DA:217,52 -FN:223,RuleWhitelist._msgData -FNDA:0,RuleWhitelist._msgData -DA:229,0 -FNF:12 -FNH:11 -LF:36 -LH:35 -BRF:16 -BRH:14 -end_of_record -TN: -SF:src/modules/MetaTxModuleStandalone.sol -FN:15,MetaTxModuleStandalone._msgSender -FNDA:90,MetaTxModuleStandalone._msgSender -DA:22,90 -FN:25,MetaTxModuleStandalone._msgData -FNDA:0,MetaTxModuleStandalone._msgData -DA:32,0 -FNF:2 -FNH:1 -LF:2 -LH:1 -BRF:0 -BRH:0 -end_of_record diff --git a/doc/test/v1.0.2/test.odt b/doc/test/v1.0.2/test.odt deleted file mode 100644 index aebe3af..0000000 Binary files a/doc/test/v1.0.2/test.odt and /dev/null differ diff --git a/doc/test/v1.0.2/test.pdf b/doc/test/v1.0.2/test.pdf deleted file mode 100644 index fa300f4..0000000 Binary files a/doc/test/v1.0.2/test.pdf and /dev/null differ diff --git a/remappings.txt b/remappings.txt index fcc5cc3..abeed5c 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,2 +1,3 @@ CMTAT/=lib/CMTAT/contracts/ +RuleEngine/=lib/RuleEngine/src/ OZ/=lib/openzeppelin-contracts/contracts/ \ No newline at end of file diff --git a/src/DebtVault.sol b/src/DebtVault.sol index 9ec4e7c..d1d305e 100644 --- a/src/DebtVault.sol +++ b/src/DebtVault.sol @@ -2,17 +2,12 @@ pragma solidity ^0.8.20; - import "OZ/token/ERC20/IERC20.sol"; import "OZ/token/ERC20/utils/SafeERC20.sol"; import "OZ/utils/ReentrancyGuard.sol"; import "CMTAT/interfaces/ICMTATSnapshot.sol"; -import "CMTAT/interfaces/ICMTATSnapshot.sol"; -//import "CMTAT/modules/internal/ValidationModuleInternal.sol"; -import "CMTAT/modules/wrapper/controllers/ValidationModule.sol"; import "CMTAT/modules/wrapper/controllers/ValidationModule.sol"; import "CMTAT/modules/wrapper/extensions/MetaTxModule.sol"; -//import "./modules/AuthorizationModuleStandalone.sol"; import "./invariantStorage/DebtVaultInvariantStorage.sol"; diff --git a/src/modules/AuthorizationModuleStandalone.sol b/src/modules/AuthorizationModuleStandalone.sol deleted file mode 100644 index e05da7f..0000000 --- a/src/modules/AuthorizationModuleStandalone.sol +++ /dev/null @@ -1,23 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "OZ/access/AccessControl.sol"; - -abstract contract AuthorizationModuleStandalone is AccessControl{ - - - /* - * @dev Returns `true` if `account` has been granted `role`. - */ - function hasRole( - bytes32 role, - address account - ) public view virtual override(AccessControl) returns (bool) { - // The Default Admin has all roles - if (AccessControl.hasRole(DEFAULT_ADMIN_ROLE, account)) { - return true; - } - return AccessControl.hasRole(role, account); - } -} \ No newline at end of file diff --git a/src/modules/MetaTxModuleStandalone.sol b/src/modules/MetaTxModuleStandalone.sol deleted file mode 100644 index a234a35..0000000 --- a/src/modules/MetaTxModuleStandalone.sol +++ /dev/null @@ -1,14 +0,0 @@ -//SPDX-License-Identifier: MPL-2.0 - -pragma solidity ^0.8.20; - -import "OZ/metatx/ERC2771Context.sol"; - -/** - * @dev Meta transaction (gasless) module. - */ -abstract contract MetaTxModuleStandalone is ERC2771Context { - constructor(address trustedForwarder) ERC2771Context(trustedForwarder) { - // Nothing to do - } -} diff --git a/surya_graph_DebtVault.png b/surya_graph_DebtVault.png deleted file mode 100644 index 0fab6b3..0000000 Binary files a/surya_graph_DebtVault.png and /dev/null differ diff --git a/test/DebtVault.t.sol b/test/DebtVault.t.sol index e0b170a..909410a 100644 --- a/test/DebtVault.t.sol +++ b/test/DebtVault.t.sol @@ -5,8 +5,7 @@ import "forge-std/Test.sol"; import "./HelperContract.sol"; import "CMTAT/interfaces/engine/IRuleEngine.sol"; import "CMTAT/interfaces/engine/IAuthorizationEngine.sol"; -import "OZ/token/ERC20/IERC20.sol"; -import "OZ/token/ERC20/ERC20.sol"; + /** * @title Test for DebtVault */ @@ -17,21 +16,12 @@ contract debtVaultTest is Test, HelperContract { bool resCallBool; string resString; uint8 CODE_NONEXISTENT = 255; - // Contracts - CMTAT_STANDALONE tokenPayment; - DebtVault debtVault; - // CMTAT value - uint256 FLAG = 5; - uint8 DECIMALS = 0; - uint256 ADDRESS1_INITIAL_AMOUNT = 5000; - uint256 CMTAT_ADMIN_INITIAL_AMOUNT = 5000; + // ADMIN balance payment uint256 tokenBalance = 5000; - uint256 defaultSnapshotTime = block.timestamp + 50; - uint256 defaultDepositAmount = 2000; // Arrange function setUp() public { // Deploy CMTAT diff --git a/test/HelperContract.sol b/test/HelperContract.sol index ae10ffa..e8882bf 100644 --- a/test/HelperContract.sol +++ b/test/HelperContract.sol @@ -5,8 +5,12 @@ import "forge-std/Test.sol"; import "CMTAT/CMTAT_STANDALONE.sol"; import "../src/DebtVault.sol"; import "../src/invariantStorage/DebtVaultInvariantStorage.sol"; +import "RuleEngine/RuleEngine.sol"; +import "RuleEngine/rules/validation/RuleWhitelist.sol"; +import "OZ/token/ERC20/IERC20.sol"; +import "OZ/token/ERC20/ERC20.sol"; /** -@title Constants used by the tests +* @title Constants used by the tests */ abstract contract HelperContract is DebtVaultInvariantStorage { // EOA to perform tests @@ -41,5 +45,18 @@ abstract contract HelperContract is DebtVaultInvariantStorage { // Forwarder string ERC2771ForwarderDomain = 'ERC2771ForwarderDomain'; + + // Contracts + CMTAT_STANDALONE tokenPayment; + DebtVault debtVault; + // CMTAT value + uint256 FLAG = 5; + uint8 DECIMALS = 0; + uint256 ADDRESS1_INITIAL_AMOUNT = 5000; + uint256 CMTAT_ADMIN_INITIAL_AMOUNT = 5000; + + + uint256 defaultSnapshotTime = block.timestamp + 50; + uint256 defaultDepositAmount = 2000; constructor() {} } diff --git a/test/RuleEngineIntegration.t.sol b/test/RuleEngineIntegration.t.sol index bdfda89..579ad66 100644 --- a/test/RuleEngineIntegration.t.sol +++ b/test/RuleEngineIntegration.t.sol @@ -1,20 +1,22 @@ // SPDX-License-Identifier: MPL-2.0 pragma solidity ^0.8.20; -import "forge-std/Test.sol"; -import "CMTAT/CMTAT_STANDALONE.sol"; + import "./HelperContract.sol"; -import "src/RuleEngine.sol"; +import "RuleEngine/rules/validation/abstract/RuleAddressList/RuleWhitelistInvariantStorage.sol"; /** -@title Integration test with the CMTAT +* @title Integration test with the CMTAT */ -contract RuleEngineIntegration is Test, HelperContract { +contract RuleEngineIntegration is RuleWhitelistInvariantStorage, Test, HelperContract { // Defined in CMTAT.sol uint8 constant TRANSFER_OK = 0; string constant TEXT_TRANSFER_OK = "No restriction"; - + // Contracts RuleEngine ruleEngineMock; + RuleWhitelist ruleWhitelist; + + // Other variable uint256 resUint256; bool resBool; @@ -22,18 +24,17 @@ contract RuleEngineIntegration is Test, HelperContract { uint256 ADDRESS2_BALANCE_INIT = 32; uint256 ADDRESS3_BALANCE_INIT = 33; - uint256 FLAG = 5; - + uint256 tokenBalance = 5000; // Arrange function setUp() public { vm.prank(DEFAULT_ADMIN_ADDRESS); ruleWhitelist = new RuleWhitelist(DEFAULT_ADMIN_ADDRESS, ZERO_ADDRESS); // global arrange uint8 decimals = 0; - vm.prank(DEFAULT_ADMIN_ADDRESS); + vm.prank(CMTAT_ADMIN); CMTAT_CONTRACT = new CMTAT_STANDALONE( ZERO_ADDRESS, - DEFAULT_ADMIN_ADDRESS, + CMTAT_ADMIN, IAuthorizationEngine(address(0)), "CMTA Token", "CMTAT", @@ -50,95 +51,185 @@ contract RuleEngineIntegration is Test, HelperContract { ruleEngineMock = new RuleEngine(DEFAULT_ADMIN_ADDRESS, ZERO_ADDRESS); vm.prank(DEFAULT_ADMIN_ADDRESS); ruleEngineMock.addRuleValidation(ruleWhitelist); + + // Token payment + tokenPayment = new CMTAT_STANDALONE( + ZERO_ADDRESS, + TOKEN_PAYMENT_ADMIN, + IAuthorizationEngine(address(0)), + "CMTA Token", + "CMTAT", + DECIMALS, + "CMTAT_ISIN", + "https://cmta.ch", + IRuleEngine(address(0)), + "CMTAT_info", + FLAG + ); + + // Deploy DebtVault + debtVault = new DebtVault( + ZERO_ADDRESS + ); + debtVault.initialize( + DEFAULT_ADMIN_ADDRESS, + tokenPayment, + ICMTATSnapshot(address(CMTAT_CONTRACT)), + IRuleEngine(ZERO_ADDRESS), + IAuthorizationEngine(ZERO_ADDRESS) + ); + + // We set the Rule Engine vm.prank(DEFAULT_ADMIN_ADDRESS); - CMTAT_CONTRACT.mint(ADDRESS1, ADDRESS1_BALANCE_INIT); - vm.prank(DEFAULT_ADMIN_ADDRESS); - CMTAT_CONTRACT.mint(ADDRESS2, ADDRESS2_BALANCE_INIT); + debtVault.setRuleEngine(ruleEngineMock); + /** + vm.prank(CMTAT_ADMIN); + CMTAT_CONTRACT.mint(DEFAULT_ADMIN_ADDRESS, ADDRESS1_INITIAL_AMOUNT); + */ + vm.prank(TOKEN_PAYMENT_ADMIN); + tokenPayment.mint(DEFAULT_ADMIN_ADDRESS, tokenBalance); + } + + function _performOnlyDeposit() internal { + // Allowance vm.prank(DEFAULT_ADMIN_ADDRESS); - CMTAT_CONTRACT.mint(ADDRESS3, ADDRESS3_BALANCE_INIT); + tokenPayment.approve(address(debtVault), defaultDepositAmount); + // Act vm.prank(DEFAULT_ADMIN_ADDRESS); - // We set the Rule Engine - CMTAT_CONTRACT.setRuleEngine(ruleEngineMock); + debtVault.deposit(defaultSnapshotTime, defaultDepositAmount); + } + + function _performDeposit() internal { + _performOnlyDeposit(); + // Configure snapshot + + vm.prank(CMTAT_ADMIN); + CMTAT_CONTRACT.scheduleSnapshot(defaultSnapshotTime); + + // Mint token for Address 1 + vm.prank(CMTAT_ADMIN); + CMTAT_CONTRACT.mint(ADDRESS1, ADDRESS1_INITIAL_AMOUNT); } /******* Transfer *******/ - function testCannotTransferWithoutAddressWhitelisted() public { + function testCannotClaimWithoutAddressWhitelisted() public { // Arrange - vm.prank(ADDRESS1); - vm.expectRevert( - abi.encodeWithSelector(Errors.CMTAT_InvalidTransfer.selector, ADDRESS1, ADDRESS2, 21)); + _performDeposit(); // Act - CMTAT_CONTRACT.transfer(ADDRESS2, 21); + // Open claim + vm.prank(DEFAULT_ADMIN_ADDRESS); + debtVault.setStatusClaim(defaultSnapshotTime, true); + + // Contract pause + vm.prank(DEFAULT_ADMIN_ADDRESS); + debtVault.pause(); + + // Act + // Claim deposit + vm.expectRevert( + abi.encodeWithSelector(Errors.CMTAT_InvalidTransfer.selector, address(debtVault), ADDRESS1, defaultDepositAmount)); + vm.prank(ADDRESS1); + debtVault.claimDividend(defaultSnapshotTime); } function testCannotTransferWithoutFromAddressWhitelisted() public { // Arrange - uint256 amount = 21; vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS2); + ruleWhitelist.addAddressToTheList(address(debtVault)); - vm.prank(ADDRESS1); - vm.expectRevert( - abi.encodeWithSelector(Errors.CMTAT_InvalidTransfer.selector, ADDRESS1, ADDRESS2, amount)); + // Arrange + _performDeposit(); + // Act + // Open claim + vm.prank(DEFAULT_ADMIN_ADDRESS); + debtVault.setStatusClaim(defaultSnapshotTime, true); + + // Contract pause + vm.prank(DEFAULT_ADMIN_ADDRESS); + debtVault.pause(); + // Act - CMTAT_CONTRACT.transfer(ADDRESS2, amount); + // Claim deposit + vm.expectRevert( + abi.encodeWithSelector(Errors.CMTAT_InvalidTransfer.selector, address(debtVault), ADDRESS1, defaultDepositAmount)); + vm.prank(ADDRESS1); + debtVault.claimDividend(defaultSnapshotTime); } function testCannotTransferWithoutToAddressWhitelisted() public { // Arrange - uint256 amount = 21; vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); + ruleWhitelist.addAddressToTheList(ADDRESS1); - vm.prank(ADDRESS1); - vm.expectRevert( - abi.encodeWithSelector(Errors.CMTAT_InvalidTransfer.selector, ADDRESS1, ADDRESS2, amount)); + // Arrange + _performDeposit(); // Act - CMTAT_CONTRACT.transfer(ADDRESS2, amount); + // Open claim + vm.prank(DEFAULT_ADMIN_ADDRESS); + debtVault.setStatusClaim(defaultSnapshotTime, true); + + // Contract pause + vm.prank(DEFAULT_ADMIN_ADDRESS); + debtVault.pause(); + + // Act + // Claim deposit + vm.expectRevert( + abi.encodeWithSelector(Errors.CMTAT_InvalidTransfer.selector, address(debtVault), ADDRESS1, defaultDepositAmount)); + vm.prank(ADDRESS1); + debtVault.claimDividend(defaultSnapshotTime); } function testCanMakeATransfer() public { // Arrange address[] memory whitelist = new address[](2); whitelist[0] = ADDRESS1; - whitelist[1] = ADDRESS2; + whitelist[1] = address(debtVault); vm.prank(DEFAULT_ADMIN_ADDRESS); (bool success, ) = address(ruleWhitelist).call( abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", + "addAddressesToTheList(address[])", whitelist ) ); require(success); - vm.prank(ADDRESS1); - + // Act - CMTAT_CONTRACT.transfer(ADDRESS2, 11); + // Arrange + _performDeposit(); - // Assert - resUint256 = CMTAT_CONTRACT.balanceOf(ADDRESS1); - assertEq(resUint256, 20); - resUint256 = CMTAT_CONTRACT.balanceOf(ADDRESS2); - assertEq(resUint256, 43); - resUint256 = CMTAT_CONTRACT.balanceOf(ADDRESS3); - assertEq(resUint256, 33); + // Timeout + uint256 timeout = defaultSnapshotTime + 50; + vm.warp(timeout); + + // Open claim + vm.prank(DEFAULT_ADMIN_ADDRESS); + debtVault.setStatusClaim(defaultSnapshotTime, true); + + // Claim deposit + vm.prank(ADDRESS1); + debtVault.claimDividend(defaultSnapshotTime); + + // Check balance + resUint256 = tokenPayment.balanceOf(ADDRESS1); + assertEq(resUint256, defaultDepositAmount); } /******* detectTransferRestriction & messageForTransferRestriction *******/ function testDetectAndMessageWithFromNotWhitelisted() public { vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS2); - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS2); + ruleWhitelist.addAddressToTheList(ADDRESS2); + resBool = ruleWhitelist.addressIsListed(ADDRESS2); // Assert assertEq(resBool, true); - uint8 res1 = CMTAT_CONTRACT.detectTransferRestriction( + uint8 res1 = debtVault.detectTransferRestriction( ADDRESS1, ADDRESS2, 11 ); // Assert assertEq(res1, CODE_ADDRESS_FROM_NOT_WHITELISTED); - string memory message1 = CMTAT_CONTRACT.messageForTransferRestriction( + string memory message1 = debtVault.messageForTransferRestriction( res1 ); // Assert @@ -149,12 +240,12 @@ contract RuleEngineIntegration is Test, HelperContract { // Arrange // We add the sender to the whitelist vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); + ruleWhitelist.addAddressToTheList(ADDRESS1); // Arrange - Assert - resBool = ruleWhitelist.addressIsWhitelisted(ADDRESS1); + resBool = ruleWhitelist.addressIsListed(ADDRESS1); assertEq(resBool, true); // Act - uint8 res1 = CMTAT_CONTRACT.detectTransferRestriction( + uint8 res1 = debtVault.detectTransferRestriction( ADDRESS1, ADDRESS2, 11 @@ -162,7 +253,7 @@ contract RuleEngineIntegration is Test, HelperContract { // Assert assertEq(res1, CODE_ADDRESS_TO_NOT_WHITELISTED); // Act - string memory message1 = CMTAT_CONTRACT.messageForTransferRestriction( + string memory message1 = debtVault.messageForTransferRestriction( res1 ); // Assert @@ -171,7 +262,7 @@ contract RuleEngineIntegration is Test, HelperContract { function testDetectAndMessageWithFromAndToNotWhitelisted() public { // Act - uint8 res1 = CMTAT_CONTRACT.detectTransferRestriction( + uint8 res1 = debtVault.detectTransferRestriction( ADDRESS1, ADDRESS2, 11 @@ -180,7 +271,7 @@ contract RuleEngineIntegration is Test, HelperContract { // Assert assertEq(res1, CODE_ADDRESS_FROM_NOT_WHITELISTED); // Act - string memory message1 = CMTAT_CONTRACT.messageForTransferRestriction( + string memory message1 = debtVault.messageForTransferRestriction( res1 ); @@ -197,13 +288,13 @@ contract RuleEngineIntegration is Test, HelperContract { vm.prank(DEFAULT_ADMIN_ADDRESS); (bool success, ) = address(ruleWhitelist).call( abi.encodeWithSignature( - "addAddressesToTheWhitelist(address[])", + "addAddressesToTheList(address[])", whitelist ) ); require(success); // Act - uint8 res1 = CMTAT_CONTRACT.detectTransferRestriction( + uint8 res1 = debtVault.detectTransferRestriction( ADDRESS1, ADDRESS2, 11 @@ -211,30 +302,10 @@ contract RuleEngineIntegration is Test, HelperContract { // Assert assertEq(res1, TRANSFER_OK); // Act - string memory message1 = CMTAT_CONTRACT.messageForTransferRestriction( + string memory message1 = debtVault.messageForTransferRestriction( res1 ); // Assert assertEq(message1, TEXT_TRANSFER_OK); } - - function testCanMint() public { - // Arrange - // Add address zero to the whitelist - vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ZERO_ADDRESS); - vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleWhitelist.addAddressToTheWhitelist(ADDRESS1); - // Arrange - Assert - resBool = ruleWhitelist.addressIsWhitelisted(ZERO_ADDRESS); - assertEq(resBool, true); - - // Act - vm.prank(DEFAULT_ADMIN_ADDRESS); - CMTAT_CONTRACT.mint(ADDRESS1, 11); - - // Assert - resUint256 = CMTAT_CONTRACT.balanceOf(ADDRESS1); - assertEq(resUint256, ADDRESS1_BALANCE_INIT + 11); - } }