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

Commit 8923b55

Browse files
author
Victor Wiebe
committed
feat: 🎸 addLockUpByName
1 parent eec1d62 commit 8923b55

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

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

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,122 @@ describe('LockUpTransferManagerWrapper', () => {
814814
});
815815
});
816816

817+
describe('addLockUpByName', () => {
818+
test('should call addLockUpByName', async () => {
819+
const expectedOwnerResult = '0x8888888888888888888888888888888888888888';
820+
const expectedLockUpInvestorAddress = '0x4444444444444444444444444444444444444444';
821+
const lockupName = 'Lockup3';
822+
const expectedDecimalsResult = new BigNumber(18);
823+
const expectedLockupAmount = valueToWei(new BigNumber(10), expectedDecimalsResult);
824+
const expectedStartTime = dateToBigNumber(new Date(2030, 1));
825+
const expectedLockUpPeriodSeconds = new BigNumber(3600);
826+
const expectedReleaseFrequencySeconds = new BigNumber(60);
827+
const expectedUnlockedAmount = new BigNumber(0);
828+
const expectedGetLockupResult = [
829+
expectedLockupAmount,
830+
expectedStartTime,
831+
expectedLockUpPeriodSeconds,
832+
expectedReleaseFrequencySeconds,
833+
expectedUnlockedAmount,
834+
];
835+
const mockedGetLockupParams = {
836+
lockupName,
837+
};
838+
839+
// Security Token Address expected
840+
const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333';
841+
// Setup get Security Token Address
842+
const mockedGetSecurityTokenAddressMethod = mock(MockedCallMethod);
843+
when(mockedContract.securityToken).thenReturn(instance(mockedGetSecurityTokenAddressMethod));
844+
when(mockedGetSecurityTokenAddressMethod.callAsync()).thenResolve(expectedSecurityTokenAddress);
845+
when(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).thenResolve(
846+
instance(mockedSecurityTokenContract),
847+
);
848+
const mockedSecurityTokenDecimalsMethod = mock(MockedCallMethod);
849+
when(mockedSecurityTokenDecimalsMethod.callAsync()).thenResolve(expectedDecimalsResult);
850+
when(mockedSecurityTokenContract.decimals).thenReturn(instance(mockedSecurityTokenDecimalsMethod));
851+
const mockedSecurityTokenOwnerMethod = mock(MockedCallMethod);
852+
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
853+
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));
854+
855+
// Mock web3 wrapper owner
856+
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);
857+
858+
// Mocked method
859+
const mockedGetLockupMethod = mock(MockedCallMethod);
860+
// Stub the method
861+
when(mockedContract.getLockUp).thenReturn(instance(mockedGetLockupMethod));
862+
// Stub the request
863+
when(
864+
mockedGetLockupMethod.callAsync(objectContaining(stringToBytes32(mockedGetLockupParams.lockupName))),
865+
).thenResolve(expectedGetLockupResult);
866+
867+
const expectedGetLockupsNamesToUserResult = stringArrayToBytes32Array(['Lockup1', 'Lockup2']);
868+
const mockedGetLockupsNamesToUserParams = {
869+
user: expectedLockUpInvestorAddress,
870+
};
871+
// Mocked method
872+
const mockedGetLockupsNamesToUserMethod = mock(MockedCallMethod);
873+
// Stub the method
874+
when(mockedContract.getLockupsNamesToUser).thenReturn(instance(mockedGetLockupsNamesToUserMethod));
875+
// Stub the request
876+
when(mockedGetLockupsNamesToUserMethod.callAsync(mockedGetLockupsNamesToUserParams.user)).thenResolve(
877+
expectedGetLockupsNamesToUserResult,
878+
);
879+
880+
const mockedParams = {
881+
userAddress: expectedLockUpInvestorAddress,
882+
lockupName,
883+
txData: {},
884+
safetyFactor: 10,
885+
};
886+
const expectedResult = getMockedPolyResponse();
887+
// Mocked method
888+
const mockedMethod = mock(MockedSendMethod);
889+
// Stub the method
890+
when(mockedContract.addLockUpByName).thenReturn(instance(mockedMethod));
891+
// Stub the request
892+
when(
893+
mockedMethod.sendTransactionAsync(
894+
mockedParams.userAddress,
895+
objectContaining(stringToBytes32(mockedParams.lockupName)),
896+
mockedParams.txData,
897+
mockedParams.safetyFactor,
898+
),
899+
).thenResolve(expectedResult);
900+
901+
// Real call
902+
const result = await target.addLockUpByName(mockedParams);
903+
904+
// Result expectation
905+
expect(result).toBe(expectedResult);
906+
// Verifications
907+
verify(mockedContract.addLockUpByName).once();
908+
verify(
909+
mockedMethod.sendTransactionAsync(
910+
mockedParams.userAddress,
911+
objectContaining(stringToBytes32(mockedParams.lockupName)),
912+
mockedParams.txData,
913+
mockedParams.safetyFactor,
914+
),
915+
).once();
916+
verify(mockedSecurityTokenOwnerMethod.callAsync()).once();
917+
verify(mockedSecurityTokenContract.owner).once();
918+
verify(mockedSecurityTokenDecimalsMethod.callAsync()).once();
919+
verify(mockedSecurityTokenContract.decimals).once();
920+
verify(mockedContract.securityToken).twice();
921+
verify(mockedGetSecurityTokenAddressMethod.callAsync()).twice();
922+
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).twice();
923+
verify(mockedWrapper.getAvailableAddressesAsync()).once();
924+
verify(mockedContract.getLockUp).once();
925+
verify(
926+
mockedGetLockupMethod.callAsync(objectContaining(stringToBytes32(mockedGetLockupParams.lockupName))),
927+
).once();
928+
verify(mockedContract.getLockupsNamesToUser).once();
929+
verify(mockedGetLockupsNamesToUserMethod.callAsync(mockedGetLockupsNamesToUserParams.user)).once();
930+
});
931+
});
932+
817933
describe('verifyTransfer', () => {
818934
test('should verify Transfer', async () => {
819935
const statusCode = new BigNumber(2);

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ interface AddNewLockUpTypeMultiParams extends TxParams {
175175
lockupNames: string[];
176176
}
177177

178+
interface AddLockUpByNameParams extends TxParams {
179+
userAddress: string;
180+
lockupName: string;
181+
}
182+
178183
// // Return types ////
179184
interface LockUp {
180185
lockupAmount: BigNumber;
@@ -421,6 +426,21 @@ export default class LockUpTransferManagerWrapper extends ModuleWrapper {
421426
);
422427
};
423428

429+
430+
/*
431+
* addLockUpByName
432+
*/
433+
public addLockUpByName = async (params: AddLockUpByNameParams) => {
434+
assert.assert(await this.isCallerAllowed(params.txData, Perm.Admin), 'Caller is not allowed');
435+
await this.checkAddLockUpByName(params);
436+
return (await this.contract).addLockUpByName.sendTransactionAsync(
437+
params.userAddress,
438+
stringToBytes32(params.lockupName),
439+
params.txData,
440+
params.safetyFactor,
441+
);
442+
};
443+
424444
/**
425445
* Subscribe to an event type emitted by the contract.
426446
* @return Subscription token used later to unsubscribe
@@ -480,4 +500,15 @@ export default class LockUpTransferManagerWrapper extends ModuleWrapper {
480500
);
481501
assert.isBigNumberGreaterThanZero(params.lockupAmount, 'Lockup amount should be greater than 0');
482502
};
503+
504+
private checkAddLockUpByName = async (params: AddLockUpByNameParams) => {
505+
assert.assert(params.lockupName.length > 0, 'Lockup Name cannot be empty string');
506+
assert.isNonZeroETHAddressHex('User Address', params.userAddress);
507+
const lockup = await this.getLockUp({ lockupName: params.lockupName });
508+
assert.isFutureDate(lockup.startTime, 'Start time must be in the future');
509+
const lockupNames = await this.getLockupsNamesToUser({user: params.userAddress});
510+
console.log(lockupNames);
511+
console.log(params.lockupName);
512+
assert.assert(!lockupNames.includes(params.lockupName), 'User already added to this lockup name');
513+
};
483514
}

0 commit comments

Comments
 (0)