Skip to content

Commit 364ea2a

Browse files
authored
Merge pull request #147 from PolymathNetwork/testcoverage-steph
Test-coverage improvement
2 parents 6e6cf38 + cd774c4 commit 364ea2a

File tree

7 files changed

+722
-78
lines changed

7 files changed

+722
-78
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"lint:all": "npm run lint && npm run lint:sol",
1616
"lint:all:fix": "npm run lint:fix && npm run lint:sol:fix",
1717
"compile": "truffle compile --optimize-runs 200",
18-
"ganache-cli": "node_modules/.bin/ganache-cli -i 15 --gasLimit 8900000",
18+
"ganache-cli": "node_modules/.bin/ganache-cli -i 15 --gasLimit 90000000",
1919
"migrate:local": "truffle migrate --network=development --reset --all",
2020
"migrate:ropsten": "truffle migrate --network=ropsten --reset --all",
2121
"migrate:mainnet": "truffle migrate --network=mainnet",

test/erc20_dividends.js

Lines changed: 354 additions & 30 deletions
Large diffs are not rendered by default.

test/manual_approval_transfer_manager.js

Lines changed: 145 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,7 @@ contract('ManualApprovalTransferManager', accounts => {
234234

235235
// Verify that GeneralTransferManager module get added successfully or not
236236
assert.equal(log.args._type.toNumber(), 2);
237-
assert.equal(
238-
web3.utils.toAscii(log.args._name)
239-
.replace(/\u0000/g, ''),
240-
"GeneralTransferManager"
241-
);
237+
assert.equal(web3.utils.toUtf8(log.args._name), "GeneralTransferManager");
242238
LogAddModule.stopWatching();
243239
});
244240

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

@@ -359,10 +350,78 @@ contract('ManualApprovalTransferManager', accounts => {
359350
);
360351
});
361352

353+
it("Should fail to add a manual approval because invalid _from address", async() => {
354+
let errorThrown = false;
355+
try {
356+
await I_ManualApprovalTransferManager.addManualApproval("", account_investor4, web3.utils.toWei('2', 'ether'), latestTime() + duration.days(1), { from: token_owner });
357+
} catch(error) {
358+
console.log(` tx revert -> invalid _from address`.grey);
359+
ensureException(error);
360+
errorThrown = true;
361+
}
362+
assert.ok(errorThrown, message);
363+
});
364+
365+
it("Should fail to add a manual approval because invalid _to address", async() => {
366+
let errorThrown = false;
367+
try {
368+
await I_ManualApprovalTransferManager.addManualApproval(account_investor1, "", web3.utils.toWei('2', 'ether'), latestTime() + duration.days(1), { from: token_owner });
369+
} catch(error) {
370+
console.log(` tx revert -> invalid _to address`.grey);
371+
ensureException(error);
372+
errorThrown = true;
373+
}
374+
assert.ok(errorThrown, message);
375+
});
376+
377+
it("Should fail to add a manual approval because invalid expiry time", async() => {
378+
let errorThrown = false;
379+
try {
380+
await I_ManualApprovalTransferManager.addManualApproval(account_investor1, account_investor4, web3.utils.toWei('2', 'ether'), 99999, { from: token_owner });
381+
} catch(error) {
382+
console.log(` tx revert -> invalid expiry time`.grey);
383+
ensureException(error);
384+
errorThrown = true;
385+
}
386+
assert.ok(errorThrown, message);
387+
});
388+
362389
it("Add a manual approval for a 4th investor", async() => {
363390
await I_ManualApprovalTransferManager.addManualApproval(account_investor1, account_investor4, web3.utils.toWei('2', 'ether'), latestTime() + duration.days(1), { from: token_owner });
364391
});
365392

