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

Commit 653f2c5

Browse files
author
Victor Wiebe
committed
feat: add getFactoryDetails with associated test and prettier formatting
1 parent 50b326f commit 653f2c5

File tree

2 files changed

+58
-29
lines changed

2 files changed

+58
-29
lines changed

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

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ describe('ModuleRegistryWrapper', () => {
7777
});
7878
});
7979

80-
8180
describe('RegisterModule', () => {
8281
test.todo('should fail as moduleFactory is not an Eth address');
8382

@@ -307,11 +306,7 @@ describe('ModuleRegistryWrapper', () => {
307306
when(mockedContract.verifyModule).thenReturn(instance(mockedMethod));
308307
// Stub the request
309308
when(
310-
mockedMethod.sendTransactionAsync(
311-
mockedParams.moduleFactory,
312-
mockedParams.txData,
313-
mockedParams.safetyFactor,
314-
),
309+
mockedMethod.sendTransactionAsync(mockedParams.moduleFactory, mockedParams.txData, mockedParams.safetyFactor),
315310
).thenResolve(expectedResult);
316311

317312
// Real call
@@ -322,11 +317,7 @@ describe('ModuleRegistryWrapper', () => {
322317
// Verifications
323318
verify(mockedContract.verifyModule).once();
324319
verify(
325-
mockedMethod.sendTransactionAsync(
326-
mockedParams.moduleFactory,
327-
mockedParams.txData,
328-
mockedParams.safetyFactor,
329-
),
320+
mockedMethod.sendTransactionAsync(mockedParams.moduleFactory, mockedParams.txData, mockedParams.safetyFactor),
330321
).once();
331322
verify(mockedContract.getModulesByType).times(5);
332323

@@ -384,11 +375,7 @@ describe('ModuleRegistryWrapper', () => {
384375
when(mockedContract.unverifyModule).thenReturn(instance(mockedMethod));
385376
// Stub the request
386377
when(
387-
mockedMethod.sendTransactionAsync(
388-
mockedParams.moduleFactory,
389-
mockedParams.txData,
390-
mockedParams.safetyFactor,
391-
),
378+
mockedMethod.sendTransactionAsync(mockedParams.moduleFactory, mockedParams.txData, mockedParams.safetyFactor),
392379
).thenResolve(expectedResult);
393380

394381
// Real call
@@ -399,11 +386,7 @@ describe('ModuleRegistryWrapper', () => {
399386
// Verifications
400387
verify(mockedContract.unverifyModule).once();
401388
verify(
402-
mockedMethod.sendTransactionAsync(
403-
mockedParams.moduleFactory,
404-
mockedParams.txData,
405-
mockedParams.safetyFactor,
406-
),
389+
mockedMethod.sendTransactionAsync(mockedParams.moduleFactory, mockedParams.txData, mockedParams.safetyFactor),
407390
).once();
408391
verify(mockedContract.getModulesByType).times(5);
409392

@@ -675,6 +658,37 @@ describe('ModuleRegistryWrapper', () => {
675658
});
676659
});
677660

661+
describe('GetFactoryDetails', () => {
662+
test('should call to getFactoryDetails', async () => {
663+
// Address expected
664+
const factoryIsVerified = true;
665+
const factoryOwnerAddress = '0x1111111111111111111111111111111111111111';
666+
const listSecurityTokens = [
667+
'0x4444444444444444444444444444444444444444',
668+
'0x2222222222222222222222222222222222222222',
669+
];
670+
const expectedResult = [factoryIsVerified, factoryOwnerAddress, listSecurityTokens];
671+
const params = {
672+
factoryAddress: '0x5555555555555555555555555555555555555555',
673+
};
674+
// Mocked method
675+
const mockedMethod = mock(MockedCallMethod);
676+
// Stub the method
677+
when(mockedContract.getFactoryDetails).thenReturn(instance(mockedMethod));
678+
// Stub the request
679+
when(mockedMethod.callAsync(params.factoryAddress)).thenResolve(expectedResult);
680+
// Real call
681+
const result = await target.getFactoryDetails(params);
682+
// Result expectation
683+
expect(result.factoryIsVerified).toBe(factoryIsVerified);
684+
expect(result.factoryOwnerAddress).toBe(factoryOwnerAddress);
685+
expect(result.listSecurityTokens).toBe(listSecurityTokens);
686+
// Verifications
687+
verify(mockedContract.getFactoryDetails).once();
688+
verify(mockedMethod.callAsync(params.factoryAddress)).once();
689+
});
690+
});
691+
678692
describe('ReclaimERC20', () => {
679693
test.todo('should fail as tokenContract is not an Eth address');
680694

src/contract_wrappers/registries/module_registry_wrapper.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,6 @@ interface GetModuleRegistryLogsAsyncParams extends GetLogs {
131131
>;
132132
}
133133

134-
interface GetValueByVariableParams {
135-
variable: string;
136-
}
137-
138-
interface GetValueByKeyParams {
139-
key: string;
140-
}
141-
142134
interface ModuleFactoryParams extends TxParams {
143135
moduleFactory: string;
144136
}
@@ -161,6 +153,10 @@ interface IsCompatibleModuleParams {
161153
securityToken: string;
162154
}
163155

156+
interface GetFactoryDetailsParams {
157+
factoryAddress: string;
158+
}
159+
164160
interface ReclaimERC20Params extends TxParams {
165161
tokenContract: string;
166162
}
@@ -174,6 +170,12 @@ interface TagsByModule {
174170
module: string;
175171
tags: string[];
176172
}
173+
174+
interface FactoryDetails {
175+
factoryIsVerified: boolean;
176+
factoryOwnerAddress: string;
177+
listSecurityTokens: string[];
178+
}
177179
// // End of return types ////
178180

179181
/**
@@ -336,6 +338,19 @@ export default class ModuleRegistryWrapper extends ContractWrapper {
336338
return typedResult;
337339
};
338340

341+
/**
342+
* @returns Returns factoryIsVerified, factoryOwnerAddress, listSecurityTokens
343+
*/
344+
public getFactoryDetails = async (params: GetFactoryDetailsParams) => {
345+
const result = await (await this.contract).getFactoryDetails.callAsync(params.factoryAddress);
346+
const typedResult: FactoryDetails = {
347+
factoryIsVerified: result[0],
348+
factoryOwnerAddress: result[1],
349+
listSecurityTokens: result[2],
350+
};
351+
return typedResult;
352+
};
353+
339354
public getModulesByType = async (params: ModuleTypeParams) => {
340355
return (await this.contract).getModulesByType.callAsync(params.moduleType);
341356
};

0 commit comments

Comments
 (0)