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

Commit fe5056c

Browse files
committed
fix: 🐛 implement ErrorCode type for GPM
1 parent f4f5aa3 commit fe5056c

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

src/contract_wrappers/modules/permission_manager/general_permission_manager_wrapper.ts

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
GetLogs,
2121
Subscribe,
2222
Perm,
23+
ErrorCode,
2324
} from '../../../types';
2425
import {
2526
numberToBigNumber,
@@ -160,10 +161,18 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
160161
};
161162

162163
public addDelegate = async (params: AddDelegateParams) => {
163-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
164+
assert.assert(
165+
await this.isCallerAllowed(params.txData, Perm.Admin),
166+
ErrorCode.Unauthorized,
167+
'Caller is not allowed',
168+
);
164169
assert.isNonZeroETHAddressHex('delegate', params.delegate);
165-
assert.assert(params.details.length > 0, '0 value not allowed');
166-
assert.assert(!(await (await this.contract).checkDelegate.callAsync(params.delegate)), 'Delegate already present');
170+
assert.assert(params.details.length > 0, ErrorCode.InvalidData, '0 value not allowed');
171+
assert.assert(
172+
!(await (await this.contract).checkDelegate.callAsync(params.delegate)),
173+
ErrorCode.PreconditionRequired,
174+
'Delegate already present',
175+
);
167176
return (await this.contract).addDelegate.sendTransactionAsync(
168177
params.delegate,
169178
stringToBytes32(params.details),
@@ -173,9 +182,17 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
173182
};
174183

175184
public deleteDelegate = async (params: DelegateTxParams) => {
176-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
185+
assert.assert(
186+
await this.isCallerAllowed(params.txData, Perm.Admin),
187+
ErrorCode.Unauthorized,
188+
'Caller is not allowed',
189+
);
177190
assert.isNonZeroETHAddressHex('delegate', params.delegate);
178-
assert.assert(await (await this.contract).checkDelegate.callAsync(params.delegate), 'Delegate does not exist');
191+
assert.assert(
192+
await (await this.contract).checkDelegate.callAsync(params.delegate),
193+
ErrorCode.InvalidDelegate,
194+
'Delegate does not exist',
195+
);
179196
return (await this.contract).deleteDelegate.sendTransactionAsync(
180197
params.delegate,
181198
params.txData,
@@ -189,7 +206,11 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
189206
};
190207

191208
public changePermission = async (params: ChangePermissionParams) => {
192-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
209+
assert.assert(
210+
await this.isCallerAllowed(params.txData, Perm.Admin),
211+
ErrorCode.Unauthorized,
212+
'Caller is not allowed',
213+
);
193214
assert.isNonZeroETHAddressHex('delegate', params.delegate);
194215
assert.isETHAddressHex('module', params.module);
195216
return (await this.contract).changePermission.sendTransactionAsync(
@@ -203,12 +224,24 @@ export default class GeneralPermissionManagerWrapper extends ModuleWrapper {
203224
};
204225

205226
public changePermissionMulti = async (params: ChangePermissionMultiParams) => {
206-
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
227+
assert.assert(
228+
await this.isCallerAllowed(params.txData, Perm.Admin),
229+
ErrorCode.Unauthorized,
230+
'Caller is not allowed',
231+
);
207232
assert.isNonZeroETHAddressHex('delegate', params.delegate);
208233
params.modules.forEach(address => assert.isETHAddressHex('modules', address));
209-
assert.assert(params.modules.length > 0, '0 length is not allowed');
210-
assert.assert(params.modules.length === params.perms.length, 'Array length mismatch');
211-
assert.assert(params.valids.length === params.perms.length, 'Array length mismatch');
234+
assert.assert(params.modules.length > 0, ErrorCode.InvalidData, '0 length is not allowed');
235+
assert.assert(
236+
params.modules.length === params.perms.length,
237+
ErrorCode.MismatchedArrayLength,
238+
'Array length mismatch',
239+
);
240+
assert.assert(
241+
params.valids.length === params.perms.length,
242+
ErrorCode.MismatchedArrayLength,
243+
'Array length mismatch',
244+
);
212245
return (await this.contract).changePermissionMulti.sendTransactionAsync(
213246
params.delegate,
214247
params.modules,

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,5 @@ export enum ErrorCode {
356356
InvalidCheckpoint = 'InvalidCheckpoint',
357357
InvalidLenghtLimit = 'InvalidLenghtLimit',
358358
InvalidBound = 'InvalidBound',
359+
InvalidDelegate = 'InvalidDelegate',
359360
}

0 commit comments

Comments
 (0)