Skip to content

Commit

Permalink
test coverage increased
Browse files Browse the repository at this point in the history
  • Loading branch information
SatyamSB committed May 15, 2018
1 parent 6577ea6 commit d4185ce
Show file tree
Hide file tree
Showing 18 changed files with 8,300 additions and 348 deletions.
3 changes: 2 additions & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ module.exports = {
'helpers/PolyToken.sol',
'Migrations.sol',
'mocks/PolyTokenFaucet.sol',
'mocks/TestSTOFactory.sol']
'mocks/TestSTOFactory.sol',
'mocks/MockFactory.sol']
};
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Build Status](https://travis-ci.org/PolymathNetwork/polymath-core.svg?branch=master)](https://travis-ci.org/PolymathNetwork/polymath-core)
[![Coverage Status](https://coveralls.io/repos/github/PolymathNetwork/polymath-core/badge.svg?branch=master)](https://coveralls.io/github/PolymathNetwork/polymath-core?branch=master)
<a href="https://t.me/polymathnetwork"><img src="https://img.shields.io/badge/50k+-telegram-blue.svg" target="_blank"></a>

![Polymath logo](Polymath.png)
Expand Down
4 changes: 2 additions & 2 deletions contracts/helpers/TokenBurner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ contract TokenBurner {

address public securityToken;

constructor (address _securityToken) {
constructor (address _securityToken) public {
securityToken = _securityToken;
}

function burn(address _burner, uint256 _value) public returns(bool) {
function burn(address /*_burner*/, uint256 /*_value*/) public returns(bool) {
require(msg.sender == securityToken);
// Add the schematics for the burner( token holder) that backing the burning of the securities
return true;
Expand Down
57 changes: 57 additions & 0 deletions contracts/mocks/MockFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
pragma solidity ^0.4.23;

import "../modules/STO/DummySTO.sol";
import "../interfaces/IModuleFactory.sol";
import "../interfaces/IModule.sol";


contract MockFactory is IModuleFactory {

constructor (address _polyAddress) public
IModuleFactory(_polyAddress)
{

}

function deploy(bytes _data) external returns(address) {
if(getCost() > 0)
require(polyToken.transferFrom(msg.sender, owner, getCost()), "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(getSig(_data) == dummySTO.getInitFunction(), "Provided data is not valid");
require(address(dummySTO).call(_data), "Un-successfull call");
return address(dummySTO);
}

function getCost() public view returns(uint256) {
return uint256(1000 * 10 ** 18);
}

function getType() public view returns(uint8) {
return 0;
}

function getName() public view returns(bytes32) {
return "Mock";
}

function getDescription() public view returns(string) {
return "MockManager";
}

function getTitle() public view returns(string) {
return "Mock Manager";
}

function getInstructions() public view returns(string) {
return "Mock Manager - This is mock in nature";
}

function getTags() public view returns(bytes32[]) {
bytes32[] memory availableTags = new bytes32[](4);
availableTags[0] = "Mock";
return availableTags;
}

}
13 changes: 13 additions & 0 deletions contracts/modules/STO/CappedSTO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ contract CappedSTO is ISTO {
return allPermissions;
}

function getSTODetails() public view returns(uint256, uint256, uint256, uint256, uint256, uint256, uint256, bool) {
return (
startTime,
endTime,
cap,
rate,
fundsRaised,
investorCount,
tokensSold,
(fundraiseType == FundraiseType.POLY)
);
}

// -----------------------------------------
// Internal interface (extensible)
// -----------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion contracts/modules/STO/PreSaleSTO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ contract PreSaleSTO is ISTO {
}

function getPermissions() public view returns(bytes32[]) {
bytes32[] memory allPermissions = new bytes32[](0);
bytes32[] memory allPermissions = new bytes32[](1);
allPermissions[0] = PRE_SALE_ADMIN;
return allPermissions;
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"babel-preset-stage-3": "6.24.1",
"babel-register": "6.26.0",
"bignumber.js": "^6.0.0",
"coveralls": "^3.0.1",
"ethereumjs-testrpc": "^6.0.3",
"ethers": "^3.0.15",
"openzeppelin-solidity": "^1.9.0",
Expand Down
76 changes: 76 additions & 0 deletions test/capped_sto.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,22 @@ contract('CappedSTO', accounts => {
assert.ok(errorThrown, message);
});

it("Should buy the tokens -- failed due to invested amount is zero", async () => {
let errorThrown = false;
try {
await web3.eth.sendTransaction({
from: account_investor1,
to: I_CappedSTO.address,
value: web3.utils.toWei('0', 'ether')
});
} catch(error) {
console.log(`Failed due to invested amount is zero`);
errorThrown = true;
ensureException(error);
}
assert.ok(errorThrown, message);
});

it("Should buy the tokens -- Failed due to investor is not in the whitelist", async () => {
let errorThrown = false;
try {
Expand Down Expand Up @@ -565,6 +581,14 @@ contract('CappedSTO', accounts => {
);
});

it("Should get the raised amount of ether", async() => {
assert.equal(await I_CappedSTO.getRaisedEther.call(), web3.utils.toWei('10','ether'));
});

it("Should get the raised amount of poly", async() => {
assert.equal((await I_CappedSTO.getRaisedPOLY.call()).toNumber(), web3.utils.toWei('0','ether'));
});

});

describe("Test Cases for an STO of fundraise type POLY", async() => {
Expand Down Expand Up @@ -820,6 +844,58 @@ contract('CappedSTO', accounts => {
});

});

describe("Test cases for the CappedSTOFactory", async() => {
it("should get the exact details of the factory", async() => {
assert.equal(await I_CappedSTOFactory.getCost.call(),0);
assert.equal(await I_CappedSTOFactory.getType.call(),3);
assert.equal(web3.utils.toAscii(await I_CappedSTOFactory.getName.call())
.replace(/\u0000/g, ''),
"CappedSTO",
"Wrong Module added");
assert.equal(await I_CappedSTOFactory.getDescription.call(),
"Capped STO",
"Wrong Module added");
assert.equal(await I_CappedSTOFactory.getTitle.call(),
"Capped STO",
"Wrong Module added");
assert.equal(await I_CappedSTOFactory.getInstructions.call(),
"Initialises a capped STO. Init parameters are _startTime (time STO starts), _endTime (time STO ends), _cap (cap in tokens for STO), _rate (POLY/ETH to token rate), _fundRaiseType (whether you are raising in POLY or ETH), _polyToken (address of POLY token), _fundsReceiver (address which will receive funds)",
"Wrong Module added");
let tags = await I_CappedSTOFactory.getTags.call();
assert.equal(web3.utils.toAscii(tags[0]).replace(/\u0000/g, ''),"Capped");

});
});

describe("Test cases for the get functions of the capped sto", async() => {
it("Should verify the cap reached or not", async() => {
assert.isTrue(await I_CappedSTO.capReached.call());
});

it("Should get the raised amount of ether", async() => {
assert.equal(await I_CappedSTO.getRaisedEther.call(), web3.utils.toWei('0','ether'));
});

it("Should get the raised amount of poly", async() => {
assert.equal((await I_CappedSTO.getRaisedPOLY.call()).toNumber(), web3.utils.toWei('10000','ether'));
});

it("Should get the investors", async() => {
assert.equal(await I_CappedSTO.getNumberInvestors.call(),2);
});

it("Should get the listed permissions", async() => {
let tx = await I_CappedSTO.getPermissions.call();
assert.equal(tx.length,0);
});

it("Should get the metrics of the STO", async() => {
let metrics = await I_CappedSTO.getSTODetails.call();
assert.isTrue(metrics[7]);
});

});
});

});
62 changes: 62 additions & 0 deletions test/count_transfer_manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import latestTime from './helpers/latestTime';
import { duration, ensureException } from './helpers/utils';
import takeSnapshot, { increaseTime, revertToSnapshot } from './helpers/time';
import { error } from 'util';

const ModuleRegistry = artifacts.require('./ModuleRegistry.sol');
const SecurityToken = artifacts.require('./SecurityToken.sol');
Expand Down Expand Up @@ -357,6 +358,18 @@ contract('CountTransferManager', accounts => {
);
});

it("Should fail in modifying the holder count", async() => {
let errorThrown = false;
try {
await I_CountTransferManager.changeHolderCount(1, { from: account_investor1 });
} catch(error) {
console.log(`Failed due to only owner have the permission to change the holder count`);
errorThrown = true;
ensureException(error);
}
assert.ok(errorThrown, message);
})

it("Modify holder count to 1", async() => {
// Add the Investor in to the whitelist
// Mint some tokens
Expand All @@ -379,9 +392,27 @@ contract('CountTransferManager', accounts => {
);
});

// it("Should not be able to transfer to a token holder", async() => {
// let errorThrown = false;

// await I_CountTransferManager.pause({from: token_owner});
// assert.isTrue(await I_CountTransferManager.paused.call());

// try {
// // Mint some tokens
// await I_SecurityToken.transfer(account_investor1, web3.utils.toWei('1', 'ether'), { from: account_investor2 });
// } catch(error) {
// console.log(`Failed due to transfers are paused`);
// ensureException(error);
// errorThrown = true;
// }
// assert.ok(errorThrown, message);
// });


it("Should not be able to transfer to a new token holder", async() => {
let errorThrown = false;
// await I_CountTransferManager.unpause({from: token_owner});
try {
// Mint some tokens
await I_SecurityToken.transfer(account_investor3, web3.utils.toWei('2', 'ether'), { from: account_investor2 });
Expand All @@ -398,6 +429,37 @@ contract('CountTransferManager', accounts => {
await I_SecurityToken.transfer(account_investor2, web3.utils.toWei('1', 'ether'), { from: account_investor1 });
});

it("Should get the permission list", async() => {
let perm = await I_CountTransferManager.getPermissions.call();
assert.equal(perm.length, 0);
});

describe("Test cases for the factory", async() => {
it("should get the exact details of the factory", async() => {
assert.equal(await I_CountTransferManagerFactory.getCost.call(),0);
assert.equal(await I_CountTransferManagerFactory.getType.call(),2);
assert.equal(web3.utils.toAscii(await I_CountTransferManagerFactory.getName.call())
.replace(/\u0000/g, ''),
"CountTransferManager",
"Wrong Module added");
assert.equal(await I_CountTransferManagerFactory.getDescription.call(),
"Restrict the number of investors",
"Wrong Module added");
assert.equal(await I_CountTransferManagerFactory.getTitle.call(),
"Count Transfer Manager",
"Wrong Module added");
assert.equal(await I_CountTransferManagerFactory.getInstructions.call(),
"Allows an issuer to restrict the total number of non-zero token holders",
"Wrong Module added");

});

it("Should get the tags of the factory", async() => {
let tags = await I_CountTransferManagerFactory.getTags.call();
assert.equal(web3.utils.toAscii(tags[0]).replace(/\u0000/g, ''),"Count");
});
});

});

});
Loading

0 comments on commit d4185ce

Please sign in to comment.