@@ -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' ;
@@ -61,7 +63,9 @@ async function setupAssetContractControllers({
61
63
useNetworkControllerProvider,
62
64
infuraProjectId = '341eacb578dd44a1a049cbc5f6fd4035' ,
63
65
} : {
64
- options ?: Partial < ConstructorParameters < typeof AssetsContractController > [ 0 ] > ;
66
+ options ?: Partial <
67
+ Omit < ConstructorParameters < typeof AssetsContractController > [ 0 ] , 'messenger' >
68
+ > ;
65
69
useNetworkControllerProvider ?: boolean ;
66
70
infuraProjectId ?: string ;
67
71
} = { } ) {
@@ -75,8 +79,12 @@ async function setupAssetContractControllers({
75
79
let provider : Provider ;
76
80
77
81
const controllerMessenger = new ControllerMessenger <
78
- NetworkControllerActions | AssetsContractAllowedActions ,
79
- NetworkControllerEvents | AssetsContractAllowedEvents
82
+ | NetworkControllerActions
83
+ | AssetsContractControllerActions
84
+ | AssetsContractAllowedActions ,
85
+ | NetworkControllerEvents
86
+ | AssetsContractControllerEvents
87
+ | AssetsContractAllowedEvents
80
88
> ( ) ;
81
89
const networkMessenger = controllerMessenger . getRestricted ( {
82
90
name : 'NetworkController' ,
@@ -227,7 +235,8 @@ describe('AssetsContractController', () => {
227
235
const { assetsContract, messenger } = await setupAssetContractControllers ( ) ;
228
236
assetsContract . provider = undefined ;
229
237
await expect (
230
- assetsContract . getERC20BalanceOf (
238
+ messenger . call (
239
+ `AssetsContractController:getERC20BalanceOf` ,
231
240
ERC20_UNI_ADDRESS ,
232
241
TEST_ACCOUNT_PUBLIC_ADDRESS ,
233
242
) ,
@@ -239,7 +248,10 @@ describe('AssetsContractController', () => {
239
248
const { assetsContract, messenger } = await setupAssetContractControllers ( ) ;
240
249
assetsContract . provider = undefined ;
241
250
await expect (
242
- assetsContract . getERC20TokenDecimals ( ERC20_UNI_ADDRESS ) ,
251
+ messenger . call (
252
+ `AssetsContractController:getERC20TokenDecimals` ,
253
+ ERC20_UNI_ADDRESS ,
254
+ ) ,
243
255
) . rejects . toThrow ( MISSING_PROVIDER_ERROR ) ;
244
256
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
245
257
} ) ;
@@ -285,11 +297,13 @@ describe('AssetsContractController', () => {
285
297
} ,
286
298
] ,
287
299
} ) ;
288
- const UNIBalance = await assetsContract . getERC20BalanceOf (
300
+ const UNIBalance = await messenger . call (
301
+ `AssetsContractController:getERC20BalanceOf` ,
289
302
ERC20_UNI_ADDRESS ,
290
303
TEST_ACCOUNT_PUBLIC_ADDRESS ,
291
304
) ;
292
- const UNINoBalance = await assetsContract . getERC20BalanceOf (
305
+ const UNINoBalance = await messenger . call (
306
+ `AssetsContractController:getERC20BalanceOf` ,
293
307
ERC20_UNI_ADDRESS ,
294
308
'0x202637dAAEfbd7f131f90338a4A6c69F6Cd5CE91' ,
295
309
) ;
@@ -323,7 +337,8 @@ describe('AssetsContractController', () => {
323
337
} ,
324
338
] ,
325
339
} ) ;
326
- const tokenId = await assetsContract . getERC721NftTokenId (
340
+ const tokenId = await messenger . call (
341
+ `AssetsContractController:getERC721NftTokenId` ,
327
342
ERC721_GODS_ADDRESS ,
328
343
'0x9a90bd8d1149a88b42a99cf62215ad955d6f498a' ,
329
344
0 ,
@@ -336,7 +351,8 @@ describe('AssetsContractController', () => {
336
351
const { assetsContract, messenger } = await setupAssetContractControllers ( ) ;
337
352
assetsContract . provider = undefined ;
338
353
await expect (
339
- assetsContract . getTokenStandardAndDetails (
354
+ messenger . call (
355
+ `AssetsContractController:getTokenStandardAndDetails` ,
340
356
ERC20_UNI_ADDRESS ,
341
357
TEST_ACCOUNT_PUBLIC_ADDRESS ,
342
358
) ,
@@ -350,7 +366,8 @@ describe('AssetsContractController', () => {
350
366
assetsContract . provider = provider ;
351
367
const error = 'Unable to determine contract standard' ;
352
368
await expect (
353
- assetsContract . getTokenStandardAndDetails (
369
+ messenger . call (
370
+ `AssetsContractController:getTokenStandardAndDetails` ,
354
371
'BaDeRc20AdDrEsS' ,
355
372
TEST_ACCOUNT_PUBLIC_ADDRESS ,
356
373
) ,
@@ -415,7 +432,8 @@ describe('AssetsContractController', () => {
415
432
} ,
416
433
] ,
417
434
} ) ;
418
- const standardAndDetails = await assetsContract . getTokenStandardAndDetails (
435
+ const standardAndDetails = await messenger . call (
436
+ `AssetsContractController:getTokenStandardAndDetails` ,
419
437
ERC721_GODS_ADDRESS ,
420
438
TEST_ACCOUNT_PUBLIC_ADDRESS ,
421
439
) ;
@@ -496,7 +514,8 @@ describe('AssetsContractController', () => {
496
514
} ,
497
515
] ,
498
516
} ) ;
499
- const standardAndDetails = await assetsContract . getTokenStandardAndDetails (
517
+ const standardAndDetails = await messenger . call (
518
+ `AssetsContractController:getTokenStandardAndDetails` ,
500
519
ERC1155_ADDRESS ,
501
520
TEST_ACCOUNT_PUBLIC_ADDRESS ,
502
521
) ;
@@ -597,7 +616,8 @@ describe('AssetsContractController', () => {
597
616
} ,
598
617
] ,
599
618
} ) ;
600
- const standardAndDetails = await assetsContract . getTokenStandardAndDetails (
619
+ const standardAndDetails = await messenger . call (
620
+ `AssetsContractController:getTokenStandardAndDetails` ,
601
621
ERC20_UNI_ADDRESS ,
602
622
TEST_ACCOUNT_PUBLIC_ADDRESS ,
603
623
) ;
@@ -646,7 +666,8 @@ describe('AssetsContractController', () => {
646
666
} ,
647
667
] ,
648
668
} ) ;
649
- const tokenId = await assetsContract . getERC721TokenURI (
669
+ const tokenId = await messenger . call (
670
+ `AssetsContractController:getERC721TokenURI` ,
650
671
ERC721_GODS_ADDRESS ,
651
672
'0' ,
652
673
) ;
@@ -699,7 +720,8 @@ describe('AssetsContractController', () => {
699
720
} ,
700
721
] ,
701
722
} ) ;
702
- const uri = await assetsContract . getERC721TokenURI (
723
+ const uri = await messenger . call (
724
+ `AssetsContractController:getERC721TokenURI` ,
703
725
'0x0000000000000000000000000000000000000000' ,
704
726
'0' ,
705
727
) ;
@@ -737,7 +759,10 @@ describe('AssetsContractController', () => {
737
759
} ,
738
760
] ,
739
761
} ) ;
740
- const name = await assetsContract . getERC721AssetName ( ERC721_GODS_ADDRESS ) ;
762
+ const name = await messenger . call (
763
+ `AssetsContractController:getERC721AssetName` ,
764
+ ERC721_GODS_ADDRESS ,
765
+ ) ;
741
766
expect ( name ) . toBe ( 'Gods Unchained' ) ;
742
767
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
743
768
} ) ;
@@ -767,17 +792,21 @@ describe('AssetsContractController', () => {
767
792
} ,
768
793
] ,
769
794
} ) ;
770
- const symbol = await assetsContract . getERC721AssetSymbol (
795
+ const symbol = await messenger . call (
796
+ `AssetsContractController:getERC721AssetSymbol` ,
771
797
ERC721_GODS_ADDRESS ,
772
798
) ;
773
799
expect ( symbol ) . toBe ( 'GODS' ) ;
774
800
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
775
801
} ) ;
776
802
777
803
it ( 'should throw missing provider error when getting ERC-721 NFT symbol when missing provider' , async ( ) => {
778
- const { assetsContract , messenger } = await setupAssetContractControllers ( ) ;
804
+ const { messenger } = await setupAssetContractControllers ( ) ;
779
805
await expect (
780
- assetsContract . getERC721AssetSymbol ( ERC721_GODS_ADDRESS ) ,
806
+ messenger . call (
807
+ `AssetsContractController:getERC721AssetSymbol` ,
808
+ ERC721_GODS_ADDRESS ,
809
+ ) ,
781
810
) . rejects . toThrow ( MISSING_PROVIDER_ERROR ) ;
782
811
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
783
812
} ) ;
@@ -807,7 +836,8 @@ describe('AssetsContractController', () => {
807
836
} ,
808
837
] ,
809
838
} ) ;
810
- const decimals = await assetsContract . getERC20TokenDecimals (
839
+ const decimals = await messenger . call (
840
+ `AssetsContractController:getERC20TokenDecimals` ,
811
841
ERC20_SAI_ADDRESS ,
812
842
) ;
813
843
expect ( Number ( decimals ) ) . toBe ( 18 ) ;
@@ -840,7 +870,10 @@ describe('AssetsContractController', () => {
840
870
] ,
841
871
} ) ;
842
872
843
- const name = await assetsContract . getERC20TokenName ( ERC20_DAI_ADDRESS ) ;
873
+ const name = await messenger . call (
874
+ `AssetsContractController:getERC20TokenName` ,
875
+ ERC20_DAI_ADDRESS ,
876
+ ) ;
844
877
845
878
expect ( name ) . toBe ( 'Dai Stablecoin' ) ;
846
879
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
@@ -871,7 +904,8 @@ describe('AssetsContractController', () => {
871
904
} ,
872
905
] ,
873
906
} ) ;
874
- const tokenId = await assetsContract . getERC721OwnerOf (
907
+ const tokenId = await messenger . call (
908
+ `AssetsContractController:getERC721OwnerOf` ,
875
909
ERC721_GODS_ADDRESS ,
876
910
'148332' ,
877
911
) ;
@@ -880,9 +914,13 @@ describe('AssetsContractController', () => {
880
914
} ) ;
881
915
882
916
it ( 'should throw missing provider error when getting ERC-721 NFT ownership' , async ( ) => {
883
- const { assetsContract , messenger } = await setupAssetContractControllers ( ) ;
917
+ const { messenger } = await setupAssetContractControllers ( ) ;
884
918
await expect (
885
- assetsContract . getERC721OwnerOf ( ERC721_GODS_ADDRESS , '148332' ) ,
919
+ messenger . call (
920
+ `AssetsContractController:getERC721OwnerOf` ,
921
+ ERC721_GODS_ADDRESS ,
922
+ '148332' ,
923
+ ) ,
886
924
) . rejects . toThrow ( MISSING_PROVIDER_ERROR ) ;
887
925
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
888
926
} ) ;
@@ -912,7 +950,8 @@ describe('AssetsContractController', () => {
912
950
} ,
913
951
] ,
914
952
} ) ;
915
- const balances = await assetsContract . getBalancesInSingleCall (
953
+ const balances = await messenger . call (
954
+ `AssetsContractController:getBalancesInSingleCall` ,
916
955
ERC20_SAI_ADDRESS ,
917
956
[ ERC20_SAI_ADDRESS ] ,
918
957
) ;
@@ -988,7 +1027,7 @@ describe('AssetsContractController', () => {
988
1027
} ,
989
1028
] ,
990
1029
} ) ;
991
- const { assetsContract, network, provider } =
1030
+ const { assetsContract, messenger , network, provider } =
992
1031
await setupAssetContractControllers ( {
993
1032
options : {
994
1033
chainId : ChainId . mainnet ,
@@ -998,7 +1037,8 @@ describe('AssetsContractController', () => {
998
1037
} ) ;
999
1038
assetsContract . provider = provider ;
1000
1039
1001
- const balancesOnMainnet = await assetsContract . getBalancesInSingleCall (
1040
+ const balancesOnMainnet = await messenger . call (
1041
+ `AssetsContractController:getBalancesInSingleCall` ,
1002
1042
ERC20_SAI_ADDRESS ,
1003
1043
[ ERC20_SAI_ADDRESS ] ,
1004
1044
) ;
@@ -1008,9 +1048,11 @@ describe('AssetsContractController', () => {
1008
1048
1009
1049
await network . setActiveNetwork ( InfuraNetworkType [ 'linea-mainnet' ] ) ;
1010
1050
1011
- const balancesOnLineaMainnet = await assetsContract . getBalancesInSingleCall (
1051
+ const balancesOnLineaMainnet = await messenger . call (
1052
+ `AssetsContractController:getBalancesInSingleCall` ,
1012
1053
ERC20_SAI_ADDRESS ,
1013
1054
[ ERC20_SAI_ADDRESS ] ,
1055
+ InfuraNetworkType [ 'linea-mainnet' ] ,
1014
1056
) ;
1015
1057
expect ( balancesOnLineaMainnet ) . toStrictEqual ( {
1016
1058
[ ERC20_SAI_ADDRESS ] : BigNumber . from ( '0xa0155d09733ed8ef4c4' ) ,
@@ -1078,15 +1120,17 @@ describe('AssetsContractController', () => {
1078
1120
] ,
1079
1121
} ) ;
1080
1122
1081
- const balances = await assetsContract . getBalancesInSingleCall (
1123
+ const balances = await messenger . call (
1124
+ `AssetsContractController:getBalancesInSingleCall` ,
1082
1125
ERC20_SAI_ADDRESS ,
1083
1126
[ ERC20_SAI_ADDRESS ] ,
1084
1127
) ;
1085
1128
expect ( balances [ ERC20_SAI_ADDRESS ] ) . toBeDefined ( ) ;
1086
1129
1087
1130
await network . setActiveNetwork ( NetworkType . sepolia ) ;
1088
1131
1089
- const noBalances = await assetsContract . getBalancesInSingleCall (
1132
+ const noBalances = await messenger . call (
1133
+ `AssetsContractController:getBalancesInSingleCall` ,
1090
1134
ERC20_SAI_ADDRESS ,
1091
1135
[ ERC20_SAI_ADDRESS ] ,
1092
1136
) ;
@@ -1098,7 +1142,8 @@ describe('AssetsContractController', () => {
1098
1142
const { assetsContract, messenger } = await setupAssetContractControllers ( ) ;
1099
1143
assetsContract . provider = undefined ;
1100
1144
await expect (
1101
- assetsContract . transferSingleERC1155 (
1145
+ messenger . call (
1146
+ `AssetsContractController:transferSingleERC1155` ,
1102
1147
ERC1155_ADDRESS ,
1103
1148
TEST_ACCOUNT_PUBLIC_ADDRESS ,
1104
1149
TEST_ACCOUNT_PUBLIC_ADDRESS ,
@@ -1135,7 +1180,8 @@ describe('AssetsContractController', () => {
1135
1180
] ,
1136
1181
} ) ;
1137
1182
await expect (
1138
- assetsContract . transferSingleERC1155 (
1183
+ messenger . call (
1184
+ `AssetsContractController:transferSingleERC1155` ,
1139
1185
ERC1155_ADDRESS ,
1140
1186
'0x0' ,
1141
1187
TEST_ACCOUNT_PUBLIC_ADDRESS ,
@@ -1171,19 +1217,21 @@ describe('AssetsContractController', () => {
1171
1217
} ,
1172
1218
] ,
1173
1219
} ) ;
1174
- const balance = await assetsContract . getERC1155BalanceOf (
1220
+ const balance = await messenger . call (
1221
+ `AssetsContractController:getERC1155BalanceOf` ,
1175
1222
TEST_ACCOUNT_PUBLIC_ADDRESS ,
1176
1223
ERC1155_ADDRESS ,
1177
1224
ERC1155_ID ,
1178
1225
) ;
1179
- expect ( Number ( balance ) ) . toBeGreaterThan ( 0 ) ;
1226
+ expect ( balance . isZero ( ) || balance . isNeg ( ) ) . toBe ( false ) ;
1180
1227
messenger . clearEventSubscriptions ( 'NetworkController:networkDidChange' ) ;
1181
1228
} ) ;
1182
1229
1183
1230
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 ( ) ;
1231
+ const { messenger } = await setupAssetContractControllers ( ) ;
1185
1232
await expect (
1186
- assetsContract . getERC1155BalanceOf (
1233
+ messenger . call (
1234
+ `AssetsContractController:getERC1155BalanceOf` ,
1187
1235
TEST_ACCOUNT_PUBLIC_ADDRESS ,
1188
1236
ERC1155_ADDRESS ,
1189
1237
ERC1155_ID ,
@@ -1218,7 +1266,8 @@ describe('AssetsContractController', () => {
1218
1266
] ,
1219
1267
} ) ;
1220
1268
const expectedUri = `https://api.opensea.io/api/v1/metadata/${ ERC1155_ADDRESS } /0x{id}` ;
1221
- const uri = await assetsContract . getERC1155TokenURI (
1269
+ const uri = await messenger . call (
1270
+ `AssetsContractController:getERC1155TokenURI` ,
1222
1271
ERC1155_ADDRESS ,
1223
1272
ERC1155_ID ,
1224
1273
) ;
0 commit comments