Files
Mohamad HammoudandGitHub 94182deb9c ✨ BT-1418 integrate foundry & hardhat + migrating solidity tests (#76)
* ✨ integrate foundry alongside hardhat for dual testing framework

- Add foundry.toml configuration
- Reorganize test structure: test/forge/ and test/hardhat/
- Add Foundry scripts to package.json (build:forge, test:forge, coverage:forge)
- Update hardhat.config.ts with evmVersion for compatibility
- Add GitHub workflows and coverage scripts from template
- Add Husky hooks (pre-commit, post-checkout, post-merge)
- Add .vscode/settings.json for better IDE support
- Disable coverage checks until tests are migrated (commented with TODO)

This migration is based on TokenySolutions/contracts-template and enables
gradual migration of tests from Hardhat (TypeScript) to Foundry (Solidity).

Related to: BT-1418

* ✅ trex factory tests

* ⚰️ remove trex suit

* feat(forge): reorganize Foundry test structure and sync GitHub workflows

- Move TREXFactorySetup to helpers folder
- Rename TREXSuite.t.sol to TREXFactory.t.sol
- Update fixture to inherit from Test for proper Foundry pattern
- Transfer ownership to deployer address to match Hardhat behavior
- Sync GitHub workflows with package.json scripts
- Update test.yml to use npm run build and npm run test
- Update push_checking.yml to use unified npm run lint
- Update forge_coverage.sh to use npm run coverage

* fix(ci): install Foundry and skip husky in push_checking workflow

- Add Foundry installation step before npm ci
- Set HUSKY=0 to skip husky setup in CI environment
- Fixes 'forge: not found' error during npm prepare script

* 🔧 keep hardhat settings

* ✅ create addressess directly

* ✅ removed test_StandardAddressesSet

* ✅ fix lint

* 💡 removed title natspecs

* ✅ migrated trex factort tests

* ✅ added test module multicall

* ✅ migrate agent role test

* ✅ migrate claim topics registry

* ✅ migrated trusted issuer registry

* ✅ migrate identity registry storage

* ✅ migrated identity registry tests

* ✅ migrated implementation authority test

* ✅ migrated token agen restrictions

* ✅ migrated token information test

* ✅ migrated token recover

* ✅ migrated token permit

* ✅ migrated token transfer

* ✅ migrated utilities upgrade

* ✅ migrated freeze check

* ✅ migrated compliance check in utilities test

* ✅ migrated eligibility check

* ✅ migrated transfer check in utilities

* ✅ migrated compliance test

* ✅ migrated gateway tests

* 🔥 removed already defined events

* 🗑️ imported Initializable error from openzeppelin

* ➕ added already defined events and errors

* ✅ added base test token

* ✅ used idFactory

* ♻️ refactored compliance test

* ⚰️ remoced useless vm.prank

* 🔧 deleted hardhat configurations

* 💚 fixed ci

* refactor: remove 100% coverage requirement from forge_coverage.sh

- Remove strict 100% coverage checks that were causing workflow failures
- Script now only generates and displays coverage report without failing
- Aligns with previous behavior where coverage was informational only

* ✅ resolve getVerifiedDetails

* ✅ applied _getEligibility and remove via-ir from foundry.toml

* ✅ cover tokena and token permit

* ✅ cover compliance

* ✅ cover identity registry

* ✅ increased trex gateway coverage

* ✅ increase coverage for trex factory

* ✅ increased AbstractModuleUpgradeable.sol coverage

* ⚰️ removed abstract module

* 🔧 updted generate coverage

* ✅ coverage 100% identity registry

* ✅ coverage 100% trex gate way

* ✅ coverage trex factory

* ✅ coverage 100% AbstractModuleUpgradeable by test module

* ✅ coverage IAFactory.sol

* ✅ coverage 100% for implementation authority

* ✅ coverage 1005 abstract proxy

* ✅ coverage 100% claim topic registry

* ✅ coverage 100% identity registry storage

* ✅ coverage 100% modular compliance proxy

* ✅ coverage trusted issuer registry proxy

* ✅ coverage 100% identity registry

* ✅ coverage 100% token proxy

* 🚨 resolve linter in token information

* ✅ coverage 100% roles

* 🚨 resolve linter

* 🔧 added no coverage for test, _testContracts and  utils

* ✅ coverage 100% for token.sol

* ✅ coverage 100% for modular compliance

* ✅ coverage 100% trusted issuer registry

* 🔧 restore package.json

* ✅ coverage 100% for utlity checker

* 🚨 fix linter
2025-12-31 16:58:16 +08:00

319 lines
13 KiB
Solidity

// SPDX-License-Identifier: GPL-3.0
//
// :+#####%%%%%%%%%%%%%%+
// .-*@@@%+.:+%@@@@@%%#***%@@%=
// :=*%@@@#=. :#@@% *@@@%=
// .-+*%@%*-.:+%@@@@@@+. -*+: .=#. :%@@@%-
// :=*@@@@%%@@@@@@@@@%@@@- .=#@@@%@%= =@@@@#.
// -=+#%@@%#*=:. :%@@@@%. -*@@#*@@@@@@@#=:- *@@@@+
// =@@%=:. :=: *@@@@@%#- =%*%@@@@#+-. =+ :%@@@%-
// -@@%. .+@@@ =+=-. @@#- +@@@%- =@@@@%:
// :@@@. .+@@#%: : .=*=-::.-%@@@+*@@= +@@@@#.
// %@@: +@%%* =%@@@@@@@@@@@#. .*@%- +@@@@*.
// #@@= .+@@@@%:=*@@@@@- :%@%: .*@@@@+
// *@@* +@@@#-@@%-:%@@* +@@#. :%@@@@-
// -@@% .:-=++*##%%%@@@@@@@@@@@@*. :@+.@@@%: .#@@+ =@@@@#:
// .@@@*-+*#%%%@@@@@@@@@@@@@@@@%%#**@@%@@@. *@=*@@# :#@%= .#@@@@#-
// -%@@@@@@@@@@@@@@@*+==-:-@@@= *@# .#@*-=*@@@@%= -%@@@* =@@@@@%-
// -+%@@@#. %@%%= -@@:+@: -@@* *@@*-:: -%@@%=. .*@@@@@#
// *@@@* +@* *@@##@@- #@*@@+ -@@= . :+@@@#: .-+@@@%+-
// +@@@%*@@:..=@@@@* .@@@* .#@#. .=+- .=%@@@*. :+#@@@@*=:
// =@@@@%@@@@@@@@@@@@@@@@@@@@@@%- :+#*. :*@@@%=. .=#@@@@%+:
// .%@@= ..... .=#@@+. .#@@@*: -*%@@@@%+.
// +@@#+===---:::... .=%@@*- +@@@+. -*@@@@@%+.
// -@@@@@@@@@@@@@@@@@@@@@@%@@@@= -@@@+ -#@@@@@#=.
// ..:::---===+++***###%%%@@@#- .#@@+ -*@@@@@#=.
// @@@@@@+. +@@*. .+@@@@@%=.
// -@@@@@= =@@%: -#@@@@%+.
// +@@@@@. =@@@= .+@@@@@*:
// #@@@@#:%@@#. :*@@@@#-
// @@@@@%@@@= :#@@@@+.
// :@@@@@@@#.:#@@@%-
// +@@@@@@-.*@@@*:
// #@@@@#.=@@@+.
// @@@@+-%@%=
// :@@@#%@%=
// +@@@@%-
// :#%%=
//
/**
* NOTICE
*
* The T-REX software is licensed under a proprietary license or the GPL v.3.
* If you choose to receive it under the GPL v.3 license, the following applies:
* T-REX is a suite of smart contracts implementing the ERC-3643 standard and
* developed by Tokeny to manage and transfer financial assets on EVM blockchains
*
* Copyright (C) 2025, Tokeny sàrl.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity 0.8.30;
import "@onchain-id/solidity/contracts/interface/IClaimIssuer.sol";
import "@onchain-id/solidity/contracts/interface/IIdentity.sol";
import "../../errors/InvalidArgumentErrors.sol";
import "../../roles/AgentRoleUpgradeable.sol";
import "../../roles/IERC173.sol";
import "../interface/IClaimTopicsRegistry.sol";
import "../interface/IIdentityRegistry.sol";
import "../interface/IIdentityRegistryStorage.sol";
import "../interface/ITrustedIssuersRegistry.sol";
import "../storage/IRStorage.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/// error triggered when eligibility checks are disabled and the disable function is called
error EligibilityChecksDisabledAlready();
/// error triggered when eligibility checks are enabled and the enable function is called
error EligibilityChecksEnabledAlready();
contract IdentityRegistry is IIdentityRegistry, AgentRoleUpgradeable, IRStorage, IERC165 {
constructor() {
_disableInitializers();
}
/**
* @dev the constructor initiates the Identity Registry smart contract
* @param _trustedIssuersRegistry the trusted issuers registry linked to the Identity Registry
* @param _claimTopicsRegistry the claim topics registry linked to the Identity Registry
* @param _identityStorage the identity registry storage linked to the Identity Registry
* emits a `ClaimTopicsRegistrySet` event
* emits a `TrustedIssuersRegistrySet` event
* emits an `IdentityStorageSet` event
*/
function init(address _trustedIssuersRegistry, address _claimTopicsRegistry, address _identityStorage)
external
initializer
{
require(
_trustedIssuersRegistry != address(0) && _claimTopicsRegistry != address(0)
&& _identityStorage != address(0),
ZeroAddress()
);
_tokenTopicsRegistry = IClaimTopicsRegistry(_claimTopicsRegistry);
_tokenIssuersRegistry = ITrustedIssuersRegistry(_trustedIssuersRegistry);
_tokenIdentityStorage = IIdentityRegistryStorage(_identityStorage);
_checksDisabled = false;
emit ClaimTopicsRegistrySet(_claimTopicsRegistry);
emit TrustedIssuersRegistrySet(_trustedIssuersRegistry);
emit IdentityStorageSet(_identityStorage);
emit EligibilityChecksEnabled();
__Ownable_init();
}
/**
* @dev See {IIdentityRegistry-batchRegisterIdentity}.
*/
function batchRegisterIdentity(
address[] calldata _userAddresses,
IIdentity[] calldata _identities,
uint16[] calldata _countries
) external override {
for (uint256 i = 0; i < _userAddresses.length; i++) {
registerIdentity(_userAddresses[i], _identities[i], _countries[i]);
}
}
/**
* @dev See {IIdentityRegistry-updateIdentity}.
*/
function updateIdentity(address _userAddress, IIdentity _identity) external override onlyAgent {
IIdentity oldIdentity = identity(_userAddress);
_tokenIdentityStorage.modifyStoredIdentity(_userAddress, _identity);
emit IdentityUpdated(oldIdentity, _identity);
}
/**
* @dev See {IIdentityRegistry-updateCountry}.
*/
function updateCountry(address _userAddress, uint16 _country) external override onlyAgent {
_tokenIdentityStorage.modifyStoredInvestorCountry(_userAddress, _country);
emit CountryUpdated(_userAddress, _country);
}
/**
* @dev See {IIdentityRegistry-deleteIdentity}.
*/
function deleteIdentity(address _userAddress) external override onlyAgent {
IIdentity oldIdentity = identity(_userAddress);
_tokenIdentityStorage.removeIdentityFromStorage(_userAddress);
emit IdentityRemoved(_userAddress, oldIdentity);
}
/**
* @dev See {IIdentityRegistry-setIdentityRegistryStorage}.
*/
function setIdentityRegistryStorage(address _identityRegistryStorage) external override onlyOwner {
_tokenIdentityStorage = IIdentityRegistryStorage(_identityRegistryStorage);
emit IdentityStorageSet(_identityRegistryStorage);
}
/**
* @dev See {IIdentityRegistry-setClaimTopicsRegistry}.
*/
function setClaimTopicsRegistry(address _claimTopicsRegistry) external override onlyOwner {
_tokenTopicsRegistry = IClaimTopicsRegistry(_claimTopicsRegistry);
emit ClaimTopicsRegistrySet(_claimTopicsRegistry);
}
/**
* @dev See {IIdentityRegistry-setTrustedIssuersRegistry}.
*/
function setTrustedIssuersRegistry(address _trustedIssuersRegistry) external override onlyOwner {
_tokenIssuersRegistry = ITrustedIssuersRegistry(_trustedIssuersRegistry);
emit TrustedIssuersRegistrySet(_trustedIssuersRegistry);
}
/**
* @dev See {IIdentityRegistry-disableEligibilityChecks}.
*/
function disableEligibilityChecks() external override onlyOwner {
require(!_checksDisabled, EligibilityChecksDisabledAlready());
_checksDisabled = true;
emit EligibilityChecksDisabled();
}
/**
* @dev See {IIdentityRegistry-enableEligibilityChecks}.
*/
function enableEligibilityChecks() external override onlyOwner {
require(_checksDisabled, EligibilityChecksEnabledAlready());
_checksDisabled = false;
emit EligibilityChecksEnabled();
}
/**
* @dev See {IIdentityRegistry-isVerified}.
*/
// solhint-disable-next-line code-complexity
function isVerified(address _userAddress) external view override returns (bool) {
if (_checksDisabled) return true;
if (address(identity(_userAddress)) == address(0)) return false;
uint256[] memory requiredClaimTopics = _tokenTopicsRegistry.getClaimTopics();
if (requiredClaimTopics.length == 0) {
return true;
}
uint256 foundClaimTopic;
uint256 scheme;
address issuer;
bytes memory sig;
bytes memory data;
uint256 claimTopic;
for (claimTopic = 0; claimTopic < requiredClaimTopics.length; claimTopic++) {
IClaimIssuer[] memory trustedIssuers =
_tokenIssuersRegistry.getTrustedIssuersForClaimTopic(requiredClaimTopics[claimTopic]);
if (trustedIssuers.length == 0) return false;
bytes32[] memory claimIds = new bytes32[](trustedIssuers.length);
for (uint256 i = 0; i < trustedIssuers.length; i++) {
claimIds[i] = keccak256(abi.encode(trustedIssuers[i], requiredClaimTopics[claimTopic]));
}
for (uint256 j = 0; j < claimIds.length; j++) {
(foundClaimTopic, scheme, issuer, sig, data,) = identity(_userAddress).getClaim(claimIds[j]);
if (foundClaimTopic == requiredClaimTopics[claimTopic]) {
try IClaimIssuer(issuer)
.isClaimValid(identity(_userAddress), requiredClaimTopics[claimTopic], sig, data) returns (
bool _validity
) {
if (_validity) {
j = claimIds.length;
}
if (!_validity && j == (claimIds.length - 1)) {
return false;
}
} catch {
if (j == (claimIds.length - 1)) {
return false;
}
}
} else if (j == (claimIds.length - 1)) {
return false;
}
}
}
return true;
}
/**
* @dev See {IIdentityRegistry-investorCountry}.
*/
function investorCountry(address _userAddress) external view override returns (uint16) {
return _tokenIdentityStorage.storedInvestorCountry(_userAddress);
}
/**
* @dev See {IIdentityRegistry-issuersRegistry}.
*/
function issuersRegistry() external view override returns (IERC3643TrustedIssuersRegistry) {
return _tokenIssuersRegistry;
}
/**
* @dev See {IIdentityRegistry-topicsRegistry}.
*/
function topicsRegistry() external view override returns (IERC3643ClaimTopicsRegistry) {
return _tokenTopicsRegistry;
}
/**
* @dev See {IIdentityRegistry-identityStorage}.
*/
function identityStorage() external view override returns (IERC3643IdentityRegistryStorage) {
return _tokenIdentityStorage;
}
/**
* @dev See {IIdentityRegistry-contains}.
*/
function contains(address _userAddress) external view override returns (bool) {
if (address(identity(_userAddress)) == address(0)) {
return false;
}
return true;
}
/**
* @dev See {IIdentityRegistry-registerIdentity}.
*/
function registerIdentity(address _userAddress, IIdentity _identity, uint16 _country) public override onlyAgent {
_tokenIdentityStorage.addIdentityToStorage(_userAddress, _identity, _country);
emit IdentityRegistered(_userAddress, _identity);
}
/**
* @dev See {IIdentityRegistry-identity}.
*/
function identity(address _userAddress) public view override returns (IIdentity) {
return _tokenIdentityStorage.storedIdentity(_userAddress);
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public pure virtual override returns (bool) {
return interfaceId == type(IIdentityRegistry).interfaceId
|| interfaceId == type(IERC3643IdentityRegistry).interfaceId || interfaceId == type(IERC173).interfaceId
|| interfaceId == type(IERC165).interfaceId;
}
}