Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

Commit 5aad2dc

Browse files
committed
fix: 🐛 implement ErrorCode type for backlist transfer manager
1 parent e9b23ec commit 5aad2dc

File tree

2 files changed

+123
-34
lines changed

2 files changed

+123
-34
lines changed

src/contract_wrappers/modules/transfer_manager/blacklist_transfer_manager_wrapper.ts

Lines changed: 121 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
SubscribeAsyncParams,
2828
TransferResult,
2929
TxParams,
30+
ErrorCode,
3031
} from '../../../types';
3132
import {
3233
bigNumberToDate,
@@ -310,8 +311,12 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
310311
* unpause the module
311312
*/
312313
public unpause = async (params: TxParams) => {
313-
assert.assert(await this.paused(), 'Controller not currently paused');
314-
assert.assert(await this.isCallerTheSecurityTokenOwner(params.txData), 'Sender is not owner');
314+
assert.assert(await this.paused(), ErrorCode.PreconditionRequired, 'Controller not currently paused');
315+
assert.assert(
316+
await this.isCallerTheSecurityTokenOwner(params.txData),
317+
ErrorCode.Unauthorized,
318+
'Sender is not owner',
319+
);
315320
return (await this.contract).unpause.sendTransactionAsync(params.txData, params.safetyFactor);
316321
};
317322

@@ -326,16 +331,20 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
326331
* pause the module
327332
*/
328333
public pause = async (params: TxParams) => {
329-
assert.assert(!(await this.paused()), 'Controller currently paused');
330-
assert.assert(await this.isCallerTheSecurityTokenOwner(params.txData), 'Sender is not owner');
334+
assert.assert(!(await this.paused()), ErrorCode.ContractPaused, 'Controller currently paused');
335+
assert.assert(
336+
await this.isCallerTheSecurityTokenOwner(params.txData),
337+
ErrorCode.Unauthorized,
338+
'Sender is not owner',
339+
);
331340
return (await this.contract).pause.sendTransactionAsync(params.txData, params.safetyFactor);
332341
};
333342

334343
/**
335344
* Return the different blacklist details corresponding to a blacklists name
336345
*/
337346
public blacklists = async (params: BlacklistParams): Promise<BlacklistsDetails> => {
338-
assert.assert(params.blacklistName.length > 0, 'Blacklist name must not be an empty string');
347+
assert.assert(params.blacklistName.length > 0, ErrorCode.InvalidData, 'Blacklist name must not be an empty string');
339348
const result = await (await this.contract).blacklists.callAsync(stringToBytes32(params.blacklistName));
340349
return {
341350
startTime: bigNumberToDate(result[0]),
@@ -348,7 +357,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
348357
* Used to add the blacklist type
349358
*/
350359
public addBlacklistType = async (params: BlacklistTypeParams) => {
351-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
360+
assert.assert(
361+
await this.isCallerAllowed(params.txData, Perm.Admin),
362+
ErrorCode.Unauthorized,
363+
'Caller is not allowed',
364+
);
352365
await this.checkAddBlacklistType(params);
353366
return (await this.contract).addBlacklistType.sendTransactionAsync(
354367
dateToBigNumber(params.startTime),
@@ -368,8 +381,12 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
368381
[params.startTimes, params.endTimes, params.blacklistNames, params.repeatPeriodTimes],
369382
'Argument arrays length mismatch',
370383
);
371-
assert.assert(params.startTimes.length > 0, 'Empty blacklist information');
372-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
384+
assert.assert(params.startTimes.length > 0, ErrorCode.InvalidData, 'Empty blacklist information');
385+
assert.assert(
386+
await this.isCallerAllowed(params.txData, Perm.Admin),
387+
ErrorCode.Unauthorized,
388+
'Caller is not allowed',
389+
);
373390
const results = [];
374391
for (let i = 0; i < params.startTimes.length; i += 1) {
375392
results.push(
@@ -396,7 +413,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
396413
* Used to modify the details of a given blacklist type
397414
*/
398415
public modifyBlacklistType = async (params: BlacklistTypeParams) => {
399-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
416+
assert.assert(
417+
await this.isCallerAllowed(params.txData, Perm.Admin),
418+
ErrorCode.Unauthorized,
419+
'Caller is not allowed',
420+
);
400421
await this.checkModifyBlacklistType(params);
401422
return (await this.contract).modifyBlacklistType.sendTransactionAsync(
402423
dateToBigNumber(params.startTime),
@@ -416,8 +437,12 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
416437
[params.startTimes, params.endTimes, params.blacklistNames, params.repeatPeriodTimes],
417438
'Argument arrays length mismatch',
418439
);
419-
assert.assert(params.startTimes.length > 0, 'Empty blacklist information');
420-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
440+
assert.assert(params.startTimes.length > 0, ErrorCode.InvalidData, 'Empty blacklist information');
441+
assert.assert(
442+
await this.isCallerAllowed(params.txData, Perm.Admin),
443+
ErrorCode.Unauthorized,
444+
'Caller is not allowed',
445+
);
421446
const results = [];
422447
for (let i = 0; i < params.startTimes.length; i += 1) {
423448
results.push(
@@ -444,7 +469,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
444469
* Used to delete the blacklist type
445470
*/
446471
public deleteBlacklistType = async (params: DeleteBlacklistTypeParams) => {
447-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
472+
assert.assert(
473+
await this.isCallerAllowed(params.txData, Perm.Admin),
474+
ErrorCode.Unauthorized,
475+
'Caller is not allowed',
476+
);
448477
await this.checkDeleteBlacklistType(params.blacklistName);
449478
return (await this.contract).deleteBlacklistType.sendTransactionAsync(
450479
stringToBytes32(params.blacklistName),
@@ -457,8 +486,12 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
457486
* Used to delete the multiple blacklist types
458487
*/
459488
public deleteBlacklistTypeMulti = async (params: DeleteBlacklistTypeMultiParams) => {
460-
assert.assert(params.blacklistNames.length > 0, 'Empty blacklist information');
461-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
489+
assert.assert(params.blacklistNames.length > 0, ErrorCode.InvalidData, 'Empty blacklist information');
490+
assert.assert(
491+
await this.isCallerAllowed(params.txData, Perm.Admin),
492+
ErrorCode.Unauthorized,
493+
'Caller is not allowed',
494+
);
462495
const results = [];
463496
for (let i = 0; i < params.blacklistNames.length; i += 1) {
464497
results.push(this.checkDeleteBlacklistType(params.blacklistNames[i]));
@@ -475,7 +508,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
475508
* Used to assign the blacklist type to the investor
476509
*/
477510
public addInvestorToBlacklist = async (params: InvestorAndBlacklistParams) => {
478-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
511+
assert.assert(
512+
await this.isCallerAllowed(params.txData, Perm.Admin),
513+
ErrorCode.Unauthorized,
514+
'Caller is not allowed',
515+
);
479516
await this.checkAddInvestorToBlacklist(params);
480517
return (await this.contract).addInvestorToBlacklist.sendTransactionAsync(
481518
params.userAddress,
@@ -489,8 +526,12 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
489526
* Used to assign a single blacklist type to multiple investors
490527
*/
491528
public addInvestorToBlacklistMulti = async (params: InvestorMultiAndBlacklistParams) => {
492-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
493-
assert.assert(params.userAddresses.length > 0, 'Empty user address information');
529+
assert.assert(
530+
await this.isCallerAllowed(params.txData, Perm.Admin),
531+
ErrorCode.Unauthorized,
532+
'Caller is not allowed',
533+
);
534+
assert.assert(params.userAddresses.length > 0, ErrorCode.InvalidData, 'Empty user address information');
494535
const results = [];
495536
for (let i = 0; i < params.userAddresses.length; i += 1) {
496537
results.push(
@@ -513,9 +554,13 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
513554
* Used to assign multiple specific blacklist types to multiple investors
514555
*/
515556
public addMultiInvestorToBlacklistMulti = async (params: InvestorMultiAndBlacklistMultiParams) => {
516-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
557+
assert.assert(
558+
await this.isCallerAllowed(params.txData, Perm.Admin),
559+
ErrorCode.Unauthorized,
560+
'Caller is not allowed',
561+
);
517562
assert.areValidArrayLengths([params.userAddresses, params.blacklistNames], 'Argument arrays length mismatch');
518-
assert.assert(params.userAddresses.length > 0, 'Empty user address information');
563+
assert.assert(params.userAddresses.length > 0, ErrorCode.InvalidData, 'Empty user address information');
519564
const results = [];
520565
for (let i = 0; i < params.userAddresses.length; i += 1) {
521566
results.push(
@@ -538,7 +583,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
538583
* Used to create a new blacklist type and add it to the investor
539584
*/
540585
public addInvestorToNewBlacklist = async (params: AddNewInvestorToNewBlacklistParams) => {
541-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
586+
assert.assert(
587+
await this.isCallerAllowed(params.txData, Perm.Admin),
588+
ErrorCode.Unauthorized,
589+
'Caller is not allowed',
590+
);
542591
await this.checkAddBlacklistType(params);
543592
return (await this.contract).addInvestorToNewBlacklist.sendTransactionAsync(
544593
dateToBigNumber(params.startTime),
@@ -555,7 +604,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
555604
* Used to delete the investor from the blacklist
556605
*/
557606
public deleteInvestorFromBlacklist = async (params: InvestorAndBlacklistParams) => {
558-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
607+
assert.assert(
608+
await this.isCallerAllowed(params.txData, Perm.Admin),
609+
ErrorCode.Unauthorized,
610+
'Caller is not allowed',
611+
);
559612
await this.checkDeleteInvestorFromBlacklist(params);
560613
return (await this.contract).deleteInvestorFromBlacklist.sendTransactionAsync(
561614
params.userAddress,
@@ -569,9 +622,13 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
569622
* Used to delete the multiple investors from multiple specific blacklists
570623
*/
571624
public deleteMultiInvestorsFromBlacklistMulti = async (params: InvestorMultiAndBlacklistMultiParams) => {
572-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
625+
assert.assert(
626+
await this.isCallerAllowed(params.txData, Perm.Admin),
627+
ErrorCode.Unauthorized,
628+
'Caller is not allowed',
629+
);
573630
assert.areValidArrayLengths([params.userAddresses, params.blacklistNames], 'Argument arrays length mismatch');
574-
assert.assert(params.userAddresses.length > 0, 'Empty user address information');
631+
assert.assert(params.userAddresses.length > 0, ErrorCode.InvalidData, 'Empty user address information');
575632
const results = [];
576633
for (let i = 0; i < params.userAddresses.length; i += 1) {
577634
results.push(
@@ -594,7 +651,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
594651
* Used to delete the investor from all the associated blacklist types
595652
*/
596653
public deleteInvestorFromAllBlacklist = async (params: DeleteInvestorFromAllBlacklistParams) => {
597-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
654+
assert.assert(
655+
await this.isCallerAllowed(params.txData, Perm.Admin),
656+
ErrorCode.Unauthorized,
657+
'Caller is not allowed',
658+
);
598659
await this.checkDeleteInvestorFromAllBlacklist(params);
599660
return (await this.contract).deleteInvestorFromAllBlacklist.sendTransactionAsync(
600661
params.investor,
@@ -607,7 +668,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
607668
* Used to delete multiple investors from multiple associated blacklist types
608669
*/
609670
public deleteInvestorFromAllBlacklistMulti = async (params: DeleteInvestorFromAllBlacklistMultiParams) => {
610-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
671+
assert.assert(
672+
await this.isCallerAllowed(params.txData, Perm.Admin),
673+
ErrorCode.Unauthorized,
674+
'Caller is not allowed',
675+
);
611676
const results = [];
612677
for (let i = 0; i < params.investors.length; i += 1) {
613678
results.push(
@@ -629,7 +694,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
629694
* @return address List of investors associated with the blacklist
630695
*/
631696
public getListOfAddresses = async (params: BlacklistParams): Promise<string[]> => {
632-
assert.assert(params.blacklistName.length > 0, 'Blacklist details must not be an empty string');
697+
assert.assert(
698+
params.blacklistName.length > 0,
699+
ErrorCode.InvalidData,
700+
'Blacklist details must not be an empty string',
701+
);
633702
return (await this.contract).getListOfAddresses.callAsync(stringToBytes32(params.blacklistName));
634703
};
635704

@@ -749,7 +818,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
749818

750819
private checkAddBlacklistType = async (params: BlacklistTypeParams) => {
751820
const blacklistInfo = await this.blacklists({ blacklistName: params.blacklistName });
752-
assert.assert(dateToBigNumber(blacklistInfo.endTime).isZero(), 'Blacklist you are trying to add already exists');
821+
assert.assert(
822+
dateToBigNumber(blacklistInfo.endTime).isZero(),
823+
ErrorCode.BacklistAlreadyExist,
824+
'Blacklist you are trying to add already exists',
825+
);
753826
await this.checkBlacklistTypeDetails(params);
754827
};
755828

@@ -760,50 +833,64 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
760833
};
761834

762835
private checkBlacklistTypeDetails = async (params: BlacklistTypeParams) => {
763-
assert.assert(params.blacklistName.length > 0, 'Blacklist Name cannot be empty string');
836+
assert.assert(params.blacklistName.length > 0, ErrorCode.InvalidData, 'Blacklist Name cannot be empty string');
764837
assert.isFutureDate(params.startTime, 'Start time must be in the future');
765-
assert.assert(params.startTime < params.endTime, 'Start time must be before the end time');
838+
assert.assert(params.startTime < params.endTime, ErrorCode.TooLate, 'Start time must be before the end time');
766839
if (params.repeatPeriodTime !== 0) {
767840
const blacklistDays = (params.endTime.getTime() - params.startTime.getTime()) / (1000 * 60 * 60 * 24);
768841
assert.assert(
769842
blacklistDays <= params.repeatPeriodTime,
843+
ErrorCode.TooEarly,
770844
'The repeat period time in days must be greater than or equal to the difference between start and end time',
771845
);
772846
}
773847
};
774848

775849
private checkDeleteBlacklistType = async (blacklistName: string) => {
776-
assert.assert(blacklistName.length > 0, 'Blacklist Name cannot be empty string');
850+
assert.assert(blacklistName.length > 0, ErrorCode.InvalidData, 'Blacklist Name cannot be empty string');
777851
const blacklistsDetails = await this.blacklists({ blacklistName });
778852
assert.isNotDateZero(blacklistsDetails.endTime, 'Blacklist does not exist');
779853
const lookupListOfAddresses = await this.getListOfAddresses({ blacklistName });
780854
assert.assert(
781855
lookupListOfAddresses.length === 0,
856+
ErrorCode.PreconditionRequired,
782857
'There are users attached to the blacklist that must be removed before removing the blacklist type',
783858
);
784859
};
785860

786861
private checkBlacklistToModifyInvestors = async (params: InvestorAndBlacklistParams) => {
787-
assert.assert(params.blacklistName.length > 0, 'Blacklist name cannot be empty string');
862+
assert.assert(params.blacklistName.length > 0, ErrorCode.InvalidData, 'Blacklist name cannot be empty string');
788863
const blacklistsDetails = await this.blacklists({ blacklistName: params.blacklistName });
789864
assert.isNotDateZero(blacklistsDetails.endTime, 'Blacklist does not exist');
790865
};
791866

792867
private checkAddInvestorToBlacklist = async (params: InvestorAndBlacklistParams) => {
793868
await this.checkBlacklistToModifyInvestors(params);
794869
const currentBlacklistNames = await this.getBlacklistNamesToUser({ user: params.userAddress });
795-
assert.assert(!currentBlacklistNames.includes(params.blacklistName), 'User already added to this blacklist name');
870+
assert.assert(
871+
!currentBlacklistNames.includes(params.blacklistName),
872+
ErrorCode.AlreadyAdded,
873+
'User already added to this blacklist name',
874+
);
796875
};
797876

798877
private checkDeleteInvestorFromBlacklist = async (params: InvestorAndBlacklistParams) => {
799878
await this.checkBlacklistToModifyInvestors(params);
800879
const currentBlacklistNames = await this.getBlacklistNamesToUser({ user: params.userAddress });
801-
assert.assert(currentBlacklistNames.includes(params.blacklistName), 'User is not added to this blacklist name');
880+
assert.assert(
881+
currentBlacklistNames.includes(params.blacklistName),
882+
ErrorCode.PreconditionRequired,
883+
'User is not added to this blacklist name',
884+
);
802885
};
803886

804887
private checkDeleteInvestorFromAllBlacklist = async (params: DeleteInvestorFromAllBlacklistParams) => {
805888
assert.isNonZeroETHAddressHex('Investor Address', params.investor);
806889
const currentBlacklistNames = await this.getBlacklistNamesToUser({ user: params.investor });
807-
assert.assert(currentBlacklistNames.length > 0, 'Investor is not currently present on any blacklists');
890+
assert.assert(
891+
currentBlacklistNames.length > 0,
892+
ErrorCode.PreconditionRequired,
893+
'Investor is not currently present on any blacklists',
894+
);
808895
};
809896
}

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,6 @@ export enum ErrorCode {
364364
STOClosed = 'STOClosed',
365365
CoinNotAllowed = 'CoinNotAllowed',
366366
ErrorLimit = 'ErrorLimit',
367+
BacklistAlreadyExist = 'BacklistAlreadyExist',
368+
AlreadyAdded = 'AlreadyAdded',
367369
}

0 commit comments

Comments
 (0)