@@ -24,6 +24,8 @@ import assert from 'assert';
24
24
import { mockNetwork } from '../../../tests/mock-network' ;
25
25
import { buildInfuraNetworkClientConfiguration } from '../../network-controller/tests/helpers' ;
26
26
import type {
27
+ AssetsContractControllerActions ,
28
+ AssetsContractControllerEvents ,
27
29
AllowedActions as AssetsContractAllowedActions ,
28
30
AllowedEvents as AssetsContractAllowedEvents ,
29
31
} from './AssetsContractController' ;
@@ -75,8 +77,12 @@ async function setupAssetContractControllers({
75
77
let provider : Provider ;
76
78
77
79
const controllerMessenger = new ControllerMessenger <
78
- NetworkControllerActions | AssetsContractAllowedActions ,
79
- NetworkControllerEvents | AssetsContractAllowedEvents
80
+ | NetworkControllerActions
81
+ | AssetsContractControllerActions
82
+ | AssetsContractAllowedActions ,
83
+ | NetworkControllerEvents
84
+ | AssetsContractControllerEvents
85
+ | AssetsContractAllowedEvents
80
86
> ( ) ;
81
87
const networkMessenger = controllerMessenger . getRestricted ( {
82
88
name : 'NetworkController' ,
@@ -227,10 +233,9 @@ describe('AssetsContractController', () => {
227
233
const { assetsContract, messenger } = await setupAssetContractControllers ( ) ;
228
234
assetsContract . provider = undefined ;
229
235
await expect (
230
- assetsContract . getERC20BalanceOf (
231
- ERC20_UNI_ADDRESS ,
232
- TEST_ACCOUNT_PUBLIC_ADDRESS ,
233
- ) ,
236
+ messenger
237
+ . call ( 'AssetsContractController:getERC20Standard' )
238
+ . getBalanceOf ( ERC20_UNI_ADDRESS , TEST_ACCOUNT_PUBLIC_ADDRESS ) ,
234
239
) . rejects . toThrow ( MISSING_PROVIDER_ERROR ) ;
235
240
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
236
241
} ) ;
@@ -239,7 +244,9 @@ describe('AssetsContractController', () => {
239
244
const { assetsContract, messenger } = await setupAssetContractControllers ( ) ;
240
245
assetsContract . provider = undefined ;
241
246
await expect (
242
- assetsContract . getERC20TokenDecimals ( ERC20_UNI_ADDRESS ) ,
247
+ messenger
248
+ . call ( 'AssetsContractController:getERC20Standard' )
249
+ . getTokenDecimals ( ERC20_UNI_ADDRESS ) ,
243
250
) . rejects . toThrow ( MISSING_PROVIDER_ERROR ) ;
244
251
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
245
252
} ) ;
@@ -285,14 +292,15 @@ describe('AssetsContractController', () => {
285
292
} ,
286
293
] ,
287
294
} ) ;
288
- const UNIBalance = await assetsContract . getERC20BalanceOf (
289
- ERC20_UNI_ADDRESS ,
290
- TEST_ACCOUNT_PUBLIC_ADDRESS ,
291
- ) ;
292
- const UNINoBalance = await assetsContract . getERC20BalanceOf (
293
- ERC20_UNI_ADDRESS ,
294
- '0x202637dAAEfbd7f131f90338a4A6c69F6Cd5CE91' ,
295
- ) ;
295
+ const UNIBalance = await messenger
296
+ . call ( 'AssetsContractController:getERC20Standard' )
297
+ . getBalanceOf ( ERC20_UNI_ADDRESS , TEST_ACCOUNT_PUBLIC_ADDRESS ) ;
298
+ const UNINoBalance = await messenger
299
+ . call ( 'AssetsContractController:getERC20Standard' )
300
+ . getBalanceOf (
301
+ ERC20_UNI_ADDRESS ,
302
+ '0x202637dAAEfbd7f131f90338a4A6c69F6Cd5CE91' ,
303
+ ) ;
296
304
expect ( UNIBalance . toString ( 16 ) ) . not . toBe ( '0' ) ;
297
305
expect ( UNINoBalance . toString ( 16 ) ) . toBe ( '0' ) ;
298
306
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
@@ -323,11 +331,13 @@ describe('AssetsContractController', () => {
323
331
} ,
324
332
] ,
325
333
} ) ;
326
- const tokenId = await assetsContract . getERC721NftTokenId (
327
- ERC721_GODS_ADDRESS ,
328
- '0x9a90bd8d1149a88b42a99cf62215ad955d6f498a' ,
329
- 0 ,
330
- ) ;
334
+ const tokenId = await messenger
335
+ . call ( 'AssetsContractController:getERC721Standard' )
336
+ . getNftTokenId (
337
+ ERC721_GODS_ADDRESS ,
338
+ '0x9a90bd8d1149a88b42a99cf62215ad955d6f498a' ,
339
+ 0 ,
340
+ ) ;
331
341
expect ( tokenId ) . not . toBe ( 0 ) ;
332
342
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
333
343
} ) ;
@@ -336,7 +346,8 @@ describe('AssetsContractController', () => {
336
346
const { assetsContract, messenger } = await setupAssetContractControllers ( ) ;
337
347
assetsContract . provider = undefined ;
338
348
await expect (
339
- assetsContract . getTokenStandardAndDetails (
349
+ messenger . call (
350
+ 'AssetsContractController:getTokenStandardAndDetails' ,
340
351
ERC20_UNI_ADDRESS ,
341
352
TEST_ACCOUNT_PUBLIC_ADDRESS ,
342
353
) ,
@@ -350,7 +361,8 @@ describe('AssetsContractController', () => {
350
361
assetsContract . provider = provider ;
351
362
const error = 'Unable to determine contract standard' ;
352
363
await expect (
353
- assetsContract . getTokenStandardAndDetails (
364
+ messenger . call (
365
+ 'AssetsContractController:getTokenStandardAndDetails' ,
354
366
'BaDeRc20AdDrEsS' ,
355
367
TEST_ACCOUNT_PUBLIC_ADDRESS ,
356
368
) ,
@@ -415,7 +427,8 @@ describe('AssetsContractController', () => {
415
427
} ,
416
428
] ,
417
429
} ) ;
418
- const standardAndDetails = await assetsContract . getTokenStandardAndDetails (
430
+ const standardAndDetails = await messenger . call (
431
+ 'AssetsContractController:getTokenStandardAndDetails' ,
419
432
ERC721_GODS_ADDRESS ,
420
433
TEST_ACCOUNT_PUBLIC_ADDRESS ,
421
434
) ;
@@ -496,7 +509,8 @@ describe('AssetsContractController', () => {
496
509
} ,
497
510
] ,
498
511
} ) ;
499
- const standardAndDetails = await assetsContract . getTokenStandardAndDetails (
512
+ const standardAndDetails = await messenger . call (
513
+ 'AssetsContractController:getTokenStandardAndDetails' ,
500
514
ERC1155_ADDRESS ,
501
515
TEST_ACCOUNT_PUBLIC_ADDRESS ,
502
516
) ;
@@ -597,7 +611,8 @@ describe('AssetsContractController', () => {
597
611
} ,
598
612
] ,
599
613
} ) ;
600
- const standardAndDetails = await assetsContract . getTokenStandardAndDetails (
614
+ const standardAndDetails = await messenger . call (
615
+ 'AssetsContractController:getTokenStandardAndDetails' ,
601
616
ERC20_UNI_ADDRESS ,
602
617
TEST_ACCOUNT_PUBLIC_ADDRESS ,
603
618
) ;
@@ -646,10 +661,9 @@ describe('AssetsContractController', () => {
646
661
} ,
647
662
] ,
648
663
} ) ;
649
- const tokenId = await assetsContract . getERC721TokenURI (
650
- ERC721_GODS_ADDRESS ,
651
- '0' ,
652
- ) ;
664
+ const tokenId = await messenger
665
+ . call ( 'AssetsContractController:getERC721Standard' )
666
+ . getTokenURI ( ERC721_GODS_ADDRESS , '0' ) ;
653
667
expect ( tokenId ) . toBe ( 'https://api.godsunchained.com/card/0' ) ;
654
668
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
655
669
} ) ;
@@ -699,10 +713,9 @@ describe('AssetsContractController', () => {
699
713
} ,
700
714
] ,
701
715
} ) ;
702
- const uri = await assetsContract . getERC721TokenURI (
703
- '0x0000000000000000000000000000000000000000' ,
704
- '0' ,
705
- ) ;
716
+ const uri = await messenger
717
+ . call ( 'AssetsContractController:getERC721Standard' )
718
+ . getTokenURI ( '0x0000000000000000000000000000000000000000' , '0' ) ;
706
719
expect ( uri ) . toBe ( 'https://api.godsunchained.com/card/0' ) ;
707
720
expect ( errorLogSpy ) . toHaveBeenCalledTimes ( 1 ) ;
708
721
expect ( errorLogSpy . mock . calls ) . toContainEqual ( [
@@ -737,7 +750,9 @@ describe('AssetsContractController', () => {
737
750
} ,
738
751
] ,
739
752
} ) ;
740
- const name = await assetsContract . getERC721AssetName ( ERC721_GODS_ADDRESS ) ;
753
+ const name = await messenger
754
+ . call ( 'AssetsContractController:getERC721Standard' )
755
+ . getAssetName ( ERC721_GODS_ADDRESS ) ;
741
756
expect ( name ) . toBe ( 'Gods Unchained' ) ;
742
757
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
743
758
} ) ;
@@ -767,17 +782,19 @@ describe('AssetsContractController', () => {
767
782
} ,
768
783
] ,
769
784
} ) ;
770
- const symbol = await assetsContract . getERC721AssetSymbol (
771
- ERC721_GODS_ADDRESS ,
772
- ) ;
785
+ const symbol = await messenger
786
+ . call ( 'AssetsContractController:getERC721Standard' )
787
+ . getAssetSymbol ( ERC721_GODS_ADDRESS ) ;
773
788
expect ( symbol ) . toBe ( 'GODS' ) ;
774
789
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
775
790
} ) ;
776
791
777
792
it ( 'should throw missing provider error when getting ERC-721 NFT symbol when missing provider' , async ( ) => {
778
- const { assetsContract , messenger } = await setupAssetContractControllers ( ) ;
793
+ const { messenger } = await setupAssetContractControllers ( ) ;
779
794
await expect (
780
- assetsContract . getERC721AssetSymbol ( ERC721_GODS_ADDRESS ) ,
795
+ messenger
796
+ . call ( 'AssetsContractController:getERC721Standard' )
797
+ . getAssetSymbol ( ERC721_GODS_ADDRESS ) ,
781
798
) . rejects . toThrow ( MISSING_PROVIDER_ERROR ) ;
782
799
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
783
800
} ) ;
@@ -807,9 +824,9 @@ describe('AssetsContractController', () => {
807
824
} ,
808
825
] ,
809
826
} ) ;
810
- const decimals = await assetsContract . getERC20TokenDecimals (
811
- ERC20_SAI_ADDRESS ,
812
- ) ;
827
+ const decimals = await messenger
828
+ . call ( 'AssetsContractController:getERC20Standard' )
829
+ . getTokenDecimals ( ERC20_SAI_ADDRESS ) ;
813
830
expect ( Number ( decimals ) ) . toBe ( 18 ) ;
814
831
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
815
832
} ) ;
@@ -840,7 +857,9 @@ describe('AssetsContractController', () => {
840
857
] ,
841
858
} ) ;
842
859
843
- const name = await assetsContract . getERC20TokenName ( ERC20_DAI_ADDRESS ) ;
860
+ const name = await messenger
861
+ . call ( 'AssetsContractController:getERC20Standard' )
862
+ . getTokenName ( ERC20_DAI_ADDRESS ) ;
844
863
845
864
expect ( name ) . toBe ( 'Dai Stablecoin' ) ;
846
865
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
@@ -871,18 +890,19 @@ describe('AssetsContractController', () => {
871
890
} ,
872
891
] ,
873
892
} ) ;
874
- const tokenId = await assetsContract . getERC721OwnerOf (
875
- ERC721_GODS_ADDRESS ,
876
- '148332' ,
877
- ) ;
893
+ const tokenId = await messenger
894
+ . call ( 'AssetsContractController:getERC721Standard' )
895
+ . getOwnerOf ( ERC721_GODS_ADDRESS , '148332' ) ;
878
896
expect ( tokenId ) . not . toBe ( '' ) ;
879
897
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
880
898
} ) ;
881
899
882
900
it ( 'should throw missing provider error when getting ERC-721 NFT ownership' , async ( ) => {
883
- const { assetsContract , messenger } = await setupAssetContractControllers ( ) ;
901
+ const { messenger } = await setupAssetContractControllers ( ) ;
884
902
await expect (
885
- assetsContract . getERC721OwnerOf ( ERC721_GODS_ADDRESS , '148332' ) ,
903
+ messenger
904
+ . call ( 'AssetsContractController:getERC721Standard' )
905
+ . getOwnerOf ( ERC721_GODS_ADDRESS , '148332' ) ,
886
906
) . rejects . toThrow ( MISSING_PROVIDER_ERROR ) ;
887
907
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
888
908
} ) ;
@@ -912,7 +932,8 @@ describe('AssetsContractController', () => {
912
932
} ,
913
933
] ,
914
934
} ) ;
915
- const balances = await assetsContract . getBalancesInSingleCall (
935
+ const balances = await messenger . call (
936
+ 'AssetsContractController:getBalancesInSingleCall' ,
916
937
ERC20_SAI_ADDRESS ,
917
938
[ ERC20_SAI_ADDRESS ] ,
918
939
) ;
@@ -1078,15 +1099,17 @@ describe('AssetsContractController', () => {
1078
1099
] ,
1079
1100
} ) ;
1080
1101
1081
- const balances = await assetsContract . getBalancesInSingleCall (
1102
+ const balances = await messenger . call (
1103
+ 'AssetsContractController:getBalancesInSingleCall' ,
1082
1104
ERC20_SAI_ADDRESS ,
1083
1105
[ ERC20_SAI_ADDRESS ] ,
1084
1106
) ;
1085
1107
expect ( balances [ ERC20_SAI_ADDRESS ] ) . toBeDefined ( ) ;
1086
1108
1087
1109
await network . setActiveNetwork ( NetworkType . sepolia ) ;
1088
1110
1089
- const noBalances = await assetsContract . getBalancesInSingleCall (
1111
+ const noBalances = await messenger . call (
1112
+ 'AssetsContractController:getBalancesInSingleCall' ,
1090
1113
ERC20_SAI_ADDRESS ,
1091
1114
[ ERC20_SAI_ADDRESS ] ,
1092
1115
) ;
@@ -1098,13 +1121,15 @@ describe('AssetsContractController', () => {
1098
1121
const { assetsContract, messenger } = await setupAssetContractControllers ( ) ;
1099
1122
assetsContract . provider = undefined ;
1100
1123
await expect (
1101
- assetsContract . transferSingleERC1155 (
1102
- ERC1155_ADDRESS ,
1103
- TEST_ACCOUNT_PUBLIC_ADDRESS ,
1104
- TEST_ACCOUNT_PUBLIC_ADDRESS ,
1105
- ERC1155_ID ,
1106
- '1' ,
1107
- ) ,
1124
+ messenger
1125
+ . call ( 'AssetsContractController:getERC1155Standard' )
1126
+ . transferSingle (
1127
+ ERC1155_ADDRESS ,
1128
+ TEST_ACCOUNT_PUBLIC_ADDRESS ,
1129
+ TEST_ACCOUNT_PUBLIC_ADDRESS ,
1130
+ ERC1155_ID ,
1131
+ '1' ,
1132
+ ) ,
1108
1133
) . rejects . toThrow ( MISSING_PROVIDER_ERROR ) ;
1109
1134
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
1110
1135
} ) ;
@@ -1135,13 +1160,15 @@ describe('AssetsContractController', () => {
1135
1160
] ,
1136
1161
} ) ;
1137
1162
await expect (
1138
- assetsContract . transferSingleERC1155 (
1139
- ERC1155_ADDRESS ,
1140
- '0x0' ,
1141
- TEST_ACCOUNT_PUBLIC_ADDRESS ,
1142
- ERC1155_ID ,
1143
- '1' ,
1144
- ) ,
1163
+ messenger
1164
+ . call ( 'AssetsContractController:getERC1155Standard' )
1165
+ . transferSingle (
1166
+ ERC1155_ADDRESS ,
1167
+ '0x0' ,
1168
+ TEST_ACCOUNT_PUBLIC_ADDRESS ,
1169
+ ERC1155_ID ,
1170
+ '1' ,
1171
+ ) ,
1145
1172
) . rejects . toThrow ( 'contract.transferSingle is not a function' ) ;
1146
1173
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
1147
1174
} ) ;
@@ -1171,23 +1198,19 @@ describe('AssetsContractController', () => {
1171
1198
} ,
1172
1199
] ,
1173
1200
} ) ;
1174
- const balance = await assetsContract . getERC1155BalanceOf (
1175
- TEST_ACCOUNT_PUBLIC_ADDRESS ,
1176
- ERC1155_ADDRESS ,
1177
- ERC1155_ID ,
1178
- ) ;
1201
+ const balance = await messenger
1202
+ . call ( 'AssetsContractController:getERC1155Standard' )
1203
+ . getBalanceOf ( TEST_ACCOUNT_PUBLIC_ADDRESS , ERC1155_ADDRESS , ERC1155_ID ) ;
1179
1204
expect ( Number ( balance ) ) . toBeGreaterThan ( 0 ) ;
1180
1205
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
1181
1206
} ) ;
1182
1207
1183
1208
it ( 'should throw missing provider error when getting the balance of a ERC-1155 NFT when missing provider' , async ( ) => {
1184
- const { assetsContract , messenger } = await setupAssetContractControllers ( ) ;
1209
+ const { messenger } = await setupAssetContractControllers ( ) ;
1185
1210
await expect (
1186
- assetsContract . getERC1155BalanceOf (
1187
- TEST_ACCOUNT_PUBLIC_ADDRESS ,
1188
- ERC1155_ADDRESS ,
1189
- ERC1155_ID ,
1190
- ) ,
1211
+ messenger
1212
+ . call ( 'AssetsContractController:getERC1155Standard' )
1213
+ . getBalanceOf ( TEST_ACCOUNT_PUBLIC_ADDRESS , ERC1155_ADDRESS , ERC1155_ID ) ,
1191
1214
) . rejects . toThrow ( MISSING_PROVIDER_ERROR ) ;
1192
1215
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
1193
1216
} ) ;
@@ -1218,10 +1241,9 @@ describe('AssetsContractController', () => {
1218
1241
] ,
1219
1242
} ) ;
1220
1243
const expectedUri = `https://api.opensea.io/api/v1/metadata/${ ERC1155_ADDRESS } /0x{id}` ;
1221
- const uri = await assetsContract . getERC1155TokenURI (
1222
- ERC1155_ADDRESS ,
1223
- ERC1155_ID ,
1224
- ) ;
1244
+ const uri = await messenger
1245
+ . call ( 'AssetsContractController:getERC1155Standard' )
1246
+ . getTokenURI ( ERC1155_ADDRESS , ERC1155_ID ) ;
1225
1247
expect ( uri . toLowerCase ( ) ) . toStrictEqual ( expectedUri ) ;
1226
1248
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
1227
1249
} ) ;
0 commit comments