diff --git a/lib/RuleEngine b/lib/RuleEngine new file mode 160000 index 0000000..a5516c9 --- /dev/null +++ b/lib/RuleEngine @@ -0,0 +1 @@ +Subproject commit a5516c930c3868f142dece919851ce0c94a18f5a diff --git a/src/public/IncomeVaultOpen.sol b/src/public/IncomeVaultOpen.sol index 069f336..9f88418 100644 --- a/src/public/IncomeVaultOpen.sol +++ b/src/public/IncomeVaultOpen.sol @@ -10,20 +10,35 @@ import "CMTAT/modules/wrapper/controllers/ValidationModule.sol"; * @title public function */ abstract contract IncomeVaultOpen is ReentrancyGuardUpgradeable, ValidationModule , IncomeVaultInternal { - + enum TIME_ERROR_CODE {OK, CLAIM_NOT_ACTIVATED, TOO_LATE_TO_WITHDRAW, TOO_EARLY_TO_WITHDRAW} /** * @notice validate if a time is valid */ function validateTime(uint256 time) public view{ - if(!segregatedClaim[time]){ - revert IncomeVault_ClaimNotActivated(); + TIME_ERROR_CODE code = validateTimeCode(time); + if(code == TIME_ERROR_CODE.OK){ + return; + }else if(code == TIME_ERROR_CODE.CLAIM_NOT_ACTIVATED){ + revert IncomeVault_ClaimNotActivated(); } - if(block.timestamp > timeLimitToWithdraw + time){ + else if(code == TIME_ERROR_CODE.TOO_LATE_TO_WITHDRAW){ revert IncomeVault_TooLateToWithdraw(block.timestamp); + }else if (code == TIME_ERROR_CODE.TOO_EARLY_TO_WITHDRAW){ + revert IncomeVault_TooEarlyToWithdraw(block.timestamp); + } + } + + function validateTimeCode(uint256 time) public view returns(TIME_ERROR_CODE code){ + if(!segregatedClaim[time]){ + return TIME_ERROR_CODE.CLAIM_NOT_ACTIVATED; + } + if(block.timestamp > timeLimitToWithdraw + time){ + return TIME_ERROR_CODE.TOO_LATE_TO_WITHDRAW; } if(block.timestamp < time){ - revert IncomeVault_TooEarlyToWithdraw(block.timestamp); + return TIME_ERROR_CODE.TOO_EARLY_TO_WITHDRAW; } + return TIME_ERROR_CODE.OK; } /** diff --git a/test/RuleEngineIntegration.t.sol b/test/RuleEngineIntegration.t.sol index a328ef0..64a80b8 100644 --- a/test/RuleEngineIntegration.t.sol +++ b/test/RuleEngineIntegration.t.sol @@ -46,12 +46,6 @@ contract RuleEngineIntegration is RuleWhitelistInvariantStorage, Test, HelperCon FLAG ); - // specific arrange - vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleEngineMock = new RuleEngine(DEFAULT_ADMIN_ADDRESS, ZERO_ADDRESS); - vm.prank(DEFAULT_ADMIN_ADDRESS); - ruleEngineMock.addRuleValidation(ruleWhitelist); - // Token payment tokenPayment = new CMTAT_STANDALONE( ZERO_ADDRESS, @@ -66,7 +60,7 @@ contract RuleEngineIntegration is RuleWhitelistInvariantStorage, Test, HelperCon "CMTAT_info", FLAG ); - + // IncomeVault deployment Options memory opts; opts.constructorData = abi.encode(ZERO_ADDRESS); address proxy = Upgrades.deployTransparentProxy( @@ -82,6 +76,12 @@ contract RuleEngineIntegration is RuleWhitelistInvariantStorage, Test, HelperCon ); debtVault = IncomeVault(proxy); + // specific arrange + vm.prank(DEFAULT_ADMIN_ADDRESS); + ruleEngineMock = new RuleEngine(DEFAULT_ADMIN_ADDRESS, ZERO_ADDRESS, address(proxy)); + vm.prank(DEFAULT_ADMIN_ADDRESS); + ruleEngineMock.addRuleValidation(ruleWhitelist); + // We set the Rule Engine vm.prank(DEFAULT_ADMIN_ADDRESS); debtVault.setRuleEngine(ruleEngineMock);