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

Commit 06a3b43

Browse files
committed
fix: 🐛 implement ErrorCode type for module factory module
1 parent cec6223 commit 06a3b43

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/contract_wrappers/modules/module_factory_wrapper.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
Subscribe,
2525
SubscribeAsyncParams,
2626
TxParams,
27+
ErrorCode,
2728
} from '../../types';
2829
import {
2930
bytes32ArrayToStringArray,
@@ -211,7 +212,7 @@ export default class ModuleFactoryWrapper extends ContractWrapper {
211212
*/
212213
public changeTitle = async (params: ChangeTitleParams) => {
213214
await this.checkOnlyOwner(params.txData);
214-
assert.assert(params.title.length > 0, 'Invalid title');
215+
assert.assert(params.title.length > 0, ErrorCode.InvalidData, 'Invalid title');
215216
return (await this.contract).changeTitle.sendTransactionAsync(params.title, params.txData, params.safetyFactor);
216217
};
217218

@@ -220,7 +221,7 @@ export default class ModuleFactoryWrapper extends ContractWrapper {
220221
*/
221222
public changeDescription = async (params: ChangeDescriptionParams) => {
222223
await this.checkOnlyOwner(params.txData);
223-
assert.assert(params.description.length > 0, 'Invalid description');
224+
assert.assert(params.description.length > 0, ErrorCode.InvalidData, 'Invalid description');
224225
return (await this.contract).changeDescription.sendTransactionAsync(
225226
params.description,
226227
params.txData,
@@ -233,7 +234,7 @@ export default class ModuleFactoryWrapper extends ContractWrapper {
233234
*/
234235
public changeName = async (params: ChangeNameParams) => {
235236
await this.checkOnlyOwner(params.txData);
236-
assert.assert(params.name.length > 0, 'Invalid name');
237+
assert.assert(params.name.length > 0, ErrorCode.InvalidData, 'Invalid name');
237238
return (await this.contract).changeName.sendTransactionAsync(
238239
stringToBytes32(params.name),
239240
params.txData,
@@ -246,7 +247,7 @@ export default class ModuleFactoryWrapper extends ContractWrapper {
246247
*/
247248
public changeTags = async (params: ChangeTagsParams) => {
248249
await this.checkOnlyOwner(params.txData);
249-
assert.assert(params.tags.length > 0, 'Invalid, must provide one or more tags');
250+
assert.assert(params.tags.length > 0, ErrorCode.InvalidData, 'Invalid, must provide one or more tags');
250251
return (await this.contract).changeTags.sendTransactionAsync(
251252
stringArrayToBytes32Array(params.tags),
252253
params.txData,
@@ -261,9 +262,14 @@ export default class ModuleFactoryWrapper extends ContractWrapper {
261262
await this.checkOnlyOwner(params.txData);
262263
assert.assert(
263264
params.boundType === BoundType.LowerBound || params.boundType === BoundType.UpperBound,
265+
ErrorCode.InvalidBound,
264266
'Invalid bound type',
265267
);
266-
assert.assert(params.newVersion.length === 3, 'Invalid version, number array must have 3 elements');
268+
assert.assert(
269+
params.newVersion.length === 3,
270+
ErrorCode.InvalidVersion,
271+
'Invalid version, number array must have 3 elements',
272+
);
267273
const currentBound =
268274
BoundType.LowerBound === params.boundType
269275
? await this.getLowerSTVersionBounds()
@@ -273,11 +279,13 @@ export default class ModuleFactoryWrapper extends ContractWrapper {
273279
if (params.boundType === BoundType.LowerBound) {
274280
assert.assert(
275281
semver.lte(newBoundVer, currentBoundVer),
282+
ErrorCode.InvalidBound,
276283
'New Lower ST Bounds must be less than or equal to current',
277284
);
278285
} else {
279286
assert.assert(
280287
semver.gte(newBoundVer, currentBoundVer),
288+
ErrorCode.InvalidBound,
281289
'New Upper ST Bounds must be greater than or equal to current',
282290
);
283291
}
@@ -361,6 +369,7 @@ export default class ModuleFactoryWrapper extends ContractWrapper {
361369
private checkOnlyOwner = async (txData: Partial<TxData> | undefined) => {
362370
assert.assert(
363371
functionsUtils.checksumAddressComparision(await this.owner(), await this.getCallerAddress(txData)),
372+
ErrorCode.Unauthorized,
364373
'Msg sender must be owner',
365374
);
366375
};

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,5 @@ export enum ErrorCode {
355355
InvalidDividend = 'InvalidDividend',
356356
InvalidCheckpoint = 'InvalidCheckpoint',
357357
InvalidLenghtLimit = 'InvalidLenghtLimit',
358+
InvalidBound = 'InvalidBound',
358359
}

0 commit comments

Comments
 (0)