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

Commit 56d76fd

Browse files
author
Victor Wiebe
committed
fix: refactor perms across project
* only operator and admin perms * add missing perms and test verifications
1 parent 263bbdc commit 56d76fd

9 files changed

+72
-40
lines changed

src/contract_wrappers/modules/checkpoint/__tests__/dividend_checkpoint_wrapper.test.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,14 +1129,23 @@ describe('DividendCheckpointWrapper', () => {
11291129

11301130
describe('Reclaim Dividend', () => {
11311131
test('should reclaimDividend', async () => {
1132-
// Get Decimals
1132+
// Owner Address expected
1133+
const expectedOwnerResult = '0x5555555555555555555555555555555555555555';
1134+
1135+
// Security Token Address expected
11331136
const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333';
1137+
// Setup get Security Token Address
11341138
const mockedGetSecurityTokenAddressMethod = mock(MockedCallMethod);
11351139
when(mockedContract.securityToken).thenReturn(instance(mockedGetSecurityTokenAddressMethod));
11361140
when(mockedGetSecurityTokenAddressMethod.callAsync()).thenResolve(expectedSecurityTokenAddress);
11371141
when(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).thenResolve(
11381142
instance(mockedSecurityTokenContract),
11391143
);
1144+
const mockedSecurityTokenOwnerMethod = mock(MockedCallMethod);
1145+
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
1146+
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));
1147+
1148+
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);
11401149

11411150
// getDividendsData mock
11421151
const pastDate = new Date(2010, 1);
@@ -1217,6 +1226,12 @@ describe('DividendCheckpointWrapper', () => {
12171226
verify(mockedDividendsMethod.callAsync(objectContaining(new BigNumber(dividendIndex)))).once();
12181227
verify(mockedContract.getDividendsData).once();
12191228
verify(mockedGetDividendsMethod.callAsync()).once();
1229+
verify(mockedContract.securityToken).once();
1230+
verify(mockedGetSecurityTokenAddressMethod.callAsync()).once();
1231+
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).once();
1232+
verify(mockedSecurityTokenOwnerMethod.callAsync()).once();
1233+
verify(mockedSecurityTokenContract.owner).once();
1234+
verify(mockedWrapper.getAvailableAddressesAsync()).once();
12201235
});
12211236
});
12221237

@@ -1328,6 +1343,23 @@ describe('DividendCheckpointWrapper', () => {
13281343

13291344
const dividendIndex = 2;
13301345

1346+
// Owner Address expected
1347+
const expectedOwnerResult = '0x5555555555555555555555555555555555555555';
1348+
1349+
// Security Token Address expected
1350+
const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333';
1351+
// Setup get Security Token Address
1352+
const mockedGetSecurityTokenAddressMethod = mock(MockedCallMethod);
1353+
when(mockedContract.securityToken).thenReturn(instance(mockedGetSecurityTokenAddressMethod));
1354+
when(mockedGetSecurityTokenAddressMethod.callAsync()).thenResolve(expectedSecurityTokenAddress);
1355+
when(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).thenResolve(
1356+
instance(mockedSecurityTokenContract),
1357+
);
1358+
const mockedSecurityTokenOwnerMethod = mock(MockedCallMethod);
1359+
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
1360+
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));
1361+
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);
1362+
13311363
const mockedParams = {
13321364
dividendIndex,
13331365
txData: {},
@@ -1363,6 +1395,12 @@ describe('DividendCheckpointWrapper', () => {
13631395
).once();
13641396
verify(mockedContract.getDividendsData).once();
13651397
verify(mockedGetDividendsMethod.callAsync()).once();
1398+
verify(mockedWrapper.getAvailableAddressesAsync()).once();
1399+
verify(mockedContract.securityToken).once();
1400+
verify(mockedGetSecurityTokenAddressMethod.callAsync()).once();
1401+
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).once();
1402+
verify(mockedSecurityTokenOwnerMethod.callAsync()).once();
1403+
verify(mockedSecurityTokenContract.owner).once();
13661404
});
13671405
});
13681406

