Skip to content

Commit df996a1

Browse files
satyamakgecpabloruiz55
authored andcommitted
Increase coverage (#342)
* branches coverage reached to 85 % * increase coverage of transferManagers * improve the coverage of token * introduced withdrawERC20() in the changelog * fix * minor fixes
1 parent 468b047 commit df996a1

33 files changed

+1309
-338
lines changed

.solcover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ module.exports = {
44
copyPackages: ['openzeppelin-solidity'],
55
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',
66
deepSkip: true,
7-
skipFiles: ['external', 'flat', 'helpers', 'mocks', 'oracles'],
7+
skipFiles: ['external', 'flat', 'helpers', 'mocks', 'oracles', 'libraries/KindMath.sol', 'storage'],
88
forceParse: ['mocks', 'oracles']
99
};

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ All notable changes to this project will be documented in this file.
2626
* Add `getReputationOfFactory()` & `getModuleListOfType()` functions to get the array type data from the ModuleRegistry contract.
2727
* Add `_setupCost` in `LogGenerateModuleFromFactory` event.
2828
* Add new function `getAllModulesByName()`, To get the list of modules having the same name. #198.
29-
* Add new function `modifyTickerDetails()`, To modify the details of undeployed ticker. #230
29+
* Add new function `modifyTickerDetails()`, To modify the details of undeployed ticker. #230
3030

3131
## Fixed
3232
* Generalize the STO varaible names and added them in `ISTO.sol` to use the common standard in all STOs.
33-
* Generalize the event when any new token get registered with the polymath ecosystem. `LogNewSecurityToken` should emit _ticker, _name, _securityTokenAddress, _owner, _addedAt, _registrant respectively. #230
33+
* Generalize the event when any new token get registered with the polymath ecosystem. `LogNewSecurityToken` should emit _ticker, _name, _securityTokenAddress, _owner, _addedAt, _registrant respectively. #230
34+
* 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.
3435

3536
## Removed
3637
* Remove `swarmHash` from the `registerTicker(), addCustomTicker(), generateSecurityToken(), addCustomSecurityToken()` functions of TickerRegistry.sol and SecurityTokenRegistry.sol. #230

contracts/ModuleRegistry.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ contract ModuleRegistry is IModuleRegistry, EternalStorage {
126126
require(getBool(Encoder.getKey("verified", _moduleFactory)), "ModuleFactory must be verified");
127127
}
128128
require(_isCompatibleModule(_moduleFactory, msg.sender), "Version should within the compatible range of ST");
129-
require(getUint(Encoder.getKey("registry",_moduleFactory)) != 0, "ModuleFactory type should not be 0");
130129
pushArray(Encoder.getKey("reputation", _moduleFactory), msg.sender);
131130
emit ModuleUsed(_moduleFactory, msg.sender);
132131
}

