Skip to content

Commit

Permalink
Increase coverage (#342)
Browse files Browse the repository at this point in the history
* branches coverage reached to 85 %

* increase coverage of transferManagers

* improve the coverage of token

* introduced withdrawERC20() in the changelog

* fix

* minor fixes
  • Loading branch information
satyamakgec authored and pabloruiz55 committed Oct 16, 2018
1 parent 468b047 commit df996a1
Show file tree
Hide file tree
Showing 33 changed files with 1,309 additions and 338 deletions.
2 changes: 1 addition & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module.exports = {
copyPackages: ['openzeppelin-solidity'],
testCommand: 'node ../node_modules/.bin/truffle test `find test/*.js ! -name a_poly_oracle.js -and ! -name s_v130_to_v140_upgrade.js` --network coverage',
deepSkip: true,
skipFiles: ['external', 'flat', 'helpers', 'mocks', 'oracles'],
skipFiles: ['external', 'flat', 'helpers', 'mocks', 'oracles', 'libraries/KindMath.sol', 'storage'],
forceParse: ['mocks', 'oracles']
};
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ All notable changes to this project will be documented in this file.
* Add `getReputationOfFactory()` & `getModuleListOfType()` functions to get the array type data from the ModuleRegistry contract.
* Add `_setupCost` in `LogGenerateModuleFromFactory` event.
* Add new function `getAllModulesByName()`, To get the list of modules having the same name. #198.
* Add new function `modifyTickerDetails()`, To modify the details of undeployed ticker. #230
* Add new function `modifyTickerDetails()`, To modify the details of undeployed ticker. #230

## Fixed
* Generalize the STO varaible names and added them in `ISTO.sol` to use the common standard in all STOs.
* Generalize the event when any new token get registered with the polymath ecosystem. `LogNewSecurityToken` should emit _ticker, _name, _securityTokenAddress, _owner, _addedAt, _registrant respectively. #230
* Generalize the event when any new token get registered with the polymath ecosystem. `LogNewSecurityToken` should emit _ticker, _name, _securityTokenAddress, _owner, _addedAt, _registrant respectively. #230
* Change the function name of `withdraPoly` to `withdrawERC20` and make the function generalize to extract tokens from the ST contract. parmeters are contract address and the value need to extract from the securityToken.

## Removed
* Remove `swarmHash` from the `registerTicker(), addCustomTicker(), generateSecurityToken(), addCustomSecurityToken()` functions of TickerRegistry.sol and SecurityTokenRegistry.sol. #230
Expand Down
1 change: 0 additions & 1 deletion contracts/ModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
require(getBool(Encoder.getKey("verified", _moduleFactory)), "ModuleFactory must be verified");
}
require(_isCompatibleModule(_moduleFactory, msg.sender), "Version should within the compatible range of ST");
require(getUint(Encoder.getKey("registry",_moduleFactory)) != 0, "ModuleFactory type should not be 0");
pushArray(Encoder.getKey("reputation", _moduleFactory), msg.sender);
emit ModuleUsed(_moduleFactory, msg.sender);
}
Expand Down
1 change: 1 addition & 0 deletions contracts/SecurityTokenRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
* @param _patch Patch version of the proxy
*/
function setProtocolVersion(address _STFactoryAddress, uint8 _major, uint8 _minor, uint8 _patch) external onlyOwner {
require(_STFactoryAddress != address(0), "0x address is not allowed");
_setProtocolVersion(_STFactoryAddress, _major, _minor, _patch);
}

Expand Down
7 changes: 4 additions & 3 deletions contracts/interfaces/ISecurityToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ interface ISecurityToken {
*/
function investors(uint256 _index) external view returns (address);

/**
* @notice allows the owner to withdraw unspent POLY stored by them on the ST.
/**
* @notice allows the owner to withdraw unspent POLY stored by them on the ST or any ERC20 token.
* @dev Owner can transfer POLY to the ST which will be used to pay for modules that require a POLY fee.
* @param _tokenContract Address of the ERC20Basic compliance token
* @param _value amount of POLY to withdraw
*/
function withdrawPoly(uint256 _value) external;
function withdrawERC20(address _tokenContract, uint256 _value) external;

/**
* @notice allows owner to approve more POLY to one of the modules
Expand Down
34 changes: 34 additions & 0 deletions contracts/mocks/MockBurnFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pragma solidity ^0.4.24;

import "./MockRedemptionManager.sol";
import "../modules/Burn/TrackedRedemptionFactory.sol";

/**
* @title Mock Contract Not fit for production environment
*/

contract MockBurnFactory is TrackedRedemptionFactory {

/**
* @notice Constructor
* @param _polyAddress Address of the polytoken
*/
constructor (address _polyAddress, uint256 _setupCost, uint256 _usageCost, uint256 _subscriptionCost) public
TrackedRedemptionFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost)
{
}

/**
* @notice used to launch the Module with the help of factory
* @return address Contract address of the Module
*/
function deploy(bytes /*_data*/) external returns(address) {
if(setupCost > 0)
require(polyToken.transferFrom(msg.sender, owner, setupCost), "Unable to pay setup cost");
//Check valid bytes - can only call module init function
MockRedemptionManager mockRedemptionManager = new MockRedemptionManager(msg.sender, address(polyToken));
emit GenerateModuleFromFactory(address(mockRedemptionManager), getName(), address(this), msg.sender, setupCost, now);
return address(mockRedemptionManager);
}

}
101 changes: 22 additions & 79 deletions contracts/mocks/MockFactory.sol
Original file line number Diff line number Diff line change
@@ -1,99 +1,42 @@
pragma solidity ^0.4.24;

