@@ -872,6 +872,210 @@ describe('BlacklistTransferManagerWrapper', () => {
872
872
} ) ;
873
873
} ) ;
874
874
875
+ describe ( 'addInvestorToBlacklist' , ( ) => {
876
+ test ( 'should call addInvestorToBlacklist' , async ( ) => {
877
+ const expectedOwnerResult = '0x8888888888888888888888888888888888888888' ;
878
+ const expectedBlacklistInvestorAddress = '0x4444444444444444444444444444444444444444' ;
879
+ const blacklistName = 'Blacklist1' ;
880
+ const expectedStartTime = dateToBigNumber ( new Date ( 2030 , 1 ) ) ;
881
+ const expectedEndTime = dateToBigNumber ( new Date ( 2031 , 1 ) ) ;
882
+ const expectedRepeatPeriodTime = new BigNumber ( 366 ) ;
883
+ const expectedGetBlacklistResult = [ expectedStartTime , expectedEndTime , expectedRepeatPeriodTime ] ;
884
+
885
+ // Security Token Address expected
886
+ const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333' ;
887
+ // Setup get Security Token Address
888
+ const mockedGetSecurityTokenAddressMethod = mock ( MockedCallMethod ) ;
889
+ when ( mockedContract . securityToken ) . thenReturn ( instance ( mockedGetSecurityTokenAddressMethod ) ) ;
890
+ when ( mockedGetSecurityTokenAddressMethod . callAsync ( ) ) . thenResolve ( expectedSecurityTokenAddress ) ;
891
+ when ( mockedContractFactory . getSecurityTokenContract ( expectedSecurityTokenAddress ) ) . thenResolve (
892
+ instance ( mockedSecurityTokenContract ) ,
893
+ ) ;
894
+
895
+ const mockedSecurityTokenOwnerMethod = mock ( MockedCallMethod ) ;
896
+ when ( mockedSecurityTokenOwnerMethod . callAsync ( ) ) . thenResolve ( expectedOwnerResult ) ;
897
+ when ( mockedSecurityTokenContract . owner ) . thenReturn ( instance ( mockedSecurityTokenOwnerMethod ) ) ;
898
+
899
+ // Mock web3 wrapper owner
900
+ when ( mockedWrapper . getAvailableAddressesAsync ( ) ) . thenResolve ( [ expectedOwnerResult ] ) ;
901
+
902
+ // Mocked method
903
+ const mockedBlacklistsMethod = mock ( MockedCallMethod ) ;
904
+ // Stub the method
905
+ when ( mockedContract . blacklists ) . thenReturn ( instance ( mockedBlacklistsMethod ) ) ;
906
+ // Stub the request
907
+ when ( mockedBlacklistsMethod . callAsync ( objectContaining ( stringToBytes32 ( blacklistName ) ) ) ) . thenResolve (
908
+ expectedGetBlacklistResult ,
909
+ ) ;
910
+
911
+ const expectedGetBlacklistNamesToUserResult = stringArrayToBytes32Array ( [ 'Blacklist2' , 'Blacklist3' ] ) ;
912
+ const mockedGetBlacklistNamesToUserParams = {
913
+ user : expectedBlacklistInvestorAddress ,
914
+ } ;
915
+ // Mocked method
916
+ const mockedGetBlacklistNamesToUserMethod = mock ( MockedCallMethod ) ;
917
+ // Stub the method
918
+ when ( mockedContract . getBlacklistNamesToUser ) . thenReturn ( instance ( mockedGetBlacklistNamesToUserMethod ) ) ;
919
+ // Stub the request
920
+ when ( mockedGetBlacklistNamesToUserMethod . callAsync ( mockedGetBlacklistNamesToUserParams . user ) ) . thenResolve (
921
+ expectedGetBlacklistNamesToUserResult ,
922
+ ) ;
923
+
924
+ const mockedParams = {
925
+ userAddress : expectedBlacklistInvestorAddress ,
926
+ blacklistName,
927
+ txData : { } ,
928
+ safetyFactor : 10 ,
929
+ } ;
930
+ const expectedResult = getMockedPolyResponse ( ) ;
931
+ // Mocked method
932
+ const mockedMethod = mock ( MockedSendMethod ) ;
933
+ // Stub the method
934
+ when ( mockedContract . addInvestorToBlacklist ) . thenReturn ( instance ( mockedMethod ) ) ;
935
+ // Stub the request
936
+ when (
937
+ mockedMethod . sendTransactionAsync (
938
+ mockedParams . userAddress ,
939
+ objectContaining ( stringToBytes32 ( mockedParams . blacklistName ) ) ,
940
+ mockedParams . txData ,
941
+ mockedParams . safetyFactor ,
942
+ ) ,
943
+ ) . thenResolve ( expectedResult ) ;
944
+
945
+ // Real call
946
+ const result = await target . addInvestorToBlacklist ( mockedParams ) ;
947
+
948
+ // Result expectation
949
+ expect ( result ) . toBe ( expectedResult ) ;
950
+ // Verifications
951
+ verify ( mockedContract . addInvestorToBlacklist ) . once ( ) ;
952
+ verify (
953
+ mockedMethod . sendTransactionAsync (
954
+ mockedParams . userAddress ,
955
+ objectContaining ( stringToBytes32 ( mockedParams . blacklistName ) ) ,
956
+ mockedParams . txData ,
957
+ mockedParams . safetyFactor ,
958
+ ) ,
959
+ ) . once ( ) ;
960
+ verify ( mockedSecurityTokenOwnerMethod . callAsync ( ) ) . once ( ) ;
961
+ verify ( mockedSecurityTokenContract . owner ) . once ( ) ;
962
+ verify ( mockedContract . securityToken ) . once ( ) ;
963
+ verify ( mockedGetSecurityTokenAddressMethod . callAsync ( ) ) . once ( ) ;
964
+ verify ( mockedContractFactory . getSecurityTokenContract ( expectedSecurityTokenAddress ) ) . once ( ) ;
965
+ verify ( mockedWrapper . getAvailableAddressesAsync ( ) ) . once ( ) ;
966
+ verify ( mockedContract . blacklists ) . once ( ) ;
967
+ verify ( mockedBlacklistsMethod . callAsync ( objectContaining ( stringToBytes32 ( blacklistName ) ) ) ) . once ( ) ;
968
+ verify ( mockedContract . getBlacklistNamesToUser ) . once ( ) ;
969
+ verify ( mockedGetBlacklistNamesToUserMethod . callAsync ( mockedGetBlacklistNamesToUserParams . user ) ) . once ( ) ;
970
+ } ) ;
971
+ } ) ;
972
+
973
+ describe ( 'addInvestorToBlacklistMulti' , ( ) => {
974
+ test ( 'should call addInvestorToBlacklistMulti' , async ( ) => {
975
+ const expectedOwnerResult = '0x8888888888888888888888888888888888888888' ;
976
+ const expectedBlacklistInvestorAddresses = [
977
+ '0x0123456789012345678901234567890123456789' ,
978
+ '0x2222222222222222222222222222222222222222' ,
979
+ '0x9999999999999999999999999999999999999999' ,
980
+ ] ;
981
+ const blacklistName = 'Blacklist1' ;
982
+ const expectedStartTime = dateToBigNumber ( new Date ( 2030 , 1 ) ) ;
983
+ const expectedEndTime = dateToBigNumber ( new Date ( 2031 , 1 ) ) ;
984
+ const expectedRepeatPeriodTime = new BigNumber ( 366 ) ;
985
+ const expectedGetBlacklistResult = [ expectedStartTime , expectedEndTime , expectedRepeatPeriodTime ] ;
986
+
987
+ // Security Token Address expected
988
+ const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333' ;
989
+ // Setup get Security Token Address
990
+ const mockedGetSecurityTokenAddressMethod = mock ( MockedCallMethod ) ;
991
+ when ( mockedContract . securityToken ) . thenReturn ( instance ( mockedGetSecurityTokenAddressMethod ) ) ;
992
+ when ( mockedGetSecurityTokenAddressMethod . callAsync ( ) ) . thenResolve ( expectedSecurityTokenAddress ) ;
993
+ when ( mockedContractFactory . getSecurityTokenContract ( expectedSecurityTokenAddress ) ) . thenResolve (
994
+ instance ( mockedSecurityTokenContract ) ,
995
+ ) ;
996
+
997
+ const mockedSecurityTokenOwnerMethod = mock ( MockedCallMethod ) ;
998
+ when ( mockedSecurityTokenOwnerMethod . callAsync ( ) ) . thenResolve ( expectedOwnerResult ) ;
999
+ when ( mockedSecurityTokenContract . owner ) . thenReturn ( instance ( mockedSecurityTokenOwnerMethod ) ) ;
1000
+
1001
+ // Mock web3 wrapper owner
1002
+ when ( mockedWrapper . getAvailableAddressesAsync ( ) ) . thenResolve ( [ expectedOwnerResult ] ) ;
1003
+
1004
+ // Mocked method
1005
+ const mockedBlacklistsMethod = mock ( MockedCallMethod ) ;
1006
+ // Stub the method
1007
+ when ( mockedContract . blacklists ) . thenReturn ( instance ( mockedBlacklistsMethod ) ) ;
1008
+
1009
+ when ( mockedBlacklistsMethod . callAsync ( objectContaining ( stringToBytes32 ( blacklistName ) ) ) ) . thenResolve (
1010
+ expectedGetBlacklistResult ,
1011
+ ) ;
1012
+
1013
+ const expectedGetBlacklistNamesToUserResult = stringArrayToBytes32Array ( [ 'Blacklist2' , 'Blacklist3' ] ) ;
1014
+ // Mocked method
1015
+ const mockedGetBlacklistNamesToUserMethod = mock ( MockedCallMethod ) ;
1016
+ // Stub the method
1017
+ when ( mockedContract . getBlacklistNamesToUser ) . thenReturn ( instance ( mockedGetBlacklistNamesToUserMethod ) ) ;
1018
+ // Stub the request
1019
+
1020
+ for ( let i = 0 ; i < expectedBlacklistInvestorAddresses . length ; i += 1 ) {
1021
+ when ( mockedGetBlacklistNamesToUserMethod . callAsync ( expectedBlacklistInvestorAddresses [ i ] ) ) . thenResolve (
1022
+ expectedGetBlacklistNamesToUserResult ,
1023
+ ) ;
1024
+ }
1025
+
1026
+ const mockedParams = {
1027
+ userAddresses : expectedBlacklistInvestorAddresses ,
1028
+ blacklistName,
1029
+ txData : { } ,
1030
+ safetyFactor : 10 ,
1031
+ } ;
1032
+ const expectedResult = getMockedPolyResponse ( ) ;
1033
+ // Mocked method
1034
+ const mockedMethod = mock ( MockedSendMethod ) ;
1035
+ // Stub the method
1036
+ when ( mockedContract . addInvestorToBlacklistMulti ) . thenReturn ( instance ( mockedMethod ) ) ;
1037
+ // Stub the request
1038
+ when (
1039
+ mockedMethod . sendTransactionAsync (
1040
+ mockedParams . userAddresses ,
1041
+ objectContaining ( stringToBytes32 ( mockedParams . blacklistName ) ) ,
1042
+ mockedParams . txData ,
1043
+ mockedParams . safetyFactor ,
1044
+ ) ,
1045
+ ) . thenResolve ( expectedResult ) ;
1046
+
1047
+ // Real call
1048
+ const result = await target . addInvestorToBlacklistMulti ( mockedParams ) ;
1049
+
1050
+ // Result expectation
1051
+ expect ( result ) . toBe ( expectedResult ) ;
1052
+ // Verifications
1053
+ verify ( mockedContract . addInvestorToBlacklistMulti ) . once ( ) ;
1054
+ verify (
1055
+ mockedMethod . sendTransactionAsync (
1056
+ mockedParams . userAddresses ,
1057
+ objectContaining ( stringToBytes32 ( mockedParams . blacklistName ) ) ,
1058
+ mockedParams . txData ,
1059
+ mockedParams . safetyFactor ,
1060
+ ) ,
1061
+ ) . once ( ) ;
1062
+ verify ( mockedSecurityTokenOwnerMethod . callAsync ( ) ) . once ( ) ;
1063
+ verify ( mockedSecurityTokenContract . owner ) . once ( ) ;
1064
+ verify ( mockedContract . securityToken ) . once ( ) ;
1065
+ verify ( mockedGetSecurityTokenAddressMethod . callAsync ( ) ) . once ( ) ;
1066
+ verify ( mockedContractFactory . getSecurityTokenContract ( expectedSecurityTokenAddress ) ) . once ( ) ;
1067
+ verify ( mockedWrapper . getAvailableAddressesAsync ( ) ) . once ( ) ;
1068
+ verify ( mockedContract . blacklists ) . times ( expectedBlacklistInvestorAddresses . length ) ;
1069
+ verify ( mockedBlacklistsMethod . callAsync ( objectContaining ( stringToBytes32 ( blacklistName ) ) ) ) . times (
1070
+ expectedBlacklistInvestorAddresses . length ,
1071
+ ) ;
1072
+ verify ( mockedContract . getBlacklistNamesToUser ) . times ( expectedBlacklistInvestorAddresses . length ) ;
1073
+ for ( let i = 0 ; i < expectedBlacklistInvestorAddresses . length ; i += 1 ) {
1074
+ verify ( mockedGetBlacklistNamesToUserMethod . callAsync ( expectedBlacklistInvestorAddresses [ i ] ) ) . once ( ) ;
1075
+ }
1076
+ } ) ;
1077
+ } ) ;
1078
+
875
1079
describe ( 'getListOfAddresses' , ( ) => {
876
1080
test . todo ( 'should fail as blacklist name is an empty string' ) ;
877
1081
0 commit comments