src/contract_wrappers/modules/checkpoint/dividend_checkpoint_wrapper.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ export default abstract class DividendCheckpointWrapper extends ModuleWrapper {
241241
};
242242

243243
public createCheckpoint = async (params: TxParams) => {
244-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Checkpoint), 'Caller is not allowed');
244+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Operator), 'Caller is not allowed');
245245
return (await this.contract).createCheckpoint.sendTransactionAsync(params.txData, params.safetyFactor);
246246
};
247247

248248
public setDefaultExcluded = async (params: SetDefaultExcludedParams) => {
249-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Manage), 'Caller is not allowed');
249+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
250250
assert.assert(params.excluded.length <= EXCLUDED_ADDRESS_LIMIT, 'Too many excluded addresses');
251251
params.excluded.forEach(address => assert.isNonZeroETHAddressHex('excluded', address));
252252
assert.areThereDuplicatedStrings('excluded', params.excluded);
@@ -258,7 +258,7 @@ export default abstract class DividendCheckpointWrapper extends ModuleWrapper {
258258
};
259259

260260
public setWithholding = async (params: SetWithholdingParams) => {
261-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Manage), 'Caller is not allowed');
261+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
262262
assert.assert(params.investors.length === params.withholding.length, 'Mismatched input lengths');
263263
params.withholding.forEach(withholding => assert.isPercentage('withholding tax', withholding));
264264
return (await this.contract).setWithholding.sendTransactionAsync(
@@ -270,7 +270,7 @@ export default abstract class DividendCheckpointWrapper extends ModuleWrapper {
270270
};
271271

272272
public setWithholdingFixed = async (params: SetWithholdingFixedParams) => {
273-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Manage), 'Caller is not allowed');
273+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
274274
assert.isPercentage('withholding tax', params.withholding);
275275
return (await this.contract).setWithholdingFixed.sendTransactionAsync(
276276
params.investors,
@@ -281,7 +281,7 @@ export default abstract class DividendCheckpointWrapper extends ModuleWrapper {
281281
};
282282

283283
public pushDividendPaymentToAddresses = async (params: PushDividendPaymentToAddressesParams) => {
284-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Distribute), 'Caller is not allowed');
284+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Operator), 'Caller is not allowed');
285285
params.payees.forEach(address => assert.isNonZeroETHAddressHex('payees', address));
286286
await this.checkValidDividend(params.dividendIndex);
287287
return (await this.contract).pushDividendPaymentToAddresses.sendTransactionAsync(
@@ -293,7 +293,7 @@ export default abstract class DividendCheckpointWrapper extends ModuleWrapper {
293293
};
294294

295295
public pushDividendPayment = async (params: PushDividendPaymentParams) => {
296-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Distribute), 'Caller is not allowed');
296+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Operator), 'Caller is not allowed');
297297
await this.checkValidDividend(params.dividendIndex);
298298
return (await this.contract).pushDividendPayment.sendTransactionAsync(
299299
numberToBigNumber(params.dividendIndex),
@@ -326,6 +326,7 @@ export default abstract class DividendCheckpointWrapper extends ModuleWrapper {
326326
};
327327

328328
public reclaimDividend = async (params: DividendIndexTxParams) => {
329+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Operator), 'Caller is not allowed');
329330
assert.assert(await this.isValidDividendIndex(params.dividendIndex), 'Invalid dividend index');
330331
const dividend = await this.dividends(params);
331332
assert.isPastDate(dividend.expiry, 'Dividend expiry is in the future');
@@ -356,6 +357,7 @@ export default abstract class DividendCheckpointWrapper extends ModuleWrapper {
356357
};
357358

