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

Commit d3239a9

Browse files
committed
fix: 🐛 implement ErrorCode class for feature, module and poly
1 parent a08335e commit d3239a9

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

src/contract_wrappers/registries/feature_registry_wrapper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
Feature,
1919
Subscribe,
2020
GetLogs,
21+
ErrorCode,
2122
} from '../../types';
2223
import functionsUtils from '../../utils/functions_utils';
2324

@@ -103,10 +104,11 @@ export default class FeatureRegistryWrapper extends ContractWrapper {
103104
public setFeatureStatus = async (params: SetFeatureStatusParams) => {
104105
assert.assert(
105106
functionsUtils.checksumAddressComparision(await this.owner(), await this.getCallerAddress(params.txData)),
107+
ErrorCode.Unauthorized,
106108
'From sender must be owner',
107109
);
108110
const currentStatus = await this.getFeatureStatus({ nameKey: params.nameKey });
109-
assert.assert(currentStatus !== params.newStatus, 'FeatureStatus must change');
111+
assert.assert(currentStatus !== params.newStatus, ErrorCode.PreconditionRequired, 'FeatureStatus must change');
110112
return (await this.contract).setFeatureStatus.sendTransactionAsync(
111113
params.nameKey,
112114
params.newStatus,

src/contract_wrappers/registries/module_registry_wrapper.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
Subscribe,
3131
SubscribeAsyncParams,
3232
TxParams,
33+
ErrorCode,
3334
} from '../../types';
3435
import { bytes32ArrayToStringArray } from '../../utils/convert';
3536
import functionsUtils from '../../utils/functions_utils';
@@ -228,20 +229,26 @@ export default class ModuleRegistryWrapper extends ContractWrapper {
228229
assert.assert(
229230
functionsUtils.checksumAddressComparision(callerAddress, owner) ||
230231
functionsUtils.checksumAddressComparision(callerAddress, factoryOwner),
232+
ErrorCode.Unauthorized,
231233
'Calling address must be owner or factory owner with custom modules allowed feature status',
232234
);
233235
} else {
234236
assert.assert(
235237
functionsUtils.checksumAddressComparision(callerAddress, owner),
238+
ErrorCode.Unauthorized,
236239
'Calling address must be owner without custom modules allowed feature status',
237240
);
238241
}
239242
const getTypesResult = await (await this.moduleFactoryContract(params.moduleFactory)).getTypes.callAsync();
240243
// Check for duplicates
241244
if (getTypesResult.length > 1) {
242-
assert.assert(getTypesResult.length === new Set(getTypesResult).size, 'Type mismatch');
245+
assert.assert(
246+
getTypesResult.length === new Set(getTypesResult).size,
247+
ErrorCode.MismatchedLength,
248+
'Type mismatch',
249+
);
243250
}
244-
assert.assert(getTypesResult.length > 0, 'Factory must have type');
251+
assert.assert(getTypesResult.length > 0, ErrorCode.InvalidData, 'Factory must have type');
245252
return (await this.contract).registerModule.sendTransactionAsync(
246253
params.moduleFactory,
247254
params.txData,
@@ -364,13 +371,13 @@ export default class ModuleRegistryWrapper extends ContractWrapper {
364371

365372
public pause = async (params: TxParams) => {
366373
await this.checkMsgSenderIsOwner();
367-
assert.assert(!(await this.isPaused()), 'Contract is paused');
374+
assert.assert(!(await this.isPaused()), ErrorCode.ContractPaused, 'Contract is paused');
368375
return (await this.contract).pause.sendTransactionAsync(params.txData, params.safetyFactor);
369376
};
370377

371378
public unpause = async (params: TxParams) => {
372379
await this.checkMsgSenderIsOwner();
373-
assert.assert(await this.isPaused(), 'Contract is already not paused');
380+
assert.assert(await this.isPaused(), ErrorCode.PreconditionRequired, 'Contract is already not paused');
374381
return (await this.contract).unpause.sendTransactionAsync(params.txData, params.safetyFactor);
375382
};
376383

@@ -462,28 +469,38 @@ export default class ModuleRegistryWrapper extends ContractWrapper {
462469
await this.owner(),
463470
(await this.web3Wrapper.getAvailableAddressesAsync())[0],
464471
),
472+
ErrorCode.Unauthorized,
465473
'Msg sender must be owner',
466474
);
467475
};
468476

469477
private checkModuleRegistered = async (moduleFactory: string) => {
470-
assert.assert(await this.checkForRegisteredModule(moduleFactory), 'Module is not registered');
478+
assert.assert(
479+
await this.checkForRegisteredModule(moduleFactory),
480+
ErrorCode.PreconditionRequired,
481+
'Module is not registered',
482+
);
471483
};
472484

473485
private checkModuleNotRegistered = async (moduleFactory: string) => {
474-
assert.assert(!(await this.checkForRegisteredModule(moduleFactory)), 'Module is already registered');
486+
assert.assert(
487+
!(await this.checkForRegisteredModule(moduleFactory)),
488+
ErrorCode.AlreadyExists,
489+
'Module is already registered',
490+
);
475491
};
476492

477493
private checkModuleNotPausedOrOwner = async () => {
478494
assert.assert(
479495
!(await this.isPaused()) ||
480496
functionsUtils.checksumAddressComparision(await this.owner(), await this.getCallerAddress(undefined)),
497+
ErrorCode.Unauthorized,
481498
'Contract is either paused or the calling address is not the owner',
482499
);
483500
};
484501

485502
private checkModuleNotPaused = async () => {
486-
assert.assert(!(await this.isPaused()), 'Contract is currently paused');
503+
assert.assert(!(await this.isPaused()), ErrorCode.ContractPaused, 'Contract is currently paused');
487504
};
488505

489506
private checkIsOwnerOrModuleFactoryOwner = async (moduleFactoryAddress: string) => {
@@ -493,6 +510,7 @@ export default class ModuleRegistryWrapper extends ContractWrapper {
493510
assert.assert(
494511
functionsUtils.checksumAddressComparision(callerAddress, owner) ||
495512
functionsUtils.checksumAddressComparision(callerAddress, factoryOwner),
513+
ErrorCode.Unauthorized,
496514
'Calling address must be owner or factory owner ',
497515
);
498516
};

src/contract_wrappers/registries/polymath_registry_wrapper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
PolymathContract,
1919
GetLogs,
2020
Subscribe,
21+
ErrorCode,
2122
} from '../../types';
2223
import functionsUtils from '../../utils/functions_utils';
2324

@@ -149,6 +150,7 @@ export default class PolymathRegistryWrapper extends ContractWrapper {
149150
public changeAddress = async (params: ChangeAddressParams) => {
150151
assert.assert(
151152
functionsUtils.checksumAddressComparision(await this.owner(), await this.getCallerAddress(params.txData)),
153+
ErrorCode.Unauthorized,
152154
'Form sender must be owner',
153155
);
154156
assert.isETHAddressHex('newAddress', params.newAddress);

0 commit comments

Comments
 (0)