mirror of
https://github.com/luxfi/erc-3643.git
synced 2026-10-30 16:58:28 +00:00
* ✨ 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
262 lines
10 KiB
Solidity
262 lines
10 KiB
Solidity
// SPDX-License-Identifier: UNLICENSED
|
|
pragma solidity 0.8.30;
|
|
|
|
import { IIdentity } from "@onchain-id/solidity/contracts/interface/IIdentity.sol";
|
|
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
|
|
import { AddressFrozen, RecoverySuccess, TokensFrozen } from "contracts/ERC-3643/IERC3643.sol";
|
|
import { IERC3643IdentityRegistry } from "contracts/ERC-3643/IERC3643IdentityRegistry.sol";
|
|
import { ITREXFactory } from "contracts/factory/ITREXFactory.sol";
|
|
import { IdentityRegistry } from "contracts/registry/implementation/IdentityRegistry.sol";
|
|
import {
|
|
AgentNotAuthorized,
|
|
CallerDoesNotHaveAgentRole,
|
|
NoTokenToRecover,
|
|
RecoveryNotPossible
|
|
} from "contracts/token/Token.sol";
|
|
import { Token } from "contracts/token/Token.sol";
|
|
import { TokenRoles } from "contracts/token/TokenStructs.sol";
|
|
import { TokenTestBase } from "test/token/TokenTestBase.sol";
|
|
|
|
contract TokenRecoveryTest is TokenTestBase {
|
|
|
|
// Token suite components
|
|
IdentityRegistry public identityRegistry;
|
|
|
|
function setUp() public override {
|
|
super.setUp();
|
|
|
|
// Get IdentityRegistry
|
|
IERC3643IdentityRegistry ir = token.identityRegistry();
|
|
identityRegistry = IdentityRegistry(address(ir));
|
|
|
|
// Add tokenAgent as an agent
|
|
vm.prank(deployer);
|
|
token.addAgent(tokenAgent);
|
|
|
|
// Add tokenAgent as an agent to IdentityRegistry
|
|
vm.prank(deployer);
|
|
identityRegistry.addAgent(tokenAgent);
|
|
|
|
// Register bob in IdentityRegistry
|
|
vm.prank(tokenAgent);
|
|
identityRegistry.registerIdentity(bob, bobIdentity, 666);
|
|
|
|
// Mint tokens to bob
|
|
vm.prank(tokenAgent);
|
|
token.mint(bob, 500);
|
|
|
|
// Unpause token
|
|
vm.prank(tokenAgent);
|
|
token.unpause();
|
|
}
|
|
|
|
// ============ recoveryAddress() Tests ============
|
|
|
|
/// @notice Should revert when sender is not an agent
|
|
function test_recoveryAddress_RevertWhen_NotAgent() public {
|
|
// Add key to bobIdentity for another address
|
|
bytes32 keyHash = keccak256(abi.encode(another));
|
|
vm.prank(bob);
|
|
bobIdentity.addKey(keyHash, 1, 1);
|
|
|
|
vm.prank(another);
|
|
vm.expectRevert(CallerDoesNotHaveAgentRole.selector);
|
|
token.recoveryAddress(bob, another, address(bobIdentity));
|
|
}
|
|
|
|
/// @notice Should revert when agent permission is restricted
|
|
function test_recoveryAddress_RevertWhen_AgentRestricted() public {
|
|
// Add key to bobIdentity for another address
|
|
bytes32 keyHash = keccak256(abi.encode(another));
|
|
vm.prank(bob);
|
|
bobIdentity.addKey(keyHash, 1, 1);
|
|
|
|
// Set agent restrictions
|
|
TokenRoles memory restrictions = TokenRoles({
|
|
disableMint: false,
|
|
disableBurn: false,
|
|
disablePartialFreeze: false,
|
|
disableAddressFreeze: false,
|
|
disableRecovery: true,
|
|
disableForceTransfer: false,
|
|
disablePause: false
|
|
});
|
|
|
|
vm.prank(deployer);
|
|
token.setAgentRestrictions(tokenAgent, restrictions);
|
|
|
|
vm.prank(tokenAgent);
|
|
vm.expectRevert(abi.encodeWithSelector(AgentNotAuthorized.selector, tokenAgent, "recovery disabled"));
|
|
token.recoveryAddress(bob, another, address(bobIdentity));
|
|
}
|
|
|
|
/// @notice Should revert when wallet to recover has no balance
|
|
function test_recoveryAddress_RevertWhen_NoBalance() public {
|
|
// Use agent to burn all bob's tokens
|
|
uint256 bobBalance = token.balanceOf(bob);
|
|
vm.prank(tokenAgent);
|
|
token.burn(bob, bobBalance);
|
|
|
|
vm.prank(tokenAgent);
|
|
vm.expectRevert(NoTokenToRecover.selector);
|
|
token.recoveryAddress(bob, another, address(bobIdentity));
|
|
}
|
|
|
|
/// @notice Should recover and freeze tokens on the new wallet when wallet has frozen token
|
|
function test_recoveryAddress_Success_WithFrozenTokens() public {
|
|
// Add key to bobIdentity for another address
|
|
bytes32 keyHash = keccak256(abi.encode(another));
|
|
vm.prank(bob);
|
|
bobIdentity.addKey(keyHash, 1, 1);
|
|
|
|
// Freeze partial tokens on bob
|
|
vm.prank(tokenAgent);
|
|
token.freezePartialTokens(bob, 50);
|
|
|
|
vm.prank(tokenAgent);
|
|
token.recoveryAddress(bob, another, address(bobIdentity));
|
|
|
|
assertEq(token.getFrozenTokens(another), 50);
|
|
}
|
|
|
|
/// @notice Should revert when identity registry does not contain the lost or new wallet
|
|
function test_recoveryAddress_RevertWhen_IdentityNotInRegistry() public {
|
|
// Delete bob from identity registry
|
|
vm.prank(tokenAgent);
|
|
identityRegistry.deleteIdentity(bob);
|
|
|
|
vm.prank(tokenAgent);
|
|
vm.expectRevert(RecoveryNotPossible.selector);
|
|
token.recoveryAddress(bob, another, address(bobIdentity));
|
|
}
|
|
|
|
/// @notice Should update the identity registry correctly when recovery is successful
|
|
function test_recoveryAddress_Success_WithIdentityTransfer() public {
|
|
vm.prank(tokenAgent);
|
|
vm.expectEmit(true, true, true, false, address(token));
|
|
emit RecoverySuccess(bob, another, address(bobIdentity));
|
|
token.recoveryAddress(bob, another, address(bobIdentity));
|
|
|
|
assertFalse(identityRegistry.contains(bob));
|
|
assertTrue(identityRegistry.contains(another));
|
|
}
|
|
|
|
/// @notice Should only remove the lost wallet from the registry when new wallet is already in it
|
|
function test_recoveryAddress_Success_NewWalletAlreadyInRegistry() public {
|
|
// Register another in identity registry
|
|
vm.prank(tokenAgent);
|
|
identityRegistry.registerIdentity(another, bobIdentity, 1);
|
|
|
|
vm.prank(tokenAgent);
|
|
vm.expectEmit(true, true, true, false, address(token));
|
|
emit RecoverySuccess(bob, another, address(bobIdentity));
|
|
token.recoveryAddress(bob, another, address(bobIdentity));
|
|
|
|
assertFalse(identityRegistry.contains(bob));
|
|
assertTrue(identityRegistry.contains(another));
|
|
}
|
|
|
|
/// @notice Should recover without touching IRS when recovery already happened on another token
|
|
function test_recoveryAddress_Success_RecoveryAlreadyHappened() public {
|
|
// Delete bob and register another (simulating recovery on another token)
|
|
vm.prank(tokenAgent);
|
|
identityRegistry.deleteIdentity(bob);
|
|
vm.prank(tokenAgent);
|
|
identityRegistry.registerIdentity(another, bobIdentity, 1);
|
|
|
|
vm.prank(tokenAgent);
|
|
vm.expectEmit(true, true, true, false, address(token));
|
|
emit RecoverySuccess(bob, another, address(bobIdentity));
|
|
token.recoveryAddress(bob, another, address(bobIdentity));
|
|
|
|
assertFalse(identityRegistry.contains(bob));
|
|
assertTrue(identityRegistry.contains(another));
|
|
}
|
|
|
|
/// @notice Should transfer the frozen status and transfer frozen tokens when old wallet is frozen and new is not
|
|
function test_recoveryAddress_Success_OldFrozenNewNotFrozen() public {
|
|
// Freeze bob address and partial tokens
|
|
vm.prank(tokenAgent);
|
|
token.setAddressFrozen(bob, true);
|
|
vm.prank(tokenAgent);
|
|
token.freezePartialTokens(bob, 50);
|
|
|
|
vm.prank(tokenAgent);
|
|
vm.expectEmit(true, false, false, false, address(token));
|
|
emit TokensFrozen(another, 50);
|
|
token.recoveryAddress(bob, another, address(bobIdentity));
|
|
|
|
assertTrue(token.isFrozen(another));
|
|
assertEq(token.getFrozenTokens(another), 50);
|
|
}
|
|
|
|
/// @notice Should transfer frozen tokens and keep freeze status when both wallets are frozen
|
|
function test_recoveryAddress_Success_BothFrozen() public {
|
|
// Freeze both addresses and partial tokens on bob
|
|
vm.prank(tokenAgent);
|
|
token.setAddressFrozen(bob, true);
|
|
vm.prank(tokenAgent);
|
|
token.setAddressFrozen(another, true);
|
|
vm.prank(tokenAgent);
|
|
token.freezePartialTokens(bob, 30);
|
|
|
|
vm.prank(tokenAgent);
|
|
vm.expectEmit(true, false, false, false, address(token));
|
|
emit TokensFrozen(another, 30);
|
|
token.recoveryAddress(bob, another, address(bobIdentity));
|
|
|
|
assertTrue(token.isFrozen(another));
|
|
assertEq(token.getFrozenTokens(another), 30);
|
|
}
|
|
|
|
/// @notice Should recover tokens without freezing any when there are no frozen tokens
|
|
function test_recoveryAddress_Success_NoFrozenTokens() public {
|
|
vm.prank(tokenAgent);
|
|
vm.expectEmit(true, true, true, false, address(token));
|
|
emit RecoverySuccess(bob, another, address(bobIdentity));
|
|
token.recoveryAddress(bob, another, address(bobIdentity));
|
|
|
|
assertEq(token.getFrozenTokens(another), 0);
|
|
}
|
|
|
|
/// @notice Should not emit AddressFrozen when new wallet is already frozen
|
|
function test_recoveryAddress_Success_NewWalletAlreadyFrozen() public {
|
|
// Freeze old wallet and new wallet
|
|
vm.prank(tokenAgent);
|
|
token.setAddressFrozen(bob, true);
|
|
vm.prank(tokenAgent);
|
|
token.setAddressFrozen(another, true);
|
|
|
|
// Recovery should not emit AddressFrozen for new wallet since it's already frozen
|
|
vm.prank(tokenAgent);
|
|
vm.expectEmit(true, true, true, false, address(token));
|
|
emit AddressFrozen(bob, false, address(token));
|
|
vm.expectEmit(true, true, true, false, address(token));
|
|
emit RecoverySuccess(bob, another, address(bobIdentity));
|
|
token.recoveryAddress(bob, another, address(bobIdentity));
|
|
|
|
assertTrue(token.isFrozen(another));
|
|
}
|
|
|
|
/// @notice Should recover when only new wallet is in registry (not lost wallet)
|
|
function test_recoveryAddress_Success_OnlyNewWalletInRegistry() public {
|
|
// Delete bob from identity registry but keep another registered
|
|
vm.prank(tokenAgent);
|
|
identityRegistry.deleteIdentity(bob);
|
|
|
|
// Register another in identity registry
|
|
vm.prank(tokenAgent);
|
|
identityRegistry.registerIdentity(another, bobIdentity, 1);
|
|
|
|
// Recovery should work because new wallet is in registry
|
|
vm.prank(tokenAgent);
|
|
vm.expectEmit(true, true, true, false, address(token));
|
|
emit RecoverySuccess(bob, another, address(bobIdentity));
|
|
token.recoveryAddress(bob, another, address(bobIdentity));
|
|
|
|
assertEq(token.balanceOf(another), 500);
|
|
assertTrue(identityRegistry.contains(another));
|
|
}
|
|
|
|
}
|