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

Commit c7d61e5

Browse files
author
Victor Wiebe
committed
feat: 🎸 addLockupByNameMulti method and tests
1 parent 8923b55 commit c7d61e5

File tree

2 files changed

+160
-8
lines changed

2 files changed

+160
-8
lines changed

‎src/contract_wrappers/modules/transfer_manager/__tests__/lock_up_transfer_manager_wrapper.test.ts‎

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,129 @@ describe('LockUpTransferManagerWrapper', () => {
930930
});
931931
});
932932

933+
describe('addLockUpByNameMulti', () => {
934+
test('should call addLockUpByNameMulti', async () => {
935+
const expectedOwnerResult = '0x8888888888888888888888888888888888888888';
936+
const expectedLockUpInvestorAddresses = [
937+
'0x0123456789012345678901234567890123456789',
938+
'0x2222222222222222222222222222222222222222',
939+
];
940+
const lockupNames = ['Lockup1', 'Lockup2'];
941+
const expectedDecimalsResult = new BigNumber(18);
942+
const expectedLockupAmount = valueToWei(new BigNumber(0), expectedDecimalsResult);
943+
const expectedStartTime = dateToBigNumber(new Date(2030, 1));
944+
const expectedLockUpPeriodSeconds = new BigNumber(3600);
945+
const expectedReleaseFrequencySeconds = new BigNumber(60);
946+
const expectedUnlockedAmount = new BigNumber(0);
947+
const expectedGetLockupResult = [
948+
expectedLockupAmount,
949+
expectedStartTime,
950+
expectedLockUpPeriodSeconds,
951+
expectedReleaseFrequencySeconds,
952+
expectedUnlockedAmount,
953+
];
954+
955+
// Security Token Address expected
956+
const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333';
957+
// Setup get Security Token Address
958+
const mockedGetSecurityTokenAddressMethod = mock(MockedCallMethod);
959+
when(mockedContract.securityToken).thenReturn(instance(mockedGetSecurityTokenAddressMethod));
960+
when(mockedGetSecurityTokenAddressMethod.callAsync()).thenResolve(expectedSecurityTokenAddress);
961+
when(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).thenResolve(
962+
instance(mockedSecurityTokenContract),
963+
);
964+
const mockedSecurityTokenDecimalsMethod = mock(MockedCallMethod);
965+
when(mockedSecurityTokenDecimalsMethod.callAsync()).thenResolve(expectedDecimalsResult);
966+
when(mockedSecurityTokenContract.decimals).thenReturn(instance(mockedSecurityTokenDecimalsMethod));
967+
const mockedSecurityTokenOwnerMethod = mock(MockedCallMethod);
968+
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
969+
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));
970+
971+
// Mock web3 wrapper owner
972+
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);
973+
974+
// Mocked method
975+
const mockedGetLockupMethod = mock(MockedCallMethod);
976+
// Stub the method
977+
when(mockedContract.getLockUp).thenReturn(instance(mockedGetLockupMethod));
978+
// Stub the request
979+
for (let i = 0; i < lockupNames.length; i += 1) {
980+
when(mockedGetLockupMethod.callAsync(objectContaining(stringToBytes32(lockupNames[i])))).thenResolve(
981+
expectedGetLockupResult,
982+
);
983+
}
984+
985+
const expectedGetLockupsNamesToUserResult = stringArrayToBytes32Array(['Lockup3', 'Lockup4']);
986+
const mockedGetLockupsNamesToUserParams = {
987+
userAddresses: expectedLockUpInvestorAddresses,
988+
};
989+
// Mocked method
990+
const mockedGetLockupsNamesToUserMethod = mock(MockedCallMethod);
991+
// Stub the method
992+
when(mockedContract.getLockupsNamesToUser).thenReturn(instance(mockedGetLockupsNamesToUserMethod));
993+
// Stub the request
994+
for (let i = 0; i < lockupNames.length; i += 1) {
995+
when(
996+
mockedGetLockupsNamesToUserMethod.callAsync(mockedGetLockupsNamesToUserParams.userAddresses[i]),
997+
).thenResolve(expectedGetLockupsNamesToUserResult);
998+
}
999+
1000+
const mockedParams = {
1001+
lockupNames,
1002+
userAddresses: expectedLockUpInvestorAddresses,
1003+
txData: {},
1004+
safetyFactor: 10,
1005+
};
1006+
const expectedResult = getMockedPolyResponse();
1007+
// Mocked method
1008+
const mockedMethod = mock(MockedSendMethod);
1009+
// Stub the method
1010+
when(mockedContract.addLockUpByNameMulti).thenReturn(instance(mockedMethod));
1011+
// Stub the request
1012+
when(
1013+
mockedMethod.sendTransactionAsync(
1014+
mockedParams.userAddresses,
1015+
objectContaining(stringArrayToBytes32Array(mockedParams.lockupNames)),
1016+
mockedParams.txData,
1017+
mockedParams.safetyFactor,
1018+
),
1019+
).thenResolve(expectedResult);
1020+
1021+
// Real call
1022+
const result = await target.addLockUpByNameMulti(mockedParams);
1023+
1024+
// Result expectation
1025+
expect(result).toBe(expectedResult);
1026+
// Verifications
1027+
verify(mockedContract.addLockUpByNameMulti).once();
1028+
verify(
1029+
mockedMethod.sendTransactionAsync(
1030+
mockedParams.userAddresses,
1031+
objectContaining(stringArrayToBytes32Array(mockedParams.lockupNames)),
1032+
mockedParams.txData,
1033+
mockedParams.safetyFactor,
1034+
),
1035+
).once();
1036+
verify(mockedSecurityTokenOwnerMethod.callAsync()).once();
1037+
verify(mockedSecurityTokenContract.owner).once();
1038+
verify(mockedContract.securityToken).times(3);
1039+
verify(mockedSecurityTokenDecimalsMethod.callAsync()).twice();
1040+
verify(mockedSecurityTokenContract.decimals).twice();
1041+
verify(mockedGetSecurityTokenAddressMethod.callAsync()).times(3);
1042+
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).times(3);
1043+
verify(mockedWrapper.getAvailableAddressesAsync()).once();
1044+
verify(mockedContract.getLockUp).times(lockupNames.length);
1045+
for (let i = 0; i < lockupNames.length; i += 1) {
1046+
verify(mockedGetLockupMethod.callAsync(objectContaining(stringToBytes32(lockupNames[i])))).once();
1047+
}
1048+
verify(mockedContract.getLockupsNamesToUser).times(lockupNames.length);
1049+
// Stub the request
1050+
for (let i = 0; i < lockupNames.length; i += 1) {
1051+
verify(mockedGetLockupsNamesToUserMethod.callAsync(mockedGetLockupsNamesToUserParams.userAddresses[i])).once();
1052+
}
1053+
});
1054+
});
1055+
9331056
describe('verifyTransfer', () => {
9341057
test('should verify Transfer', async () => {
9351058
const statusCode = new BigNumber(2);

‎src/contract_wrappers/modules/transfer_manager/lock_up_transfer_manager_wrapper.ts‎

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ interface AddLockUpByNameParams extends TxParams {
180180
lockupName: string;
181181
}
182182

183+
interface AddLockUpByNameMultiParams extends TxParams {
184+
userAddresses: string[];
185+
lockupNames: string[];
186+
}
187+
183188
// // Return types ////
184189
interface LockUp {
185190
lockupAmount: BigNumber;
@@ -426,18 +431,42 @@ export default class LockUpTransferManagerWrapper extends ModuleWrapper {
426431
);
427432
};
428433

429-
430434
/*
431435
* addLockUpByName
432436
*/
433437
public addLockUpByName = async (params: AddLockUpByNameParams) => {
434438
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
435439
await this.checkAddLockUpByName(params);
436440
return (await this.contract).addLockUpByName.sendTransactionAsync(
437-
params.userAddress,
438-
stringToBytes32(params.lockupName),
439-
params.txData,
440-
params.safetyFactor,
441+
params.userAddress,
442+
stringToBytes32(params.lockupName),
443+
params.txData,
444+
params.safetyFactor,
445+
);
446+
};
447+
448+
/*
449+
* addLockUpByNameMulti
450+
*/
451+
public addLockUpByNameMulti = async (params: AddLockUpByNameMultiParams) => {
452+
assert.assert(params.lockupNames.length > 0, 'Empty lockup information');
453+
assert.areValidArrayLengths([params.userAddresses, params.lockupNames], 'Argument arrays length mismatch');
454+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
455+
const results = [];
456+
for (let i = 0; i < params.lockupNames.length; i += 1) {
457+
results.push(
458+
this.checkAddLockUpByName({
459+
lockupName: params.lockupNames[i],
460+
userAddress: params.userAddresses[i],
461+
}),
462+
);
463+
}
464+
await Promise.all(results);
465+
return (await this.contract).addLockUpByNameMulti.sendTransactionAsync(
466+
params.userAddresses,
467+
stringArrayToBytes32Array(params.lockupNames),
468+
params.txData,
469+
params.safetyFactor,
441470
);
442471
};
443472

@@ -495,8 +524,8 @@ export default class LockUpTransferManagerWrapper extends ModuleWrapper {
495524
assert.isFutureDate(params.startTime, 'Start time must be in the future');
496525
assert.isBigNumberGreaterThanZero(params.lockUpPeriodSeconds, 'Lockup period in seconds should be greater than 0');
497526
assert.isBigNumberGreaterThanZero(
498-
params.releaseFrequenciesSeconds,
499-
'Release frequency in seconds should be greater than 0',
527+
params.releaseFrequenciesSeconds,
528+
'Release frequency in seconds should be greater than 0',
500529
);
501530
assert.isBigNumberGreaterThanZero(params.lockupAmount, 'Lockup amount should be greater than 0');
502531
};
@@ -506,7 +535,7 @@ export default class LockUpTransferManagerWrapper extends ModuleWrapper {
506535
assert.isNonZeroETHAddressHex('User Address', params.userAddress);
507536
const lockup = await this.getLockUp({ lockupName: params.lockupName });
508537
assert.isFutureDate(lockup.startTime, 'Start time must be in the future');
509-
const lockupNames = await this.getLockupsNamesToUser({user: params.userAddress});
538+
const lockupNames = await this.getLockupsNamesToUser({ user: params.userAddress });
510539
console.log(lockupNames);
511540
console.log(params.lockupName);
512541
assert.assert(!lockupNames.includes(params.lockupName), 'User already added to this lockup name');

0 commit comments

Comments
 (0)