358359
public withdrawWithholding = async (params: DividendIndexTxParams) => {
360+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Operator), 'Caller is not allowed');
359361
assert.assert(await this.isValidDividendIndex(params.dividendIndex), 'Invalid dividend index');
360362
return (await this.contract).withdrawWithholding.sendTransactionAsync(
361363
numberToBigNumber(params.dividendIndex),

src/contract_wrappers/modules/checkpoint/erc20_dividend_checkpoint_wrapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export default class ERC20DividendCheckpointWrapper extends DividendCheckpointWr
194194
};
195195

196196
public createDividend = async (params: CreateDividendParams) => {
197-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Manage), 'Caller is not allowed');
197+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
198198
await this.checkIfDividendIsValid(
199199
params.expiry,
200200
params.maturity,
@@ -216,7 +216,7 @@ export default class ERC20DividendCheckpointWrapper extends DividendCheckpointWr
216216
};
217217

218218
public createDividendWithCheckpoint = async (params: CreateDividendWithCheckpointParams) => {
219-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Manage), 'Caller is not allowed');
219+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
220220
await this.checkIfDividendIsValid(
221221
params.expiry,
222222
params.maturity,
@@ -240,7 +240,7 @@ export default class ERC20DividendCheckpointWrapper extends DividendCheckpointWr
240240
};
241241

242242
public createDividendWithExclusions = async (params: CreateDividendWithExclusionsParams) => {
243-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Manage), 'Caller is not allowed');
243+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
244244
await this.checkIfDividendIsValid(
245245
params.expiry,
246246
params.maturity,
@@ -267,7 +267,7 @@ export default class ERC20DividendCheckpointWrapper extends DividendCheckpointWr
267267
public createDividendWithCheckpointAndExclusions = async (
268268
params: CreateDividendWithCheckpointAndExclusionsParams,
269269
) => {
270-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Manage), 'Caller is not allowed');
270+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
271271
await this.checkIfDividendIsValid(
272272
params.expiry,
273273
params.maturity,

src/contract_wrappers/modules/checkpoint/ether_dividend_checkpoint_wrapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export default class EtherDividendCheckpointWrapper extends DividendCheckpointWr
251251
}
252252

253253
public createDividend = async (params: CreateDividendParams) => {
254-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Manage), 'Caller is not allowed');
254+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
255255
const txPayableData = {
256256
...params.txData,
257257
value: valueToWei(params.value, await this.getDecimals()),
@@ -267,7 +267,7 @@ export default class EtherDividendCheckpointWrapper extends DividendCheckpointWr
267267
};
268268

269269
public createDividendWithCheckpoint = async (params: CreateDividendWithCheckpointParams) => {
270-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Manage), 'Caller is not allowed');
270+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
271271
const txPayableData = {
272272
...params.txData,
273273
value: valueToWei(params.value, await this.getDecimals()),
@@ -284,7 +284,7 @@ export default class EtherDividendCheckpointWrapper extends DividendCheckpointWr
284284
};
285285

286286
public createDividendWithExclusions = async (params: CreateDividendWithExclusionsParams) => {
287-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Manage), 'Caller is not allowed');
287+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
288288
const txPayableData = {
289289
...params.txData,
290290
value: valueToWei(params.value, await this.getDecimals()),
@@ -310,7 +310,7 @@ export default class EtherDividendCheckpointWrapper extends DividendCheckpointWr
310310
public createDividendWithCheckpointAndExclusions = async (
311311
params: CreateDividendWithCheckpointAndExclusionsParams,
312312
) => {
313-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Manage), 'Caller is not allowed');
313+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
314314
const txPayableData = {
315315
...params.txData,
316316
value: valueToWei(params.value, await this.getDecimals()),

src/contract_wrappers/modules/permission_manager/general_permission_manager_wrapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
158158
};
159159