393+
it("Should fail to revoke manual approval because invalid _from address", async() => {
394+
let errorThrown = false;
395+
try {
396+
await I_ManualApprovalTransferManager.revokeManualApproval("", account_investor4, { from: token_owner });
397+
} catch(error) {
398+
console.log(` tx revert -> invalid _from address`.grey);
399+
ensureException(error);
400+
errorThrown = true;
401+
}
402+
assert.ok(errorThrown, message);
403+
});
404+
405+
it("Should fail to revoke manual approval because invalid _to address", async() => {
406+
let errorThrown = false;
407+
try {
408+
await I_ManualApprovalTransferManager.revokeManualApproval(account_investor1, "", { from: token_owner });
409+
} catch(error) {
410+
console.log(` tx revert -> invalid _to address`.grey);
411+
ensureException(error);
412+
errorThrown = true;
413+
}
414+
assert.ok(errorThrown, message);
415+
});
416+
417+
it("Should revoke manual approval", async() => {
418+
let tx = await I_ManualApprovalTransferManager.revokeManualApproval(account_investor1, account_investor4, { from: token_owner });
419+
assert.equal(tx.logs[0].args._from, account_investor1);
420+
assert.equal(tx.logs[0].args._to, account_investor4);
421+
assert.equal(tx.logs[0].args._addedBy, token_owner);
422+
await I_ManualApprovalTransferManager.addManualApproval(account_investor1, account_investor4, web3.utils.toWei('2', 'ether'), latestTime() + duration.days(1), { from: token_owner });
423+
});
424+
366425
it("Use 50% of manual approval for transfer", async() => {
367426
await I_SecurityToken.transfer(account_investor4, web3.utils.toWei('1', 'ether'), { from: account_investor1 });
368427

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

411470
});
412471

472+
it("Should fail to add a manual block because invalid _from address", async() => {
473+
let errorThrown = false;
474+
try {
475+
await I_ManualApprovalTransferManager.addManualBlocking("", account_investor2, latestTime() + duration.days(1), { from: token_owner });
476+
} catch(error) {
477+
console.log(` tx revert -> invalid _from address`.grey);
478+
ensureException(error);
479+
errorThrown = true;
480+
}
481+
assert.ok(errorThrown, message);
482+
});
483+
484+
it("Should fail to add a manual block because invalid _to address", async() => {
485+
let errorThrown = false;
486+
try {
487+
await I_ManualApprovalTransferManager.addManualBlocking(account_investor1, "", latestTime() + duration.days(1), { from: token_owner });
488+
} catch(error) {
489+
console.log(` tx revert -> invalid _to address`.grey);
490+
ensureException(error);
491+
errorThrown = true;
492+
}
493+
assert.ok(errorThrown, message);
494+
});
495+
496+
it("Should fail to add a manual block because invalid expiry time", async() => {
497+
let errorThrown = false;
498+
try {
499+
await I_ManualApprovalTransferManager.addManualBlocking(account_investor1, account_investor2, 99999, { from: token_owner });
500+
} catch(error) {
501+
console.log(` tx revert -> invalid expiry time`.grey);
502+
ensureException(error);
503+
errorThrown = true;
504+
}
505+
assert.ok(errorThrown, message);
506+
});
507+
413508
it("Add a manual block for a 2nd investor", async() => {
414509
await I_ManualApprovalTransferManager.addManualBlocking(account_investor1, account_investor2, latestTime() + duration.days(1), { from: token_owner });
415510
});
@@ -427,6 +522,30 @@ contract('ManualApprovalTransferManager', accounts => {
427522

428523
});
429524

