- Add Foundry project configuration (foundry.toml, foundry.lock) - Add Solidity contracts (TokenFactory138, BridgeVault138, ComplianceRegistry, etc.) - Add API definitions (OpenAPI, GraphQL, gRPC, AsyncAPI) - Add comprehensive test suite (unit, integration, fuzz, invariants) - Add API services (REST, GraphQL, orchestrator, packet service) - Add documentation (ISO20022 mapping, runbooks, adapter guides) - Add development tools (RBC tool, Swagger UI, mock server) - Update OpenZeppelin submodules to v5.0.0
132 lines
4.1 KiB
Solidity
132 lines
4.1 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.8.20;
|
|
|
|
import "forge-std/Test.sol";
|
|
import "../../src/TokenFactory138.sol";
|
|
import "../../src/eMoneyToken.sol";
|
|
import "../../src/PolicyManager.sol";
|
|
import "../../src/ComplianceRegistry.sol";
|
|
import "../../src/DebtRegistry.sol";
|
|
import "../../src/interfaces/ITokenFactory138.sol";
|
|
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
|
|
|
|
contract TokenFactoryTest is Test {
|
|
TokenFactory138 public factory;
|
|
eMoneyToken public implementation;
|
|
PolicyManager public policyManager;
|
|
ComplianceRegistry public complianceRegistry;
|
|
DebtRegistry public debtRegistry;
|
|
|
|
address public admin;
|
|
address public deployer;
|
|
address public issuer;
|
|
|
|
function setUp() public {
|
|
admin = address(0x1);
|
|
deployer = address(0x2);
|
|
issuer = address(0x3);
|
|
|
|
complianceRegistry = new ComplianceRegistry(admin);
|
|
debtRegistry = new DebtRegistry(admin);
|
|
policyManager = new PolicyManager(admin, address(complianceRegistry), address(debtRegistry));
|
|
|
|
implementation = new eMoneyToken();
|
|
|
|
factory = new TokenFactory138(
|
|
admin,
|
|
address(implementation),
|
|
address(policyManager),
|
|
address(debtRegistry),
|
|
address(complianceRegistry)
|
|
);
|
|
|
|
vm.startPrank(admin);
|
|
factory.grantRole(factory.TOKEN_DEPLOYER_ROLE(), deployer);
|
|
policyManager.grantRole(policyManager.POLICY_OPERATOR_ROLE(), address(factory));
|
|
vm.stopPrank();
|
|
}
|
|
|
|
function test_deployToken() public {
|
|
ITokenFactory138.TokenConfig memory config = ITokenFactory138.TokenConfig({
|
|
issuer: issuer,
|
|
decimals: 18,
|
|
defaultLienMode: 2,
|
|
bridgeOnly: false,
|
|
bridge: address(0)
|
|
});
|
|
|
|
vm.prank(deployer);
|
|
address token = factory.deployToken("My Token", "MTK", config);
|
|
|
|
assertTrue(token != address(0));
|
|
assertEq(eMoneyToken(token).decimals(), 18);
|
|
assertEq(eMoneyToken(token).name(), "My Token");
|
|
assertEq(eMoneyToken(token).symbol(), "MTK");
|
|
|
|
// Check policy configuration
|
|
assertEq(policyManager.lienMode(token), 2);
|
|
assertFalse(policyManager.bridgeOnly(token));
|
|
}
|
|
|
|
function test_deployToken_withBridge() public {
|
|
address bridge = address(0xB0);
|
|
|
|
ITokenFactory138.TokenConfig memory config = ITokenFactory138.TokenConfig({
|
|
issuer: issuer,
|
|
decimals: 6,
|
|
defaultLienMode: 1,
|
|
bridgeOnly: true,
|
|
bridge: bridge
|
|
});
|
|
|
|
vm.prank(deployer);
|
|
address token = factory.deployToken("Bridge Token", "BRT", config);
|
|
|
|
assertEq(policyManager.bridgeOnly(token), true);
|
|
assertEq(policyManager.bridge(token), bridge);
|
|
assertEq(policyManager.lienMode(token), 1);
|
|
}
|
|
|
|
function test_deployToken_unauthorized() public {
|
|
ITokenFactory138.TokenConfig memory config = ITokenFactory138.TokenConfig({
|
|
issuer: issuer,
|
|
decimals: 18,
|
|
defaultLienMode: 2,
|
|
bridgeOnly: false,
|
|
bridge: address(0)
|
|
});
|
|
|
|
vm.expectRevert();
|
|
factory.deployToken("Token", "TKN", config);
|
|
}
|
|
|
|
function test_deployToken_zeroIssuer() public {
|
|
ITokenFactory138.TokenConfig memory config = ITokenFactory138.TokenConfig({
|
|
issuer: address(0),
|
|
decimals: 18,
|
|
defaultLienMode: 2,
|
|
bridgeOnly: false,
|
|
bridge: address(0)
|
|
});
|
|
|
|
vm.prank(deployer);
|
|
vm.expectRevert("TokenFactory138: zero issuer");
|
|
factory.deployToken("Token", "TKN", config);
|
|
}
|
|
|
|
function test_deployToken_invalidLienMode() public {
|
|
ITokenFactory138.TokenConfig memory config = ITokenFactory138.TokenConfig({
|
|
issuer: issuer,
|
|
decimals: 18,
|
|
defaultLienMode: 0, // Invalid
|
|
bridgeOnly: false,
|
|
bridge: address(0)
|
|
});
|
|
|
|
vm.prank(deployer);
|
|
vm.expectRevert("TokenFactory138: invalid lien mode");
|
|
factory.deployToken("Token", "TKN", config);
|
|
}
|
|
}
|
|
|