@@ -11,8 +11,14 @@ import { getMockedPolyResponse, MockedCallMethod, MockedSendMethod } from '../..
11
11
import LockUpTransferManagerWrapper from '../lock_up_transfer_manager_wrapper' ;
12
12
import ContractFactory from '../../../../factories/contractFactory' ;
13
13
import ModuleWrapper from '../../module_wrapper' ;
14
- import { dateToBigNumber , stringToBytes32 , valueToWei , weiToValue } from '../../../../utils/convert' ;
15
- import { FULL_DECIMALS } from '../../../../types' ;
14
+ import {
15
+ bytes32ArrayToStringArray ,
16
+ dateToBigNumber ,
17
+ stringArrayToBytes32Array ,
18
+ stringToBytes32 ,
19
+ valueToWei ,
20
+ weiToValue ,
21
+ } from '../../../../utils/convert' ;
16
22
17
23
describe ( 'LockUpTransferManagerWrapper' , ( ) => {
18
24
let target : LockUpTransferManagerWrapper ;
@@ -196,10 +202,11 @@ describe('LockUpTransferManagerWrapper', () => {
196
202
} ) ;
197
203
198
204
describe ( 'lockups' , ( ) => {
199
- test . todo ( 'should fail as lockup details is an empty string' ) ;
205
+ test . todo ( 'should fail as lockup name is an empty string' ) ;
200
206
201
207
test ( 'should call to lockups' , async ( ) => {
202
- const expectedLockupAmount = valueToWei ( new BigNumber ( 1 ) , FULL_DECIMALS ) ;
208
+ const expectedDecimalsResult = new BigNumber ( 18 ) ;
209
+ const expectedLockupAmount = valueToWei ( new BigNumber ( 1 ) , expectedDecimalsResult ) ;
203
210
const startTime = new Date ( 2030 , 1 ) ;
204
211
const expectedStartTime = dateToBigNumber ( startTime ) ;
205
212
const expectedLockUpPeriodSeconds = new BigNumber ( 3600 ) ;
@@ -211,26 +218,177 @@ describe('LockUpTransferManagerWrapper', () => {
211
218
expectedReleaseFrequencySeconds ,
212
219
] ;
213
220
const mockedParams = {
214
- details : 'LockupDetails' ,
221
+ lockupName : 'LockupDetails' ,
215
222
} ;
223
+
224
+ // Security Token Address expected
225
+ const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333' ;
226
+ // Setup get Security Token Address
227
+ const mockedGetSecurityTokenAddressMethod = mock ( MockedCallMethod ) ;
228
+ when ( mockedContract . securityToken ) . thenReturn ( instance ( mockedGetSecurityTokenAddressMethod ) ) ;
229
+ when ( mockedGetSecurityTokenAddressMethod . callAsync ( ) ) . thenResolve ( expectedSecurityTokenAddress ) ;
230
+ when ( mockedContractFactory . getSecurityTokenContract ( expectedSecurityTokenAddress ) ) . thenResolve (
231
+ instance ( mockedSecurityTokenContract ) ,
232
+ ) ;
233
+ const mockedSecurityTokenDecimalsMethod = mock ( MockedCallMethod ) ;
234
+ when ( mockedSecurityTokenDecimalsMethod . callAsync ( ) ) . thenResolve ( expectedDecimalsResult ) ;
235
+ when ( mockedSecurityTokenContract . decimals ) . thenReturn ( instance ( mockedSecurityTokenDecimalsMethod ) ) ;
236
+
216
237
// Mocked method
217
238
const mockedMethod = mock ( MockedCallMethod ) ;
218
239
// Stub the method
219
240
when ( mockedContract . lockups ) . thenReturn ( instance ( mockedMethod ) ) ;
220
241
// Stub the request
221
- when ( mockedMethod . callAsync ( objectContaining ( stringToBytes32 ( mockedParams . details ) ) ) ) . thenResolve ( expectedResult ) ;
242
+ when ( mockedMethod . callAsync ( objectContaining ( stringToBytes32 ( mockedParams . lockupName ) ) ) ) . thenResolve (
243
+ expectedResult ,
244
+ ) ;
222
245
223
246
// Real call
224
247
const result = await target . lockups ( mockedParams ) ;
225
248
// Result expectation
226
- expect ( result . lockupAmount ) . toEqual ( weiToValue ( expectedLockupAmount , FULL_DECIMALS ) ) ;
249
+ expect ( result . lockupAmount ) . toEqual ( weiToValue ( expectedLockupAmount , expectedDecimalsResult ) ) ;
227
250
expect ( result . startTime ) . toEqual ( startTime ) ;
228
251
expect ( result . lockUpPeriodSeconds ) . toBe ( expectedResult [ 2 ] ) ;
229
252
expect ( result . releaseFrequencySeconds ) . toBe ( expectedResult [ 3 ] ) ;
230
253
231
254
// Verifications
232
255
verify ( mockedContract . lockups ) . once ( ) ;
233
- verify ( mockedMethod . callAsync ( objectContaining ( stringToBytes32 ( mockedParams . details ) ) ) ) . once ( ) ;
256
+ verify ( mockedMethod . callAsync ( objectContaining ( stringToBytes32 ( mockedParams . lockupName ) ) ) ) . once ( ) ;
257
+ verify ( mockedContract . securityToken ) . once ( ) ;
258
+ verify ( mockedGetSecurityTokenAddressMethod . callAsync ( ) ) . once ( ) ;
259
+ verify ( mockedContractFactory . getSecurityTokenContract ( expectedSecurityTokenAddress ) ) . once ( ) ;
260
+ verify ( mockedSecurityTokenDecimalsMethod . callAsync ( ) ) . once ( ) ;
261
+ verify ( mockedSecurityTokenContract . decimals ) . once ( ) ;
262
+ } ) ;
263
+ } ) ;
264
+
265
+ describe ( 'getLockUp' , ( ) => {
266
+ test . todo ( 'should fail as lockup name is an empty string' ) ;
267
+
268
+ test ( 'should call to getLockups' , async ( ) => {
269
+ const expectedDecimalsResult = new BigNumber ( 18 ) ;
270
+ const expectedLockupAmount = valueToWei ( new BigNumber ( 2 ) , expectedDecimalsResult ) ;
271
+ const startTime = new Date ( 2030 , 1 ) ;
272
+ const expectedStartTime = dateToBigNumber ( startTime ) ;
273
+ const expectedLockUpPeriodSeconds = new BigNumber ( 3600 ) ;
274
+ const expectedReleaseFrequencySeconds = new BigNumber ( 60 ) ;
275
+ const expectedUnlockedAmount = new BigNumber ( 1 ) ;
276
+ const expectedResult = [
277
+ expectedLockupAmount ,
278
+ expectedStartTime ,
279
+ expectedLockUpPeriodSeconds ,
280
+ expectedReleaseFrequencySeconds ,
281
+ expectedUnlockedAmount ,
282
+ ] ;
283
+ const mockedParams = {
284
+ lockupName : 'LockupDetails' ,
285
+ } ;
286
+
287
+ // Security Token Address expected
288
+ const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333' ;
289
+ // Setup get Security Token Address
290
+ const mockedGetSecurityTokenAddressMethod = mock ( MockedCallMethod ) ;
291
+ when ( mockedContract . securityToken ) . thenReturn ( instance ( mockedGetSecurityTokenAddressMethod ) ) ;
292
+ when ( mockedGetSecurityTokenAddressMethod . callAsync ( ) ) . thenResolve ( expectedSecurityTokenAddress ) ;
293
+ when ( mockedContractFactory . getSecurityTokenContract ( expectedSecurityTokenAddress ) ) . thenResolve (
294
+ instance ( mockedSecurityTokenContract ) ,
295
+ ) ;
296
+ const mockedSecurityTokenDecimalsMethod = mock ( MockedCallMethod ) ;
297
+ when ( mockedSecurityTokenDecimalsMethod . callAsync ( ) ) . thenResolve ( expectedDecimalsResult ) ;
298
+ when ( mockedSecurityTokenContract . decimals ) . thenReturn ( instance ( mockedSecurityTokenDecimalsMethod ) ) ;
299
+
300
+ // Mocked method
301
+ const mockedMethod = mock ( MockedCallMethod ) ;
302
+ // Stub the method
303
+ when ( mockedContract . getLockUp ) . thenReturn ( instance ( mockedMethod ) ) ;
304
+ // Stub the request
305
+ when ( mockedMethod . callAsync ( objectContaining ( stringToBytes32 ( mockedParams . lockupName ) ) ) ) . thenResolve (
306
+ expectedResult ,
307
+ ) ;
308
+
309
+ // Real call
310
+ const result = await target . getLockUp ( mockedParams ) ;
311
+ // Result expectation
312
+ expect ( result . lockupAmount ) . toEqual ( weiToValue ( expectedLockupAmount , expectedDecimalsResult ) ) ;
313
+ expect ( result . startTime ) . toEqual ( startTime ) ;
314
+ expect ( result . lockUpPeriodSeconds ) . toBe ( expectedResult [ 2 ] ) ;
315
+ expect ( result . releaseFrequencySeconds ) . toBe ( expectedResult [ 3 ] ) ;
316
+ expect ( result . unlockedAmount ) . toEqual ( weiToValue ( expectedUnlockedAmount , expectedDecimalsResult ) ) ;
317
+
318
+ // Verifications
319
+ verify ( mockedContract . getLockUp ) . once ( ) ;
320
+ verify ( mockedMethod . callAsync ( objectContaining ( stringToBytes32 ( mockedParams . lockupName ) ) ) ) . once ( ) ;
321
+ verify ( mockedContract . securityToken ) . once ( ) ;
322
+ verify ( mockedGetSecurityTokenAddressMethod . callAsync ( ) ) . once ( ) ;
323
+ verify ( mockedContractFactory . getSecurityTokenContract ( expectedSecurityTokenAddress ) ) . once ( ) ;
324
+ verify ( mockedSecurityTokenDecimalsMethod . callAsync ( ) ) . once ( ) ;
325
+ verify ( mockedSecurityTokenContract . decimals ) . once ( ) ;
326
+ } ) ;
327
+ } ) ;
328
+
329
+ describe ( 'getAllLockUpData' , ( ) => {
330
+ test ( 'should call to getAllLockupData' , async ( ) => {
331
+ const expectedDecimalsResult = new BigNumber ( 18 ) ;
332
+ const expectedNames = stringArrayToBytes32Array ( [
333
+ 'Lockup1' ,
334
+ 'Lockup2' ,
335
+ ] ) ;
336
+ const expectedLockupAmount = valueToWei ( new BigNumber ( 2 ) , expectedDecimalsResult ) ;
337
+ const startTime = new Date ( 2030 , 1 ) ;
338
+ const expectedStartTime = dateToBigNumber ( startTime ) ;
339
+ const expectedLockUpPeriodSeconds = new BigNumber ( 3600 ) ;
340
+ const expectedReleaseFrequencySeconds = new BigNumber ( 60 ) ;
341
+ const expectedUnlockedAmount = new BigNumber ( 1 ) ;
342
+ const expectedResult = [
343
+ expectedNames ,
344
+ [ expectedLockupAmount , expectedLockupAmount ] ,
345
+ [ expectedStartTime , expectedStartTime ] ,
346
+ [ expectedLockUpPeriodSeconds , expectedLockUpPeriodSeconds ] ,
347
+ [ expectedReleaseFrequencySeconds , expectedReleaseFrequencySeconds ] ,
348
+ [ expectedUnlockedAmount , expectedUnlockedAmount ] ,
349
+ ] ;
350
+
351
+ // Security Token Address expected
352
+ const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333' ;
353
+ // Setup get Security Token Address
354
+ const mockedGetSecurityTokenAddressMethod = mock ( MockedCallMethod ) ;
355
+ when ( mockedContract . securityToken ) . thenReturn ( instance ( mockedGetSecurityTokenAddressMethod ) ) ;
356
+ when ( mockedGetSecurityTokenAddressMethod . callAsync ( ) ) . thenResolve ( expectedSecurityTokenAddress ) ;
357
+ when ( mockedContractFactory . getSecurityTokenContract ( expectedSecurityTokenAddress ) ) . thenResolve (
358
+ instance ( mockedSecurityTokenContract ) ,
359
+ ) ;
360
+ const mockedSecurityTokenDecimalsMethod = mock ( MockedCallMethod ) ;
361
+ when ( mockedSecurityTokenDecimalsMethod . callAsync ( ) ) . thenResolve ( expectedDecimalsResult ) ;
362
+ when ( mockedSecurityTokenContract . decimals ) . thenReturn ( instance ( mockedSecurityTokenDecimalsMethod ) ) ;
363
+
364
+ // Mocked method
365
+ const mockedMethod = mock ( MockedCallMethod ) ;
366
+ // Stub the method
367
+ when ( mockedContract . getAllLockupData ) . thenReturn ( instance ( mockedMethod ) ) ;
368
+ // Stub the request
369
+ when ( mockedMethod . callAsync ( ) ) . thenResolve ( expectedResult ) ;
370
+
371
+ // Real call
372
+ const result = await target . getAllLockupData ( ) ;
373
+ // Result expectation
374
+ expect ( result [ 0 ] . lockupName ) . toEqual ( expectedResult [ 0 ] [ 0 ] ) ;
375
+ for ( let i = 0 ; i < result . length ; i += 1 ) {
376
+ expect ( result [ 1 ] . lockupName ) . toEqual ( bytes32ArrayToStringArray ( expectedNames ) ) ;
377
+ expect ( result [ i ] . lockupAmount ) . toEqual ( weiToValue ( expectedLockupAmount , expectedDecimalsResult ) ) ;
378
+ expect ( result [ i ] . startTime ) . toEqual ( startTime ) ;
379
+ expect ( result [ i ] . lockUpPeriodSeconds ) . toBe ( expectedResult [ 2 ] ) ;
380
+ expect ( result [ i ] . releaseFrequencySeconds ) . toBe ( expectedResult [ 3 ] ) ;
381
+ expect ( result [ i ] . unlockedAmount ) . toEqual ( weiToValue ( expectedUnlockedAmount , expectedDecimalsResult ) ) ;
382
+ } ;
383
+
384
+ // Verifications
385
+ verify ( mockedContract . getAllLockupData ) . once ( ) ;
386
+ verify ( mockedMethod . callAsync ( ) ) . once ( ) ;
387
+ verify ( mockedContract . securityToken ) . once ( ) ;
388
+ verify ( mockedGetSecurityTokenAddressMethod . callAsync ( ) ) . once ( ) ;
389
+ verify ( mockedContractFactory . getSecurityTokenContract ( expectedSecurityTokenAddress ) ) . once ( ) ;
390
+ verify ( mockedSecurityTokenDecimalsMethod . callAsync ( ) ) . once ( ) ;
391
+ verify ( mockedSecurityTokenContract . decimals ) . once ( ) ;
234
392
} ) ;
235
393
} ) ;
236
394
0 commit comments