@@ -12,8 +12,14 @@ import BlacklistTransferManagerWrapper from '../blacklist_transfer_manager_wrapp
12
12
import ContractFactory from '../../../../factories/contractFactory' ;
13
13
import ModuleWrapper from '../../module_wrapper' ;
14
14
import {
15
+ bytes32ArrayToStringArray , dateToBigNumber ,
16
+ parsePermBytes32Value ,
17
+ stringArrayToBytes32Array ,
18
+ stringToBytes32 ,
15
19
valueToWei ,
20
+ weiToValue ,
16
21
} from '../../../../utils/convert' ;
22
+ import { Partition , Perm } from '../../../../types' ;
17
23
18
24
describe ( 'BlacklistTransferManagerWrapper' , ( ) => {
19
25
let target : BlacklistTransferManagerWrapper ;
@@ -196,7 +202,6 @@ describe('BlacklistTransferManagerWrapper', () => {
196
202
} ) ;
197
203
} ) ;
198
204
199
-
200
205
describe ( 'verifyTransfer' , ( ) => {
201
206
test ( 'should verify Transfer' , async ( ) => {
202
207
const statusCode = new BigNumber ( 2 ) ;
@@ -259,6 +264,163 @@ describe('BlacklistTransferManagerWrapper', () => {
259
264
} ) ;
260
265
} ) ;
261
266
267
+ describe ( 'getListOfAddresses' , ( ) => {
268
+ test . todo ( 'should fail as blacklist name is an empty string' ) ;
269
+
270
+ test ( 'should call to getListOfAddresses' , async ( ) => {
271
+ const expectedResult = [
272
+ '0x8888888888888888888888888888888888888888' ,
273
+ '0x9999999999999999999999999999999999999999' ,
274
+ ] ;
275
+ const mockedParams = {
276
+ blacklistName : 'Blacklist1' ,
277
+ } ;
278
+
279
+ // Mocked method
280
+ const mockedMethod = mock ( MockedCallMethod ) ;
281
+ // Stub the method
282
+ when ( mockedContract . getListOfAddresses ) . thenReturn ( instance ( mockedMethod ) ) ;
283
+ // Stub the request
284
+ when ( mockedMethod . callAsync ( objectContaining ( stringToBytes32 ( mockedParams . blacklistName ) ) ) ) . thenResolve (
285
+ expectedResult ,
286
+ ) ;
287
+
288
+ // Real call
289
+ const result = await target . getListOfAddresses ( mockedParams ) ;
290
+ // Result expectation
291
+ expect ( result ) . toEqual ( expectedResult ) ;
292
+
293
+ // Verifications
294
+ verify ( mockedContract . getListOfAddresses ) . once ( ) ;
295
+ verify ( mockedMethod . callAsync ( objectContaining ( stringToBytes32 ( mockedParams . blacklistName ) ) ) ) . once ( ) ;
296
+ } ) ;
297
+ } ) ;
298
+
299
+ describe ( 'getBlacklistNamesToUser' , ( ) => {
300
+ test ( 'should call to getBlacklistNamesToUser' , async ( ) => {
301
+ const expectedResult = stringArrayToBytes32Array ( [ 'Blacklist1' , 'Blacklist2' ] ) ;
302
+ const mockedParams = {
303
+ user : '0x8888888888888888888888888888888888888888' ,
304
+ } ;
305
+ // Mocked method
306
+ const mockedMethod = mock ( MockedCallMethod ) ;
307
+ // Stub the method
308
+ when ( mockedContract . getBlacklistNamesToUser ) . thenReturn ( instance ( mockedMethod ) ) ;
309
+ // Stub the request
310
+ when ( mockedMethod . callAsync ( mockedParams . user ) ) . thenResolve ( expectedResult ) ;
311
+
312
+ // Real call
313
+ const result = await target . getBlacklistNamesToUser ( mockedParams ) ;
314
+ // Result expectation
315
+ expect ( result ) . toEqual ( bytes32ArrayToStringArray ( expectedResult ) ) ;
316
+
317
+ // Verifications
318
+ verify ( mockedContract . getBlacklistNamesToUser ) . once ( ) ;
319
+ verify ( mockedMethod . callAsync ( mockedParams . user ) ) . once ( ) ;
320
+ } ) ;
321
+ } ) ;
322
+
323
+ describe ( 'getAllBlacklists' , ( ) => {
324
+ test ( 'should call to getAllBlacklists' , async ( ) => {
325
+ const expectedResult = stringArrayToBytes32Array ( [ 'Blacklist1' , 'Blacklist2' ] ) ;
326
+
327
+ // Mocked method
328
+ const mockedMethod = mock ( MockedCallMethod ) ;
329
+ // Stub the method
330
+ when ( mockedContract . getAllBlacklists ) . thenReturn ( instance ( mockedMethod ) ) ;
331
+ // Stub the request
332
+ when ( mockedMethod . callAsync ( ) ) . thenResolve ( expectedResult ) ;
333
+
334
+ // Real call
335
+ const result = await target . getAllBlacklists ( ) ;
336
+ // Result expectation
337
+ expect ( result ) . toEqual ( bytes32ArrayToStringArray ( expectedResult ) ) ;
338
+
339
+ // Verifications
340
+ verify ( mockedContract . getAllBlacklists ) . once ( ) ;
341
+ verify ( mockedMethod . callAsync ( ) ) . once ( ) ;
342
+ } ) ;
343
+ } ) ;
344
+
345
+ describe ( 'getTokensByPartition' , ( ) => {
346
+ test ( 'should call to getTokensByPartition' , async ( ) => {
347
+ const expectedDecimalsResult = new BigNumber ( 18 ) ;
348
+ const expectedResult = valueToWei ( new BigNumber ( 100 ) , expectedDecimalsResult ) ;
349
+ const mockedParams = {
350
+ partition : Partition . Unlocked ,
351
+ tokenHolder : '0x8888888888888888888888888888888888888888' ,
352
+ additionalBalance : new BigNumber ( 10 ) ,
353
+ } ;
354
+
355
+ // Security Token Address expected
356
+ const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333' ;
357
+ // Setup get Security Token Address
358
+ const mockedGetSecurityTokenAddressMethod = mock ( MockedCallMethod ) ;
359
+ when ( mockedContract . securityToken ) . thenReturn ( instance ( mockedGetSecurityTokenAddressMethod ) ) ;
360
+ when ( mockedGetSecurityTokenAddressMethod . callAsync ( ) ) . thenResolve ( expectedSecurityTokenAddress ) ;
361
+ when ( mockedContractFactory . getSecurityTokenContract ( expectedSecurityTokenAddress ) ) . thenResolve (
362
+ instance ( mockedSecurityTokenContract ) ,
363
+ ) ;
364
+ const mockedSecurityTokenDecimalsMethod = mock ( MockedCallMethod ) ;
365
+ when ( mockedSecurityTokenDecimalsMethod . callAsync ( ) ) . thenResolve ( expectedDecimalsResult ) ;
366
+ when ( mockedSecurityTokenContract . decimals ) . thenReturn ( instance ( mockedSecurityTokenDecimalsMethod ) ) ;
367
+
368
+ // Mocked method
369
+ const mockedMethod = mock ( MockedCallMethod ) ;
370
+ // Stub the method
371
+ when ( mockedContract . getTokensByPartition ) . thenReturn ( instance ( mockedMethod ) ) ;
372
+ // Stub the request
373
+ when (
374
+ mockedMethod . callAsync (
375
+ mockedParams . partition ,
376
+ mockedParams . tokenHolder ,
377
+ objectContaining ( valueToWei ( mockedParams . additionalBalance , expectedDecimalsResult ) ) ,
378
+ ) ,
379
+ ) . thenResolve ( expectedResult ) ;
380
+
381
+ // Real call
382
+ const result = await target . getTokensByPartition ( mockedParams ) ;
383
+ // Result expectation
384
+ expect ( result ) . toEqual ( weiToValue ( expectedResult , expectedDecimalsResult ) ) ;
385
+
386
+ // Verifications
387
+ verify ( mockedContract . getTokensByPartition ) . once ( ) ;
388
+ verify (
389
+ mockedMethod . callAsync (
390
+ mockedParams . partition ,
391
+ mockedParams . tokenHolder ,
392
+ objectContaining ( valueToWei ( mockedParams . additionalBalance , expectedDecimalsResult ) ) ,
393
+ ) ,
394
+ ) . once ( ) ;
395
+ verify ( mockedContract . securityToken ) . once ( ) ;
396
+ verify ( mockedGetSecurityTokenAddressMethod . callAsync ( ) ) . once ( ) ;
397
+ verify ( mockedContractFactory . getSecurityTokenContract ( expectedSecurityTokenAddress ) ) . once ( ) ;
398
+ verify ( mockedSecurityTokenDecimalsMethod . callAsync ( ) ) . once ( ) ;
399
+ verify ( mockedSecurityTokenContract . decimals ) . once ( ) ;
400
+ } ) ;
401
+ } ) ;
402
+
403
+ describe ( 'getPermissions' , ( ) => {
404
+ test ( 'should call to getPermissions' , async ( ) => {
405
+ const expectedResult = stringArrayToBytes32Array ( [ Perm . Admin ] ) ;
406
+
407
+ // Mocked method
408
+ const mockedMethod = mock ( MockedCallMethod ) ;
409
+ // Stub the method
410
+ when ( mockedContract . getPermissions ) . thenReturn ( instance ( mockedMethod ) ) ;
411
+ // Stub the request
412
+ when ( mockedMethod . callAsync ( ) ) . thenResolve ( expectedResult ) ;
413
+
414
+ // Real call
415
+ const result = await target . getPermissions ( ) ;
416
+ // Result expectation
417
+ expect ( result ) . toEqual ( expectedResult . map ( parsePermBytes32Value ) ) ;
418
+ // Verifications
419
+ verify ( mockedContract . getPermissions ) . once ( ) ;
420
+ verify ( mockedMethod . callAsync ( ) ) . once ( ) ;
421
+ } ) ;
422
+ } ) ;
423
+
262
424
describe ( 'SubscribeAsync' , ( ) => {
263
425
test ( 'should throw as eventName does not belong to BlacklistTransferManager' , async ( ) => {
264
426
// Mocked parameters
0 commit comments