Skip to content

Commit bd09190

Browse files
authored
Merge pull request #755 from PolymathNetwork/chore/reason-strings-cont
Unit testing: add explicit revert reason checks
2 parents 3ab0a11 + a683165 commit bd09190

27 files changed

+1381
-806
lines changed

test/b_capped_sto.js

Lines changed: 68 additions & 39 deletions
Large diffs are not rendered by default.

test/d_count_transfer_manager.js

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,13 @@ contract("CountTransferManager", async (accounts) => {
168168
I_GeneralTransferManager = await GeneralTransferManager.at(moduleData);
169169
});
170170

171-
it("Should successfully attach the CountTransferManager factory with the security token", async () => {
171+
it("Should FAIL to attach a CountTransferManager without sufficient tokens", async () => {
172172
await I_PolyToken.getTokens(new BN(web3.utils.toWei("2000", "ether")), token_owner);
173173
await catchRevert(
174174
I_SecurityToken.addModule(P_CountTransferManagerFactory.address, bytesSTO, new BN(web3.utils.toWei("2000", "ether")), new BN(0), false, {
175175
from: token_owner
176-
})
176+
}),
177+
"Insufficient tokens transferable"
177178
);
178179
});
179180

@@ -310,8 +311,8 @@ contract("CountTransferManager", async (accounts) => {
310311
"Failed in adding the investor in whitelist"
311312
);
312313

313-
await catchRevert(I_SecurityToken.issue(account_investor3, new BN(web3.utils.toWei("3", "ether")), "0x0", { from: token_owner }));
314-
await catchRevert(I_SecurityToken.transfer(account_investor3, new BN(web3.utils.toWei("1", "ether")), { from: account_investor2 }));
314+
await catchRevert(I_SecurityToken.issue(account_investor3, new BN(web3.utils.toWei("3", "ether")), "0x0", { from: token_owner }), "Transfer Invalid");
315+
await catchRevert(I_SecurityToken.transfer(account_investor3, new BN(web3.utils.toWei("1", "ether")), { from: account_investor2 }), "Transfer Invalid");
315316
let canTransfer = await I_SecurityToken.canTransfer(account_investor3, new BN(web3.utils.toWei("1", "ether")), "0x0", { from: account_investor2 });
316317
assert.equal(canTransfer[0], "0x50"); //Transfer failure.
317318
});
@@ -333,7 +334,7 @@ contract("CountTransferManager", async (accounts) => {
333334
});
334335

335336
it("Should fail in modifying the holder count", async () => {
336-
await catchRevert(I_CountTransferManager.changeHolderCount(1, { from: account_investor1 }));
337+
await catchRevert(I_CountTransferManager.changeHolderCount(1, { from: account_investor1 }), "Invalid permission");
337338
});
338339

