Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test-coverage #147

Merged
merged 9 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint:all": "npm run lint && npm run lint:sol",
"lint:all:fix": "npm run lint:fix && npm run lint:sol:fix",
"compile": "truffle compile --optimize-runs 200",
"ganache-cli": "node_modules/.bin/ganache-cli -i 15 --gasLimit 8900000",
"ganache-cli": "node_modules/.bin/ganache-cli -i 15 --gasLimit 90000000",
"migrate:local": "truffle migrate --network=development --reset --all",
"migrate:ropsten": "truffle migrate --network=ropsten --reset --all",
"migrate:mainnet": "truffle migrate --network=mainnet",
Expand Down
384 changes: 354 additions & 30 deletions test/erc20_dividends.js

Large diffs are not rendered by default.

167 changes: 145 additions & 22 deletions test/manual_approval_transfer_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,7 @@ contract('ManualApprovalTransferManager', accounts => {

// Verify that GeneralTransferManager module get added successfully or not
assert.equal(log.args._type.toNumber(), 2);
assert.equal(
web3.utils.toAscii(log.args._name)
.replace(/\u0000/g, ''),
"GeneralTransferManager"
);
assert.equal(web3.utils.toUtf8(log.args._name), "GeneralTransferManager");
LogAddModule.stopWatching();
});