525+
it("Should fail to revoke manual block because invalid _from address", async() => {
526+
let errorThrown = false;
527+
try {
528+
await I_ManualApprovalTransferManager.revokeManualBlocking("0x0", account_investor2, { from: token_owner });
529+
} catch(error) {
530+
console.log(` tx revert -> invalid _from address`.grey);
531+
ensureException(error);
532+
errorThrown = true;
533+
}
534+
assert.ok(errorThrown, message);
535+
});
536+
537+
it("Should fail to revoke manual block because invalid _to address", async() => {
538+
let errorThrown = false;
539+
try {
540+
await I_ManualApprovalTransferManager.revokeManualBlocking(account_investor1, "0x0", { from: token_owner });
541+
} catch(error) {
542+
console.log(` tx revert -> invalid _to address`.grey);
543+
ensureException(error);
544+
errorThrown = true;
545+
}
546+
assert.ok(errorThrown, message);
547+
});
548+
430549
it("Revoke manual block and check transfer works", async() => {
431550
await I_ManualApprovalTransferManager.revokeManualBlocking(account_investor1, account_investor2, { from: token_owner });
432551
await I_SecurityToken.transfer(account_investor2, web3.utils.toWei('1', 'ether'), { from: account_investor1 });
@@ -464,16 +583,16 @@ contract('ManualApprovalTransferManager', accounts => {
464583

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

475590
});
476591

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

478597
// it("Check manual approval has a higher priority than an INVALID result from another TM", async() => {
479598
// //Should fail initial transfer
@@ -497,15 +616,19 @@ contract('ManualApprovalTransferManager', accounts => {
497616
it("Should get the exact details of the factory", async() => {
498617
assert.equal(await I_ManualApprovalTransferManagerFactory.setupCost.call(),0);
499618
assert.equal(await I_ManualApprovalTransferManagerFactory.getType.call(),2);
500-
assert.equal(web3.utils.toAscii(await I_ManualApprovalTransferManagerFactory.getName.call())
501-
.replace(/\u0000/g, ''),
502-
"ManualApprovalTransferManager",
503-
"Wrong Module added");
619+
let name = web3.utils.toUtf8(await I_ManualApprovalTransferManagerFactory.getName.call());
620+
assert.equal(name,"ManualApprovalTransferManager","Wrong Module added");
621+
let desc = await I_ManualApprovalTransferManagerFactory.getDescription.call();
622+
assert.equal(desc,"Manage transfers using single approvals / blocking","Wrong Module added");
623+
let title = await I_ManualApprovalTransferManagerFactory.getTitle.call();
624+
assert.equal(title,"Manual Approval Transfer Manager","Wrong Module added");
625+
let inst = await I_ManualApprovalTransferManagerFactory.getInstructions.call();
626+
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");
504627
});
505628

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

test/module_registry.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,21 @@ contract('ModuleRegistry', accounts => {
204204

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

207-
it("Should succssfully registered the module", async() => {
207+
it("Should fail to register module if registration is paused", async() => {
208+
let errorThrown = false;
209+
try {
210+
await I_ModuleRegistry.pause({ from: account_polymath});
211+
await I_ModuleRegistry.registerModule(I_GeneralTransferManagerFactory.address, { from: account_polymath });
212+
} catch(error) {
213+
console.log(` tx revert -> Registration is paused`.grey);
214+
errorThrown = true;
215+
ensureException(error);
216+
}
217+
assert.ok(errorThrown, message);
218+
});
219+
220+
it("Should succssfully register the module", async() => {
221+
await I_ModuleRegistry.unpause({ from: account_polymath});
208222
let tx = await I_ModuleRegistry.registerModule(I_GeneralTransferManagerFactory.address, { from: account_polymath });
209223

210224
assert.equal(

test/security_token.js

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,7 @@ contract('SecurityToken', accounts => {
269269

270270
// Verify that GeneralTransferManager module get added successfully or not
271271
assert.equal(log.args._type.toNumber(), transferManagerKey);
272-
assert.equal(
273-
web3.utils.toAscii(log.args._name)
274-
.replace(/\u0000/g, ''),
275-
"GeneralTransferManager"
276-
);
272+
assert.equal(web3.utils.toUtf8(log.args._name),"GeneralTransferManager");
277273
LogAddModule.stopWatching();
278274
});
279275

@@ -385,6 +381,38 @@ contract('SecurityToken', accounts => {
385381
await revertToSnapshot(id);
386382
});
387383

384+
it("Should fail to attach the STO factory because not enough poly in contract", async () => {
385+
startTime = latestTime() + duration.seconds(5000);
386+
endTime = startTime + duration.days(30);
387+
let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, [startTime, endTime, cap, rate, fundRaiseType, account_fundsReceiver]);
388+
let errorThrown = false;
389+
try {
390+
let tx = await I_SecurityToken.addModule(I_CappedSTOFactory.address, bytesSTO, maxCost, 0, true, { from: token_owner, gas: 60000000 });
391+
} catch (error) {
392+
console.log(` tx revert -> not enough poly in contract`);
393+
errorThrown = true;
394+
ensureException(error);
395+
}
396+
assert.ok(errorThrown, message);
397+
});
398+
399+
it("Should fail to attach the STO factory because max cost too small", async () => {
400+
startTime = latestTime() + duration.seconds(5000);
401+
endTime = startTime + duration.days(30);
402+
let bytesSTO = web3.eth.abi.encodeFunctionCall(functionSignature, [startTime, endTime, cap, rate, fundRaiseType, account_fundsReceiver]);
403+
await I_PolyToken.getTokens(cappedSTOSetupCost, token_owner);
404+
await I_PolyToken.transfer(I_SecurityToken.address, cappedSTOSetupCost, { from: token_owner});
405+
let errorThrown = false;
406+
try {
407+
let tx = await I_SecurityToken.addModule(I_CappedSTOFactory.address, bytesSTO, web3.utils.toWei("1000","ether"), 0, true, { from: token_owner, gas: 60000000 });
408+
} catch (error) {
409+
console.log(` tx revert -> max cost too small`);
410+
errorThrown = true;
411+
ensureException(error);
412+
}
413+
assert.ok(errorThrown, message);
414+
});
415+
388416
it("Should successfully attach the STO factory with the security token", async () => {
389417
startTime = latestTime() + duration.seconds(5000);
390418
endTime = startTime + duration.days(30);
@@ -396,14 +424,44 @@ contract('SecurityToken', accounts => {
396424
const tx = await I_SecurityToken.addModule(I_CappedSTOFactory.address, bytesSTO, maxCost, 0, true, { from: token_owner, gas: 60000000 });
397425

398426
assert.equal(tx.logs[3].args._type, stoKey, "CappedSTO doesn't get deployed");
399-
assert.equal(
400-
web3.utils.toAscii(tx.logs[3].args._name)
401-
.replace(/\u0000/g, ''),
402-
"CappedSTO",
403-
"CappedSTOFactory module was not added"
404-
);
427+
assert.equal(web3.utils.toUtf8(tx.logs[3].args._name), "CappedSTO", "CappedSTOFactory module was not added");
405428
I_CappedSTO = CappedSTO.at(tx.logs[3].args._module);
406429
});
430+
431+
});
432+
433+
describe("Upgradability functions", async() => {
434+
435+
it("Should fail to change the security token registry address because address(0)", async() => {
436+
let errorThrown = false;
437+
try {
438+
let tx = await I_SecurityToken.changeSecurityTokenRegistryAddress("0x0000000000000000000000000000000000000000", { from: token_owner });
439+
} catch (error) {
440+
console.log(` tx revert -> msg.sender should be the owner of the token`);
441+
errorThrown = true;
442+
ensureException(error);
443+
}
444+
assert.ok(errorThrown, message);
445+
});
446+
447+
it("Should fail to change the security token registry address because same address", async() => {
448+
let errorThrown = false;
449+
try {
450+
let tx = await I_SecurityToken.changeSecurityTokenRegistryAddress(I_SecurityTokenRegistry.address, { from: token_owner });
451+
} catch (error) {
452+
console.log(` tx revert -> msg.sender should be the owner of the token`);
453+
errorThrown = true;
454+
ensureException(error);
455+
}
456+
assert.ok(errorThrown, message);
457+
});
458+
459+
it("Should successfully change the STR address", async() => {
460+
let tx = await I_SecurityToken.changeSecurityTokenRegistryAddress("0x0000000000000000000000000000000000000001", { from: token_owner });
461+
assert.equal(tx.logs[0].args._newAddress, "0x0000000000000000000000000000000000000001")
462+
await I_SecurityToken.changeSecurityTokenRegistryAddress(I_SecurityTokenRegistry.address, { from: token_owner });
463+
});
464+
407465
});
408466

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

0 commit comments

Comments
 (0)