339340
it("Modify holder count to 1", async () => {
@@ -354,7 +355,7 @@ contract("CountTransferManager", async (accounts) => {
354355

355356
it("Should not be able to transfer to a new token holder", async () => {
356357
// await I_CountTransferManager.unpause({from: token_owner});
357-
await catchRevert(I_SecurityToken.transfer(account_investor3, new BN(web3.utils.toWei("2", "ether")), { from: account_investor2 }));
358+
await catchRevert(I_SecurityToken.transfer(account_investor3, new BN(web3.utils.toWei("2", "ether")), { from: account_investor2 }), "Transfer Invalid");
358359
});
359360

360361
it("Should be able to consolidate balances", async () => {
@@ -457,16 +458,17 @@ contract("CountTransferManager", async (accounts) => {
457458
I_GeneralTransferManager2 = await GeneralTransferManager.at(moduleData);
458459
});
459460

460-
it("Should successfully attach the CountTransferManager factory with the security token", async () => {
461+
it("Should fail to attach a CountTransferManager because of insufficient tokens", async () => {
461462
await I_PolyToken.getTokens(new BN(web3.utils.toWei("2000", "ether")), token_owner);
462463
await catchRevert(
463464
I_SecurityToken2.addModule(P_CountTransferManagerFactory.address, bytesSTO, new BN(web3.utils.toWei("2000", "ether")), new BN(0), false, {
464465
from: token_owner
465-
})
466+
}),
467+
"Insufficient tokens"
466468
);
467469
});
468470

469-
it("Should successfully attach the CountTransferManager with the security token and set max holder to 2", async () => {
471+
it("Token 2: Should successfully attach the CountTransferManager with the security token and set max holder to 2", async () => {
470472
const tx = await I_SecurityToken2.addModule(I_CountTransferManagerFactory.address, bytesSTO, new BN(0), new BN(0), false, { from: token_owner });
471473
assert.equal(tx.logs[2].args._types[0].toNumber(), transferManagerKey, "CountTransferManager doesn't get deployed");
472474
assert.equal(
@@ -479,7 +481,7 @@ contract("CountTransferManager", async (accounts) => {
479481
console.log("current max holder number is " + (await I_CountTransferManager2.maxHolderCount({ from: token_owner })));
480482
});
481483

482-
it("Should successfully attach the CountTransferManager with the third security token and set max holder to 2", async () => {
484+
it("Token 3: Should successfully attach the CountTransferManager with the third security token and set max holder to 2", async () => {
483485
const tx = await I_SecurityToken3.addModule(I_CountTransferManagerFactory.address, bytesSTO, new BN(0), new BN(0), false, { from: token_owner });
484486
assert.equal(tx.logs[2].args._types[0].toNumber(), transferManagerKey, "CountTransferManager doesn't get deployed");
485487
assert.equal(
@@ -497,24 +499,29 @@ contract("CountTransferManager", async (accounts) => {
497499
let bytesCM = encodeProxyCall(["uint256"], [11]);
498500
await catchRevert(
499501
// Fails as no upgrade available
500-
I_SecurityToken2.upgradeModule(I_CountTransferManager2.address, { from: token_owner })
502+
I_SecurityToken2.upgradeModule(I_CountTransferManager2.address, { from: token_owner }),
503+
"Incorrect version"
501504
);
502505
await catchRevert(
503506
// Fails due to the same version being used
504-
I_CountTransferManagerFactory.setLogicContract("3.0.0", I_MockCountTransferManagerLogic.address, bytesCM, { from: account_polymath })
507+
I_CountTransferManagerFactory.setLogicContract("3.0.0", I_MockCountTransferManagerLogic.address, bytesCM, { from: account_polymath }),
508+
"Same version"
505509
);
506510
await catchRevert(
507511
// Fails due to the wrong contract being used
508-
I_CountTransferManagerFactory.setLogicContract("4.0.0", "0x0000000000000000000000000000000000000000", bytesCM, { from: account_polymath })
512+
I_CountTransferManagerFactory.setLogicContract("4.0.0", "0x0000000000000000000000000000000000000000", bytesCM, { from: account_polymath }),
513+
"Invalid address"
509514
);
510515
await catchRevert(
511516
// Fails due to the wrong owner being used
512-
I_CountTransferManagerFactory.setLogicContract("4.0.0", "0x0000000000000000000000000000000000000000", bytesCM, { from: token_owner })
517+
I_CountTransferManagerFactory.setLogicContract("4.0.0", "0x0000000000000000000000000000000000000000", bytesCM, { from: token_owner }),
518+
"revert"
513519
);
514520
await I_CountTransferManagerFactory.setLogicContract("4.0.0", I_MockCountTransferManagerLogic.address, bytesCM, { from: account_polymath });
515521
await catchRevert(
516522
// Fails as upgraded module has been unverified
517-
I_SecurityToken2.upgradeModule(I_CountTransferManager2.address, { from: token_owner })
523+
I_SecurityToken2.upgradeModule(I_CountTransferManager2.address, { from: token_owner }),
524+
"ModuleFactory must be verified"
518525
);
519526
let tx = await I_MRProxied.verifyModule(I_CountTransferManagerFactory.address, { from: account_polymath });
520527
await I_SecurityToken2.upgradeModule(I_CountTransferManager2.address, { from: token_owner });
@@ -528,20 +535,24 @@ contract("CountTransferManager", async (accounts) => {
528535
let bytesCM = encodeProxyCall(["uint256"], [12]);
529536
await catchRevert(
530537
// Fails due to the same version being used
531-
I_CountTransferManagerFactory.updateLogicContract(1, "3.0.0", I_MockCountTransferManagerLogic.address, bytesCM, { from: account_polymath })
538+
I_CountTransferManagerFactory.updateLogicContract(1, "3.0.0", I_MockCountTransferManagerLogic.address, bytesCM, { from: account_polymath }),
539+
"Same version"
532540
);
533541
await catchRevert(
534542
// Fails due to the wrong contract being used
535-
I_CountTransferManagerFactory.updateLogicContract(1, "4.0.0", "0x0000000000000000000000000000000000000000", bytesCM, { from: account_polymath })
543+
I_CountTransferManagerFactory.updateLogicContract(1, "4.0.0", "0x0000000000000000000000000000000000000000", bytesCM, { from: account_polymath }),
544+
"Invalid address"
536545
);
537546
await catchRevert(
538547
// Fails due to the wrong owner being used
539-
I_CountTransferManagerFactory.updateLogicContract(1, "4.0.0", "0x0000000000000000000000000000000000000000", bytesCM, { from: token_owner })
548+
I_CountTransferManagerFactory.updateLogicContract(1, "4.0.0", "0x0000000000000000000000000000000000000000", bytesCM, { from: token_owner }),
549+
"revert"
540550
);
541551
await I_CountTransferManagerFactory.updateLogicContract(1, "4.0.0", I_MockCountTransferManagerLogic.address, bytesCM, { from: account_polymath });
542552
await catchRevert(
543553
// Fails as upgraded module has been unverified
544-
I_SecurityToken3.upgradeModule(I_CountTransferManager3.address, { from: token_owner })
554+
I_SecurityToken3.upgradeModule(I_CountTransferManager3.address, { from: token_owner }),
555+
"ModuleFactory must be verified"
545556
);
546557
let tx = await I_MRProxied.verifyModule(I_CountTransferManagerFactory.address, { from: account_polymath });
547558
await I_SecurityToken3.upgradeModule(I_CountTransferManager3.address, { from: token_owner });
@@ -557,16 +568,20 @@ contract("CountTransferManager", async (accounts) => {
557568
let bytesCM = encodeProxyCall(["uint256"], [11]);
558569
await catchRevert(
559570
// Fails as no upgrade available
560-
I_SecurityToken2.upgradeModule(I_CountTransferManager2.address, { from: token_owner })
571+
I_SecurityToken2.upgradeModule(I_CountTransferManager2.address, { from: token_owner }),
572+
"Incorrect version"
561573
);
562574
await catchRevert(
563575
// Fails due to the same version being used
564-
I_CountTransferManagerFactory.setLogicContract("4.0.0", I_MockCountTransferManagerLogic.address, bytesCM, { from: account_polymath })
576+
I_CountTransferManagerFactory.setLogicContract("4.0.0", I_MockCountTransferManagerLogic.address, bytesCM, { from: account_polymath }),
577+
"Same version"
565578
);
566579
await I_CountTransferManagerFactory.setLogicContract("5.0.0", I_MockCountTransferManagerLogic.address, bytesCM, { from: account_polymath });
580+
567581
await catchRevert(
568582
// Fails due to the same contract being used
569-
I_CountTransferManagerFactory.setLogicContract("6.0.0", I_MockCountTransferManagerLogic.address, bytesCM, { from: account_polymath })
583+
I_CountTransferManagerFactory.setLogicContract("6.0.0", I_MockCountTransferManagerLogic.address, bytesCM, { from: account_polymath }),
584+
"Same version"
570585
);
571586
I_MockCountTransferManagerLogic = await MockCountTransferManager.new("0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000", { from: account_polymath });
572587
await I_CountTransferManagerFactory.setLogicContract("6.0.0", I_MockCountTransferManagerLogic.address, bytesCM, { from: account_polymath });
@@ -611,7 +626,8 @@ contract("CountTransferManager", async (accounts) => {
611626
describe("Test cases for the ModuleFactory", async () => {
612627
it("Should successfully change the SetupCost -- fail beacuse of bad owner", async () => {
613628
await catchRevert(
614-
I_CountTransferManagerFactory.changeSetupCost(new BN(web3.utils.toWei("500")), { from: account_investor3 })
629+
I_CountTransferManagerFactory.changeSetupCost(new BN(web3.utils.toWei("500")), { from: account_investor3 }),
630+
"revert"
615631
);
616632
});
617633

@@ -622,7 +638,8 @@ contract("CountTransferManager", async (accounts) => {
622638

623639
it("Should successfully change the cost type -- fail beacuse of bad owner", async () => {
624640
await catchRevert(
625-
I_CountTransferManagerFactory.changeCostAndType(new BN(web3.utils.toWei("500")), true, { from: account_investor3 })
641+
I_CountTransferManagerFactory.changeCostAndType(new BN(web3.utils.toWei("500")), true, { from: account_investor3 }),
642+
"revert"
626643
);
627644
});
628645

@@ -640,17 +657,17 @@ contract("CountTransferManager", async (accounts) => {
640657

641658
describe("Test case for the changeSTVersionBounds", async () => {
642659
it("Should successfully change the version bounds -- failed because of the non permitted bound type", async () => {
643-
await catchRevert(I_CountTransferManagerFactory.changeSTVersionBounds("middleType", [1, 2, 3], { from: account_polymath }));
660+
await catchRevert(I_CountTransferManagerFactory.changeSTVersionBounds("middleType", [1, 2, 3], { from: account_polymath }), "Invalid bound type");
644661
});
645662

646663
it("Should successfully change the version bound --failed because the new version length < 3", async () => {
647-
await catchRevert(I_CountTransferManagerFactory.changeSTVersionBounds("lowerBound", [1, 2], { from: account_polymath }));
664+
await catchRevert(I_CountTransferManagerFactory.changeSTVersionBounds("lowerBound", [1, 2], { from: account_polymath }), "Invalid version");
648665
});
649666

650667
it("Should successfully change the version bound", async () => {
651668
await I_CountTransferManagerFactory.changeSTVersionBounds("lowerBound", [1, 2, 1], { from: account_polymath });
652669
await I_CountTransferManagerFactory.changeSTVersionBounds("lowerBound", [1, 0, 9], { from: account_polymath });
653-
await catchRevert(I_CountTransferManagerFactory.changeSTVersionBounds("lowerBound", [1, 1, 0], { from: account_polymath }));
670+
await catchRevert(I_CountTransferManagerFactory.changeSTVersionBounds("lowerBound", [1, 1, 0], { from: account_polymath }), "Invalid version");
654671
});
655672
});
656673
});

0 commit comments

Comments
 (0)