160160
public addDelegate = async (params: AddDelegateParams) => {
161-
assert.assert(await this.isCallerAllowed(params.txData, Perm.ChangePermission), 'Caller is not allowed');
161+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
162162
assert.isNonZeroETHAddressHex('delegate', params.delegate);
163163
assert.assert(params.details.length > 0, '0 value not allowed');
164164
assert.assert(!await (await this.contract).checkDelegate.callAsync(params.delegate), 'Already present');
@@ -171,7 +171,7 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
171171
};
172172

173173
public deleteDelegate = async (params: DelegateTxParams) => {
174-
assert.assert(await this.isCallerAllowed(params.txData, Perm.ChangePermission), 'Caller is not allowed');
174+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
175175
assert.isNonZeroETHAddressHex('delegate', params.delegate);
176176
assert.assert(await (await this.contract).checkDelegate.callAsync(params.delegate), 'Delegate does not exist');
177177
return (await this.contract).deleteDelegate.sendTransactionAsync(
@@ -187,7 +187,7 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
187187
};
188188

189189
public changePermission = async (params: ChangePermissionParams) => {
190-
assert.assert(await this.isCallerAllowed(params.txData, Perm.ChangePermission), 'Caller is not allowed');
190+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
191191
assert.isNonZeroETHAddressHex('delegate', params.delegate);
192192
assert.isETHAddressHex('module', params.module);
193193
return (await this.contract).changePermission.sendTransactionAsync(
@@ -201,7 +201,7 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
201201
};
202202

203203
public changePermissionMulti = async (params: ChangePermissionMultiParams) => {
204-
assert.assert(await this.isCallerAllowed(params.txData, Perm.ChangePermission), 'Caller is not allowed');
204+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
205205
assert.isNonZeroETHAddressHex('delegate', params.delegate);
206206
params.modules.forEach(address => assert.isETHAddressHex('modules', address));
207207
assert.assert(params.modules.length > 0, '0 length is not allowed');

src/contract_wrappers/modules/transfer_manager/general_transfer_manager_wrapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
285285
};
286286

287287
public changeDefaults = async (params: ChangeDefaultsParams) => {
288-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Flags), 'Caller is not allowed');
288+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
289289
return (await this.contract).changeDefaults.sendTransactionAsync(
290290
dateToBigNumber(params.defaultFromTime),
291291
dateToBigNumber(params.defaultToTime),
@@ -296,7 +296,7 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
296296

297297
public changeIssuanceAddress = async (params: ChangeIssuanceAddressParams) => {
298298
assert.isETHAddressHex('issuanceAddress', params.issuanceAddress);
299-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Flags), 'Caller is not allowed');
299+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
300300
return (await this.contract).changeIssuanceAddress.sendTransactionAsync(
301301
params.issuanceAddress,
302302
params.txData,
@@ -306,7 +306,7 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
306306

307307
public modifyKYCData = async (params: ModifyKYCDataParams) => {
308308
assert.isNonZeroETHAddressHex('investor', params.investor);
309-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Whitelist), 'Caller is not allowed');
309+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
310310
assert.isLessThanMax64BytesDate('canSendAfter', params.canSendAfter);
311311
assert.isLessThanMax64BytesDate('canReceiveAfter', params.canReceiveAfter);
312312
assert.isLessThanMax64BytesDate('expiryTime', params.expiryTime);
@@ -433,7 +433,7 @@ export default class GeneralTransferManagerWrapper extends ModuleWrapper {
433433

434434
public modifyKYCDataSigned = async (params: ModifyKYCDataSignedParams) => {
435435
assert.isNonZeroETHAddressHex('investor', params.investor);
436-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Whitelist), 'Caller is not allowed');
436+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
437437
assert.isLessThanMax64BytesDate('canSendAfter', params.canSendAfter);
438438
assert.isLessThanMax64BytesDate('canReceiveAfter', params.canReceiveAfter);
439439
assert.isLessThanMax64BytesDate('expiryTime', params.expiryTime);

0 commit comments

Comments
 (0)