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

Commit 48727cd

Browse files
author
Victor Wiebe
committed
fix: 🐛 check factory owner from unarchive, refactor duplication
1 parent 91deb3e commit 48727cd

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/contract_wrappers/registries/__tests__/module_registry_wrapper.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,16 @@ describe('ModuleRegistryWrapper', () => {
322322
test('should successfully call to unverifyModule', async () => {
323323
// Owner Address expected
324324
const expectedOwnerResult = '0x0123456789012345678901234567890123456789';
325+
326+
// Setup mocked owner from module factory contract
327+
const moduleFactoryAddress = '0x2222222222222222222222222222222222222222';
328+
when(mockedContractFactory.getModuleFactoryContract(moduleFactoryAddress)).thenResolve(
329+
instance(mockedModuleFactoryContract),
330+
);
331+
const mockedModuleFactoryOwnerMethod = mock(MockedCallMethod);
332+
when(mockedModuleFactoryOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
333+
when(mockedModuleFactoryContract.owner).thenReturn(instance(mockedModuleFactoryOwnerMethod));
334+
325335
// Mocked method
326336
const mockedOwnerMethod = mock(MockedCallMethod);
327337
// Stub the method
@@ -390,6 +400,9 @@ describe('ModuleRegistryWrapper', () => {
390400
verify(mockedContract.owner).once();
391401
verify(mockedOwnerMethod.callAsync()).once();
392402
verify(mockedWrapper.getAvailableAddressesAsync()).once();
403+
verify(mockedContractFactory.getModuleFactoryContract(moduleFactoryAddress)).once();
404+
verify(mockedModuleFactoryOwnerMethod.callAsync()).once();
405+
verify(mockedModuleFactoryContract.owner).once();
393406
});
394407
});
395408

src/contract_wrappers/registries/module_registry_wrapper.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,7 @@ export default class ModuleRegistryWrapper extends ContractWrapper {
245245
assert.isETHAddressHex('moduleFactory', params.moduleFactory);
246246
await this.checkModuleNotPausedOrOwner();
247247
await this.checkModuleRegistered(params.moduleFactory);
248-
const callerAddress = await this.getCallerAddress(undefined);
249-
const owner = await this.owner();
250-
const factoryOwner = await (await this.moduleFactoryContract(params.moduleFactory)).owner.callAsync();
251-
assert.assert(
252-
functionsUtils.checksumAddressComparision(callerAddress, owner) ||
253-
functionsUtils.checksumAddressComparision(callerAddress, factoryOwner),
254-
'Calling address must be owner or factory owner ',
255-
);
248+
await this.checkIsOwnerOrModuleFactoryOwner(params.moduleFactory);
256249
return (await this.contract).removeModule.sendTransactionAsync(
257250
params.moduleFactory,
258251
params.txData,
@@ -273,7 +266,7 @@ export default class ModuleRegistryWrapper extends ContractWrapper {
273266

274267
public unverifyModule = async (params: ModuleFactoryParams) => {
275268
assert.isETHAddressHex('moduleFactory', params.moduleFactory);
276-
await this.checkMsgSenderIsOwner();
269+
await this.checkIsOwnerOrModuleFactoryOwner(params.moduleFactory);
277270
await this.checkModuleRegistered(params.moduleFactory);
278271
return (await this.contract).unverifyModule.sendTransactionAsync(
279272
params.moduleFactory,
@@ -470,7 +463,18 @@ export default class ModuleRegistryWrapper extends ContractWrapper {
470463
assert.assert(
471464
!(await this.isPaused()) ||
472465
functionsUtils.checksumAddressComparision(await this.owner(), await this.getCallerAddress(undefined)),
473-
'Contract should not be Paused',
466+
'Check contract is not be paused or method has not been called by owner',
474467
);
475468
};
469+
470+
private checkIsOwnerOrModuleFactoryOwner = async(moduleFactoryAddress: string) => {
471+
const callerAddress = await this.getCallerAddress(undefined);
472+
const owner = await this.owner();
473+
const factoryOwner = await (await this.moduleFactoryContract(moduleFactoryAddress)).owner.callAsync();
474+
assert.assert(
475+
functionsUtils.checksumAddressComparision(callerAddress, owner) ||
476+
functionsUtils.checksumAddressComparision(callerAddress, factoryOwner),
477+
'Calling address must be owner or factory owner ',
478+
);
479+
}
476480
}

0 commit comments

Comments
 (0)