import "../modules/STO/DummySTO.sol";
import "../modules/ModuleFactory.sol";
import "../libraries/Util.sol";
import "../modules/STO/DummySTOFactory.sol";

contract MockFactory is ModuleFactory {
/**
* @title Mock Contract Not fit for production environment
*/

contract MockFactory is DummySTOFactory {

bool public switchTypes = false;
/**
* @notice Constructor
* @param _polyAddress Address of the polytoken
*/
constructor (address _polyAddress, uint256 _setupCost, uint256 _usageCost, uint256 _subscriptionCost) public
ModuleFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost)
DummySTOFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost)
{
version = "1.0.0";
name = "Mock";
title = "Mock Manager";
description = "MockManager";
compatibleSTVersionRange["lowerBound"] = VersionUtils.pack(uint8(0), uint8(0), uint8(0));
compatibleSTVersionRange["upperBound"] = VersionUtils.pack(uint8(0), uint8(0), uint8(0));
}

/**
* @notice used to launch the Module with the help of factory
* @param _data Data used for the intialization of the module factory variables
* @return address Contract address of the Module
*/
function deploy(bytes _data) external returns(address) {
if(setupCost > 0)
require(polyToken.transferFrom(msg.sender, owner, setupCost), "Unable to pay setup cost");
//Check valid bytes - can only call module init function
DummySTO dummySTO = new DummySTO(msg.sender, address(polyToken));
//Checks that _data is valid (not calling anything it shouldn't)
require(Util.getSig(_data) == dummySTO.getInitFunction(), "Invalid initialisation");
require(address(dummySTO).call(_data), "Unsuccessfull initialisation");
return address(dummySTO);
}

/**
* @notice Type of the Module factory
*/
function getTypes() external view returns(uint8[]) {
uint8[] memory res = new uint8[](0);
return res;
}

/**
* @notice Get the name of the Module
*/
function getName() public view returns(bytes32) {
return name;
}

/**
* @notice Get the description of the Module
*/
function getDescription() external view returns(string) {
return description;
}

/**
* @notice Get the title of the Module
*/
function getTitle() external view returns(string) {
return title;
}

/**
* @notice Get the version of the Module
*/
function getVersion() external view returns(string) {
return version;
}

/**
* @notice Get the setup cost of the module
*/
function getSetupCost() external view returns (uint256) {
return setupCost;
}

/**
* @notice Returns the instructions associated with the module
*/
function getInstructions() external view returns(string) {
return "Mock Manager - This is mock in nature";
}

/**
* @notice Get the tags related to the module factory
*/
function getTags() external view returns(bytes32[]) {
bytes32[] memory availableTags = new bytes32[](4);
availableTags[0] = "Mock";
return availableTags;
if (!switchTypes) {
uint8[] memory types = new uint8[](0);
return types;
} else {
uint8[] memory res = new uint8[](2);
res[0] = 1;
res[1] = 1;
return res;
}

}

function changeTypes() external onlyOwner {
switchTypes = !switchTypes;
}

}
45 changes: 45 additions & 0 deletions contracts/mocks/MockRedemptionManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
pragma solidity ^0.4.24;

import "../modules/Burn/TrackedRedemption.sol";

/**
* @title Burn module for burning tokens and keeping track of burnt amounts
*/
contract MockRedemptionManager is TrackedRedemption {

mapping (address => uint256) tokenToRedeem;

event RedeemedTokenByOwner(address _investor, address _byWhoom, uint256 _value, uint256 _timestamp);

/**
* @notice Constructor
* @param _securityToken Address of the security token
* @param _polyAddress Address of the polytoken
*/
constructor (address _securityToken, address _polyAddress) public
TrackedRedemption(_securityToken, _polyAddress)
{
}

/**
* @notice Transfer tokens to Module to burn
* @param _value The number of tokens to redeem
*/
function transferToRedeem(uint256 _value) public {
require(ISecurityToken(securityToken).transferFrom(msg.sender, address(this), _value), "Insufficient funds");
tokenToRedeem[msg.sender] = _value;
}

/**
* @notice use to redeem tokens by the module
* @param _value The number of tokens to redeem
*/
function redeemTokenByOwner(uint256 _value) public {
require(tokenToRedeem[msg.sender] >= _value);
tokenToRedeem[msg.sender] = tokenToRedeem[msg.sender].sub(_value);
redeemedTokens[msg.sender] = redeemedTokens[msg.sender].add(_value);
ISecurityToken(securityToken).burnWithData(_value, "");
emit RedeemedTokenByOwner(msg.sender, address(this), _value, now);
}

}
31 changes: 31 additions & 0 deletions contracts/mocks/MockWrongTypeFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pragma solidity ^0.4.24;

