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

Commit 841a12e

Browse files
author
Victor Wiebe
committed
feat: 🎸 getTokensByPartition with test
1 parent de2b1f9 commit 841a12e

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
valueToWei,
2121
weiToValue,
2222
} from '../../../../utils/convert';
23+
import { Partition } from '../../../../types';
2324

2425
describe('LockUpTransferManagerWrapper', () => {
2526
let target: LockUpTransferManagerWrapper;
@@ -511,6 +512,64 @@ describe('LockUpTransferManagerWrapper', () => {
511512
});
512513
});
513514

515+
describe('getTokensByPartition', () => {
516+
test('should call to getTokensByPartition', async () => {
517+
const expectedDecimalsResult = new BigNumber(18);
518+
const expectedResult = valueToWei(new BigNumber(100), expectedDecimalsResult);
519+
const mockedParams = {
520+
partition: Partition.Unlocked,
521+
tokenHolder: '0x8888888888888888888888888888888888888888',
522+
additionalBalance: new BigNumber(10),
523+
};
524+
525+
// Security Token Address expected
526+
const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333';
527+
// Setup get Security Token Address
528+
const mockedGetSecurityTokenAddressMethod = mock(MockedCallMethod);
529+
when(mockedContract.securityToken).thenReturn(instance(mockedGetSecurityTokenAddressMethod));
530+
when(mockedGetSecurityTokenAddressMethod.callAsync()).thenResolve(expectedSecurityTokenAddress);
531+
when(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).thenResolve(
532+
instance(mockedSecurityTokenContract),
533+
);
534+
const mockedSecurityTokenDecimalsMethod = mock(MockedCallMethod);
535+
when(mockedSecurityTokenDecimalsMethod.callAsync()).thenResolve(expectedDecimalsResult);
536+
when(mockedSecurityTokenContract.decimals).thenReturn(instance(mockedSecurityTokenDecimalsMethod));
537+
538+
// Mocked method
539+
const mockedMethod = mock(MockedCallMethod);
540+
// Stub the method
541+
when(mockedContract.getTokensByPartition).thenReturn(instance(mockedMethod));
542+
// Stub the request
543+
when(
544+
mockedMethod.callAsync(
545+
mockedParams.partition,
546+
mockedParams.tokenHolder,
547+
objectContaining(valueToWei(mockedParams.additionalBalance, expectedDecimalsResult)),
548+
),
549+
).thenResolve(expectedResult);
550+
551+
// Real call
552+
const result = await target.getTokensByPartition(mockedParams);
553+
// Result expectation
554+
expect(result).toEqual(weiToValue(expectedResult, expectedDecimalsResult));
555+
556+
// Verifications
557+
verify(mockedContract.getTokensByPartition).once();
558+
verify(
559+
mockedMethod.callAsync(
560+
mockedParams.partition,
561+
mockedParams.tokenHolder,
562+
objectContaining(valueToWei(mockedParams.additionalBalance, expectedDecimalsResult)),
563+
),
564+
).once();
565+
verify(mockedContract.securityToken).once();
566+
verify(mockedGetSecurityTokenAddressMethod.callAsync()).once();
567+
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).once();
568+
verify(mockedSecurityTokenDecimalsMethod.callAsync()).once();
569+
verify(mockedSecurityTokenContract.decimals).once();
570+
});
571+
});
572+
514573
describe('verifyTransfer', () => {
515574
test('should verify Transfer', async () => {
516575
const statusCode = new BigNumber(2);

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
EventCallback,
2424
GetLogs,
2525
GetLogsAsyncParams,
26+
Partition,
2627
Subscribe,
2728
SubscribeAsyncParams,
2829
TransferResult,
@@ -139,6 +140,12 @@ interface UserAddressParams {
139140
user: string;
140141
}
141142

143+
interface GetTokensByPartitionParams {
144+
partition: Partition;
145+
tokenHolder: string;
146+
additionalBalance: BigNumber;
147+
}
148+
142149
interface VerifyTransferParams {
143150
from: string;
144151
to: string;
@@ -289,6 +296,22 @@ export default class LockUpTransferManagerWrapper extends ModuleWrapper {
289296
return weiToValue(await (await this.contract).getLockedTokenToUser.callAsync(params.user), decimals);
290297
};
291298

299+
/**
300+
* getTokensByPartition
301+
*/
302+
public getTokensByPartition = async (params: GetTokensByPartitionParams): Promise<BigNumber> => {
303+
assert.isNonZeroETHAddressHex('Token Holder', params.tokenHolder);
304+
const decimals = await (await this.securityTokenContract()).decimals.callAsync();
305+
return weiToValue(
306+
await (await this.contract).getTokensByPartition.callAsync(
307+
params.partition,
308+
params.tokenHolder,
309+
valueToWei(params.additionalBalance, decimals),
310+
),
311+
decimals,
312+
);
313+
};
314+
292315
/*
293316
* verifyTransfer
294317
*/

0 commit comments

Comments
 (0)