contracts/SecurityTokenRegistry.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ contract SecurityTokenRegistry is ISecurityTokenRegistry, EternalStorage {
669669
* @param _patch Patch version of the proxy
670670
*/
671671
function setProtocolVersion(address _STFactoryAddress, uint8 _major, uint8 _minor, uint8 _patch) external onlyOwner {
672+
require(_STFactoryAddress != address(0), "0x address is not allowed");
672673
_setProtocolVersion(_STFactoryAddress, _major, _minor, _patch);
673674
}
674675

contracts/interfaces/ISecurityToken.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,13 @@ interface ISecurityToken {
127127
*/
128128
function investors(uint256 _index) external view returns (address);
129129

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

137138
/**
138139
* @notice allows owner to approve more POLY to one of the modules
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
pragma solidity ^0.4.24;
2+
3+
import "./MockRedemptionManager.sol";
4+
import "../modules/Burn/TrackedRedemptionFactory.sol";
5+
6+
/**
7+
* @title Mock Contract Not fit for production environment
8+
*/
9+
10+
contract MockBurnFactory is TrackedRedemptionFactory {
11+
12+
/**
13+
* @notice Constructor
14+
* @param _polyAddress Address of the polytoken
15+
*/
16+
constructor (address _polyAddress, uint256 _setupCost, uint256 _usageCost, uint256 _subscriptionCost) public
17+
TrackedRedemptionFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost)
18+
{
19+
}
20+
21+
/**
22+
* @notice used to launch the Module with the help of factory
23+
* @return address Contract address of the Module
24+
*/
25+
function deploy(bytes /*_data*/) external returns(address) {
26+
if(setupCost > 0)
27+
require(polyToken.transferFrom(msg.sender, owner, setupCost), "Unable to pay setup cost");
28+
//Check valid bytes - can only call module init function
29+
MockRedemptionManager mockRedemptionManager = new MockRedemptionManager(msg.sender, address(polyToken));
30+
emit GenerateModuleFromFactory(address(mockRedemptionManager), getName(), address(this), msg.sender, setupCost, now);
31+
return address(mockRedemptionManager);
32+
}
33+
34+
}

contracts/mocks/MockFactory.sol

Lines changed: 22 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,42 @@
11
pragma solidity ^0.4.24;
22

3-
import "../modules/STO/DummySTO.sol";
4-
import "../modules/ModuleFactory.sol";
5-
import "../libraries/Util.sol";
3+
import "../modules/STO/DummySTOFactory.sol";
64

7-
contract MockFactory is ModuleFactory {
5+
/**
6+
* @title Mock Contract Not fit for production environment
7+
*/
88

9+
contract MockFactory is DummySTOFactory {
10+
11+
bool public switchTypes = false;
912
/**
1013
* @notice Constructor
1114
* @param _polyAddress Address of the polytoken
1215
*/
1316
constructor (address _polyAddress, uint256 _setupCost, uint256 _usageCost, uint256 _subscriptionCost) public
14-
ModuleFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost)
17+
DummySTOFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost)
1518
{
16-
version = "1.0.0";
17-
name = "Mock";
18-
title = "Mock Manager";
19-
description = "MockManager";
20-
compatibleSTVersionRange["lowerBound"] = VersionUtils.pack(uint8(0), uint8(0), uint8(0));
21-
compatibleSTVersionRange["upperBound"] = VersionUtils.pack(uint8(0), uint8(0), uint8(0));
22-
}
2319

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

4022
/**
4123
* @notice Type of the Module factory
4224
*/
4325
function getTypes() external view returns(uint8[]) {
44-
uint8[] memory res = new uint8[](0);
45-
return res;
46-
}
47-
48-
/**
49-
* @notice Get the name of the Module
50-
*/
51-
function getName() public view returns(bytes32) {
52-
return name;
53-
}
54-
55-
/**
56-
* @notice Get the description of the Module
57-
*/
58-
function getDescription() external view returns(string) {
59-
return description;
60-
}
61-
62-
/**
63-
* @notice Get the title of the Module
64-
*/
65-
function getTitle() external view returns(string) {
66-
return title;
67-
}
68-
69-
/**
70-
* @notice Get the version of the Module
71-
*/
72-
function getVersion() external view returns(string) {
73-
return version;
74-
}
75-
76-
/**
77-
* @notice Get the setup cost of the module
78-
*/
79-
function getSetupCost() external view returns (uint256) {
80-
return setupCost;
81-
}
82-
83-
/**
84-
* @notice Returns the instructions associated with the module
85-
*/
86-
function getInstructions() external view returns(string) {
87-
return "Mock Manager - This is mock in nature";
88-
}
89-
90-
/**
91-
* @notice Get the tags related to the module factory
92-
*/
93-
function getTags() external view returns(bytes32[]) {
94-
bytes32[] memory availableTags = new bytes32[](4);
95-
availableTags[0] = "Mock";
96-
return availableTags;
26+
if (!switchTypes) {
27+
uint8[] memory types = new uint8[](0);
28+
return types;
29+
} else {
30+
uint8[] memory res = new uint8[](2);
31+
res[0] = 1;
32+
res[1] = 1;
33+
return res;
34+
}
35+
36+
}
37+
38+
function changeTypes() external onlyOwner {
39+
switchTypes = !switchTypes;
9740
}
9841

9942
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
pragma solidity ^0.4.24;
2+
3+
import "../modules/Burn/TrackedRedemption.sol";
4+
5+
/**
6+
* @title Burn module for burning tokens and keeping track of burnt amounts
7+
*/
8+
contract MockRedemptionManager is TrackedRedemption {
9+
10+
mapping (address => uint256) tokenToRedeem;
11+
12+
event RedeemedTokenByOwner(address _investor, address _byWhoom, uint256 _value, uint256 _timestamp);
13+
14+
/**
15+
* @notice Constructor
16+
* @param _securityToken Address of the security token
17+
* @param _polyAddress Address of the polytoken
18+
*/
19+
constructor (address _securityToken, address _polyAddress) public
20+
TrackedRedemption(_securityToken, _polyAddress)
21+
{
22+
}
23+
24+
/**
25+
* @notice Transfer tokens to Module to burn
26+
* @param _value The number of tokens to redeem
27+
*/
28+
function transferToRedeem(uint256 _value) public {
29+
require(ISecurityToken(securityToken).transferFrom(msg.sender, address(this), _value), "Insufficient funds");
30+
tokenToRedeem[msg.sender] = _value;
31+
}
32+
33+
/**
34+
* @notice use to redeem tokens by the module
35+
* @param _value The number of tokens to redeem
36+
*/
37+
function redeemTokenByOwner(uint256 _value) public {
38+
require(tokenToRedeem[msg.sender] >= _value);
39+
tokenToRedeem[msg.sender] = tokenToRedeem[msg.sender].sub(_value);
40+
redeemedTokens[msg.sender] = redeemedTokens[msg.sender].add(_value);
41+
ISecurityToken(securityToken).burnWithData(_value, "");
42+
emit RedeemedTokenByOwner(msg.sender, address(this), _value, now);
43+
}
44+
45+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
pragma solidity ^0.4.24;
2+
3+
import "./MockBurnFactory.sol";
4+
import "../modules/ModuleFactory.sol";
5+
import "../libraries/Util.sol";
6+
7+
/**
8+
* @title Mock Contract Not fit for production environment
9+
*/
10+
11+
contract MockWrongTypeFactory is MockBurnFactory {
12+
13+
/**
14+
* @notice Constructor
15+
* @param _polyAddress Address of the polytoken
16+
*/
17+
constructor (address _polyAddress, uint256 _setupCost, uint256 _usageCost, uint256 _subscriptionCost) public
18+
MockBurnFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost)
19+
{
20+
}
21+
22+
/**
23+
* @notice Type of the Module factory
24+
*/
25+
function getTypes() external view returns(uint8[]) {
26+
uint8[] memory types = new uint8[](1);
27+
types[0] = 4;
28+
return types;
29+
}
30+
31+
}

contracts/mocks/TestSTOFactory.sol

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
pragma solidity ^0.4.24;
22

3-
import "../modules/STO/DummySTO.sol";
4-
import "../modules/ModuleFactory.sol";
5-
import "../libraries/Util.sol";
3+
import "../modules/STO/DummySTOFactory.sol";
64

7-
contract TestSTOFactory is ModuleFactory {
5+
contract TestSTOFactory is DummySTOFactory {
86

97
/**
108
* @notice Constructor
119
* @param _polyAddress Address of the polytoken
1210
*/
1311
constructor (address _polyAddress, uint256 _setupCost, uint256 _usageCost, uint256 _subscriptionCost) public
14-
ModuleFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost)
12+
DummySTOFactory(_polyAddress, _setupCost, _usageCost, _subscriptionCost)
1513
{
1614
version = "1.0.0";
1715
name = "TestSTO";
@@ -21,66 +19,6 @@ contract TestSTOFactory is ModuleFactory {
2119
compatibleSTVersionRange["upperBound"] = VersionUtils.pack(uint8(0), uint8(0), uint8(0));
2220
}
2321

24-
/**
25-
* @notice used to launch the Module with the help of factory
26-
* @param _data Data used for the intialization of the module factory variables
27-
* @return address Contract address of the Module
28-
*/
29-
function deploy(bytes _data) external returns(address) {
30-
if(setupCost > 0)
31-
require(polyToken.transferFrom(msg.sender, owner, setupCost), "Failed transferFrom because of sufficent Allowance is not provided");
32-
//Check valid bytes - can only call module init function
33-
DummySTO dummySTO = new DummySTO(msg.sender, address(polyToken));
34-
//Checks that _data is valid (not calling anything it shouldn't)
35-
require(Util.getSig(_data) == dummySTO.getInitFunction(), "Provided data is not valid");
36-
require(address(dummySTO).call(_data), "Un-successfull call");
37-
return address(dummySTO);
38-
}
39-
40-
/**
41-
* @notice Type of the Module factory
42-
*/
43-
function getTypes() external view returns(uint8[]) {
44-
uint8[] memory res = new uint8[](1);
45-
res[0] = 3;
46-
return res;
47-
}
48-
49-
/**
50-
* @notice Get the name of the Module
51-
*/
52-
function getName() external view returns(bytes32) {
53-
return name;
54-
}
55-
56-
/**
57-
* @notice Get the description of the Module
58-
*/
59-
function getDescription() external view returns(string) {
60-
return description;
61-
}
62-
63-
/**
64-
* @notice Get the title of the Module
65-
*/
66-
function getTitle() external view returns(string) {
67-
return title;
68-
}
69-
70-
/**
71-
* @notice Get the version of the Module
72-
*/
73-
function getVersion() external view returns(string) {
74-
return version;
75-
}
76-
77-
/**
78-
* @notice Get the setup cost of the module
79-
*/
80-
function getSetupCost() external view returns (uint256) {
81-
return setupCost;
82-
}
83-
8422
/**
8523
* @notice Returns the instructions associated with the module
8624
*/

0 commit comments

Comments
 (0)