import "./MockBurnFactory.sol";
import "../modules/ModuleFactory.sol";
import "../libraries/Util.sol";

/**
* @title Mock Contract Not fit for production environment
*/

contract MockWrongTypeFactory is MockBurnFactory {

/**
* @notice Constructor
* @param _polyAddress Address of the polytoken
*/
constructor (address _polyAddress, uint256 _setupCost, uint256 _usageCost, uint256 _subscriptionCost) public
MockBurnFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost)
{
}

/**
* @notice Type of the Module factory
*/
function getTypes() external view returns(uint8[]) {
uint8[] memory types = new uint8[](1);
types[0] = 4;
return types;
}

}
68 changes: 3 additions & 65 deletions contracts/mocks/TestSTOFactory.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
pragma solidity ^0.4.24;

import "../modules/STO/DummySTO.sol";
import "../modules/ModuleFactory.sol";
import "../libraries/Util.sol";
import "../modules/STO/DummySTOFactory.sol";

contract TestSTOFactory is ModuleFactory {
contract TestSTOFactory is DummySTOFactory {

/**
* @notice Constructor
* @param _polyAddress Address of the polytoken
*/
constructor (address _polyAddress, uint256 _setupCost, uint256 _usageCost, uint256 _subscriptionCost) public
ModuleFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost)
DummySTOFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost)
{
version = "1.0.0";
name = "TestSTO";
Expand All @@ -21,66 +19,6 @@ contract TestSTOFactory is ModuleFactory {
compatibleSTVersionRange["upperBound"] = VersionUtils.pack(uint8(0), uint8(0), uint8(0));
}

/**
* @notice used to launch the Module with the help of factory
* @param _data Data used for the intialization of the module factory variables
* @return address Contract address of the Module
*/
function deploy(bytes _data) external returns(address) {
if(setupCost > 0)
require(polyToken.transferFrom(msg.sender, owner, setupCost), "Failed transferFrom because of sufficent Allowance is not provided");
//Check valid bytes - can only call module init function
DummySTO dummySTO = new DummySTO(msg.sender, address(polyToken));
//Checks that _data is valid (not calling anything it shouldn't)
require(Util.getSig(_data) == dummySTO.getInitFunction(), "Provided data is not valid");
require(address(dummySTO).call(_data), "Un-successfull call");
return address(dummySTO);
}

/**
* @notice Type of the Module factory
*/
function getTypes() external view returns(uint8[]) {
uint8[] memory res = new uint8[](1);
res[0] = 3;
return res;
}

/**
* @notice Get the name of the Module
*/
function getName() external view returns(bytes32) {
return name;
}

/**
* @notice Get the description of the Module
*/
function getDescription() external view returns(string) {
return description;
}

/**
* @notice Get the title of the Module
*/
function getTitle() external view returns(string) {
return title;
}

/**
* @notice Get the version of the Module
*/
function getVersion() external view returns(string) {
return version;
}

/**
* @notice Get the setup cost of the module
*/
function getSetupCost() external view returns (uint256) {
return setupCost;
}

/**
* @notice Returns the instructions associated with the module
*/
Expand Down
2 changes: 1 addition & 1 deletion contracts/modules/Burn/TrackedRedemption.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract TrackedRedemption is IBurn, Module {
redeemedTokens[msg.sender] = redeemedTokens[msg.sender].add(_value);
emit Redeemed(msg.sender, _value, now);
}

/**
* @notice Return the permissions flag that are associated with CountTransferManager
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ contract ManualApprovalTransferManager is ITransferManager {
require(_from != address(0), "Invalid from address");
require(_to != address(0), "Invalid to address");
require(_expiryTime > now, "Invalid expiry time");
require(manualApprovals[_from][_to].expiryTime == 0, "Blocking already exists");
require(manualBlockings[_from][_to].expiryTime == 0, "Blocking already exists");
manualBlockings[_from][_to] = ManualBlocking(_expiryTime);
emit AddManualBlocking(_from, _to, _expiryTime, msg.sender);
}
Expand Down
Loading

0 comments on commit df996a1

Please sign in to comment.