Expand Down Expand Up @@ -314,12 +310,7 @@ contract('ManualApprovalTransferManager', accounts => {
it("Should successfully attach the ManualApprovalTransferManager with the security token", async () => {
const tx = await I_SecurityToken.addModule(I_ManualApprovalTransferManagerFactory.address, "", 0, 0, false, { from: token_owner });
assert.equal(tx.logs[2].args._type.toNumber(), transferManagerKey, "ManualApprovalTransferManager doesn't get deployed");
assert.equal(
web3.utils.toAscii(tx.logs[2].args._name)
.replace(/\u0000/g, ''),
"ManualApprovalTransferManager",
"ManualApprovalTransferManager module was not added"
);
assert.equal(web3.utils.toUtf8(tx.logs[2].args._name), "ManualApprovalTransferManager", "ManualApprovalTransferManager module was not added");
I_ManualApprovalTransferManager = ManualApprovalTransferManager.at(tx.logs[2].args._module);
});

Expand Down Expand Up @@ -359,10 +350,78 @@ contract('ManualApprovalTransferManager', accounts => {
);
});

it("Should fail to add a manual approval because invalid _from address", async() => {
let errorThrown = false;
try {
await I_ManualApprovalTransferManager.addManualApproval("", account_investor4, web3.utils.toWei('2', 'ether'), latestTime() + duration.days(1), { from: token_owner });
} catch(error) {
console.log(` tx revert -> invalid _from address`.grey);
ensureException(error);
errorThrown = true;
}
assert.ok(errorThrown, message);
});

it("Should fail to add a manual approval because invalid _to address", async() => {
let errorThrown = false;
try {
await I_ManualApprovalTransferManager.addManualApproval(account_investor1, "", web3.utils.toWei('2', 'ether'), latestTime() + duration.days(1), { from: token_owner });
} catch(error) {
console.log(` tx revert -> invalid _to address`.grey);
ensureException(error);
errorThrown = true;
}
assert.ok(errorThrown, message);
});

it("Should fail to add a manual approval because invalid expiry time", async() => {
let errorThrown = false;
try {
await I_ManualApprovalTransferManager.addManualApproval(account_investor1, account_investor4, web3.utils.toWei('2', 'ether'), 99999, { from: token_owner });
} catch(error) {
console.log(` tx revert -> invalid expiry time`.grey);
ensureException(error);
errorThrown = true;
}
assert.ok(errorThrown, message);
});

it("Add a manual approval for a 4th investor", async() => {
await I_ManualApprovalTransferManager.addManualApproval(account_investor1, account_investor4, web3.utils.toWei('2', 'ether'), latestTime() + duration.days(1), { from: token_owner });
});

it("Should fail to revoke manual approval because invalid _from address", async() => {
let errorThrown = false;
try {
await I_ManualApprovalTransferManager.revokeManualApproval("", account_investor4, { from: token_owner });
} catch(error) {
console.log(` tx revert -> invalid _from address`.grey);
ensureException(error);
errorThrown = true;
}
assert.ok(errorThrown, message);
});

it("Should fail to revoke manual approval because invalid _to address", async() => {
let errorThrown = false;
try {
await I_ManualApprovalTransferManager.revokeManualApproval(account_investor1, "", { from: token_owner });
} catch(error) {
console.log(` tx revert -> invalid _to address`.grey);
ensureException(error);
errorThrown = true;
}
assert.ok(errorThrown, message);
});

it("Should revoke manual approval", async() => {
let tx = await I_ManualApprovalTransferManager.revokeManualApproval(account_investor1, account_investor4, { from: token_owner });
assert.equal(tx.logs[0].args._from, account_investor1);
assert.equal(tx.logs[0].args._to, account_investor4);
assert.equal(tx.logs[0].args._addedBy, token_owner);
await I_ManualApprovalTransferManager.addManualApproval(account_investor1, account_investor4, web3.utils.toWei('2', 'ether'), latestTime() + duration.days(1), { from: token_owner });
});

it("Use 50% of manual approval for transfer", async() => {
await I_SecurityToken.transfer(account_investor4, web3.utils.toWei('1', 'ether'), { from: account_investor1 });

Expand Down Expand Up @@ -410,6 +469,42 @@ contract('ManualApprovalTransferManager', accounts => {

});

it("Should fail to add a manual block because invalid _from address", async() => {
let errorThrown = false;
try {
await I_ManualApprovalTransferManager.addManualBlocking("", account_investor2, latestTime() + duration.days(1), { from: token_owner });
} catch(error) {
console.log(` tx revert -> invalid _from address`.grey);
ensureException(error);
errorThrown = true;
}
assert.ok(errorThrown, message);
});

it("Should fail to add a manual block because invalid _to address", async() => {
let errorThrown = false;
try {
await I_ManualApprovalTransferManager.addManualBlocking(account_investor1, "", latestTime() + duration.days(1), { from: token_owner });
} catch(error) {
console.log(` tx revert -> invalid _to address`.grey);
ensureException(error);
errorThrown = true;
}
assert.ok(errorThrown, message);
});

it("Should fail to add a manual block because invalid expiry time", async() => {
let errorThrown = false;
try {
await I_ManualApprovalTransferManager.addManualBlocking(account_investor1, account_investor2, 99999, { from: token_owner });
} catch(error) {
console.log(` tx revert -> invalid expiry time`.grey);
ensureException(error);
errorThrown = true;
}
assert.ok(errorThrown, message);
});

it("Add a manual block for a 2nd investor", async() => {
await I_ManualApprovalTransferManager.addManualBlocking(account_investor1, account_investor2, latestTime() + duration.days(1), { from: token_owner });
});
Expand All @@ -427,6 +522,30 @@ contract('ManualApprovalTransferManager', accounts => {

});

it("Should fail to revoke manual block because invalid _from address", async() => {
let errorThrown = false;
try {
await I_ManualApprovalTransferManager.revokeManualBlocking("0x0", account_investor2, { from: token_owner });
} catch(error) {
console.log(` tx revert -> invalid _from address`.grey);
ensureException(error);
errorThrown = true;
}
assert.ok(errorThrown, message);
});

it("Should fail to revoke manual block because invalid _to address", async() => {
let errorThrown = false;
try {
await I_ManualApprovalTransferManager.revokeManualBlocking(account_investor1, "0x0", { from: token_owner });
} catch(error) {
console.log(` tx revert -> invalid _to address`.grey);
ensureException(error);
errorThrown = true;
}
assert.ok(errorThrown, message);
});

it("Revoke manual block and check transfer works", async() => {
await I_ManualApprovalTransferManager.revokeManualBlocking(account_investor1, account_investor2, { from: token_owner });
await I_SecurityToken.transfer(account_investor2, web3.utils.toWei('1', 'ether'), { from: account_investor1 });
Expand Down Expand Up @@ -464,16 +583,16 @@ contract('ManualApprovalTransferManager', accounts => {

const tx = await I_SecurityToken.addModule(I_CountTransferManagerFactory.address, bytesCountTM, 0, 0, false, { from: token_owner });
assert.equal(tx.logs[2].args._type.toNumber(), transferManagerKey, "CountTransferManager doesn't get deployed");
assert.equal(
web3.utils.toAscii(tx.logs[2].args._name)
.replace(/\u0000/g, ''),
"CountTransferManager",
"CountTransferManager module was not added"
);
let name = web3.utils.toUtf8(tx.logs[2].args._name);
assert.equal(name, "CountTransferManager", "CountTransferManager module was not added");
I_CountTransferManager = CountTransferManager.at(tx.logs[2].args._module);

});

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

// it("Check manual approval has a higher priority than an INVALID result from another TM", async() => {
// //Should fail initial transfer
Expand All @@ -497,15 +616,19 @@ contract('ManualApprovalTransferManager', accounts => {
it("Should get the exact details of the factory", async() => {
assert.equal(await I_ManualApprovalTransferManagerFactory.setupCost.call(),0);
assert.equal(await I_ManualApprovalTransferManagerFactory.getType.call(),2);
assert.equal(web3.utils.toAscii(await I_ManualApprovalTransferManagerFactory.getName.call())
.replace(/\u0000/g, ''),
"ManualApprovalTransferManager",
"Wrong Module added");
let name = web3.utils.toUtf8(await I_ManualApprovalTransferManagerFactory.getName.call());
assert.equal(name,"ManualApprovalTransferManager","Wrong Module added");
let desc = await I_ManualApprovalTransferManagerFactory.getDescription.call();
assert.equal(desc,"Manage transfers using single approvals / blocking","Wrong Module added");
let title = await I_ManualApprovalTransferManagerFactory.getTitle.call();
assert.equal(title,"Manual Approval Transfer Manager","Wrong Module added");
let inst = await I_ManualApprovalTransferManagerFactory.getInstructions.call();
assert.equal(inst,"Allows an issuer to set manual approvals or blocks for specific pairs of addresses and amounts. Init function takes no parameters.","Wrong Module added");
});

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

Expand Down
16 changes: 15 additions & 1 deletion test/module_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,21 @@ contract('ModuleRegistry', accounts => {

describe("Test cases of register module", async() => {

it("Should succssfully registered the module", async() => {
it("Should fail to register module if registration is paused", async() => {
let errorThrown = false;
try {
await I_ModuleRegistry.pause({ from: account_polymath});
await I_ModuleRegistry.registerModule(I_GeneralTransferManagerFactory.address, { from: account_polymath });
} catch(error) {
console.log(` tx revert -> Registration is paused`.grey);
errorThrown = true;
ensureException(error);
}
assert.ok(errorThrown, message);
});

it("Should succssfully register the module", async() => {
await I_ModuleRegistry.unpause({ from: account_polymath});
let tx = await I_ModuleRegistry.registerModule(I_GeneralTransferManagerFactory.address, { from: account_polymath });

assert.equal(
Expand Down
82 changes: 70 additions & 12 deletions test/security_token.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,7 @@ contract('SecurityToken', accounts => {

// Verify that GeneralTransferManager module get added successfully or not
assert.equal(log.args._type.toNumber(), transferManagerKey);
assert.equal(
web3.utils.toAscii(log.args._name)
.replace(/\u0000/g, ''),
"GeneralTransferManager"
);
assert.equal(web3.utils.toUtf8(log.args._name),"GeneralTransferManager");
LogAddModule.stopWatching();
});

Expand Down Expand Up @@ -385,6 +381,38 @@ contract('SecurityToken', accounts => {
await revertToSnapshot(id);
});

it("Should fail to attach the STO factory because not enough poly in contract", async () => {
startTime = latestTime() + duration.seconds(5000);
endTime = startTime + duration.days(30);
let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, [startTime, endTime, cap, rate, fundRaiseType, account_fundsReceiver]);
let errorThrown = false;
try {
let tx = await I_SecurityToken.addModule(I_CappedSTOFactory.address, bytesSTO, maxCost, 0, true, { from: token_owner, gas: 60000000 });
} catch (error) {
console.log(` tx revert -> not enough poly in contract`);
errorThrown = true;
ensureException(error);
}
assert.ok(errorThrown, message);
});

it("Should fail to attach the STO factory because max cost too small", async () => {
startTime = latestTime() + duration.seconds(5000);
endTime = startTime + duration.days(30);
let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, [startTime, endTime, cap, rate, fundRaiseType, account_fundsReceiver]);
await I_PolyToken.getTokens(cappedSTOSetupCost, token_owner);
await I_PolyToken.transfer(I_SecurityToken.address, cappedSTOSetupCost, { from: token_owner});
let errorThrown = false;
try {
let tx = await I_SecurityToken.addModule(I_CappedSTOFactory.address, bytesSTO, web3.utils.toWei("1000","ether"), 0, true, { from: token_owner, gas: 60000000 });
} catch (error) {
console.log(` tx revert -> max cost too small`);
errorThrown = true;
ensureException(error);
}
assert.ok(errorThrown, message);
});

it("Should successfully attach the STO factory with the security token", async () => {
startTime = latestTime() + duration.seconds(5000);
endTime = startTime + duration.days(30);
Expand All @@ -396,14 +424,44 @@ contract('SecurityToken', accounts => {
const tx = await I_SecurityToken.addModule(I_CappedSTOFactory.address, bytesSTO, maxCost, 0, true, { from: token_owner, gas: 60000000 });

assert.equal(tx.logs[3].args._type, stoKey, "CappedSTO doesn't get deployed");
assert.equal(
web3.utils.toAscii(tx.logs[3].args._name)
.replace(/\u0000/g, ''),
"CappedSTO",
"CappedSTOFactory module was not added"
);
assert.equal(web3.utils.toUtf8(tx.logs[3].args._name), "CappedSTO", "CappedSTOFactory module was not added");
I_CappedSTO = CappedSTO.at(tx.logs[3].args._module);
});

});

describe("Upgradability functions", async() => {

it("Should fail to change the security token registry address because address(0)", async() => {
let errorThrown = false;
try {
let tx = await I_SecurityToken.changeSecurityTokenRegistryAddress("0x0000000000000000000000000000000000000000", { from: token_owner });
} catch (error) {
console.log(` tx revert -> msg.sender should be the owner of the token`);
errorThrown = true;
ensureException(error);
}
assert.ok(errorThrown, message);
});

it("Should fail to change the security token registry address because same address", async() => {
let errorThrown = false;
try {
let tx = await I_SecurityToken.changeSecurityTokenRegistryAddress(I_SecurityTokenRegistry.address, { from: token_owner });
} catch (error) {
console.log(` tx revert -> msg.sender should be the owner of the token`);
errorThrown = true;
ensureException(error);
}
assert.ok(errorThrown, message);
});

it("Should successfully change the STR address", async() => {
let tx = await I_SecurityToken.changeSecurityTokenRegistryAddress("0x0000000000000000000000000000000000000001", { from: token_owner });
assert.equal(tx.logs[0].args._newAddress, "0x0000000000000000000000000000000000000001")
await I_SecurityToken.changeSecurityTokenRegistryAddress(I_SecurityTokenRegistry.address, { from: token_owner });
});

});

describe("Module related functions", async() => {
Expand Down Expand Up @@ -447,7 +505,7 @@ contract('SecurityToken', accounts => {
try {
let log = await I_SecurityToken.updateTokenDetails("new token details", {from: account_delegate});
} catch (error) {
console.log(`msg.sender should be the owner of the token`);
console.log(` tx revert -> msg.sender should be the owner of the token`);
errorThrown = true;
ensureException(error);
}
Expand Down
Loading