Skip to content

Commit 64095c7

Browse files
committed
stash - adapt tests
1 parent 6ff77ea commit 64095c7

File tree

4 files changed

+274
-226
lines changed

4 files changed

+274
-226
lines changed

packages/assets-controllers/src/AssetsContractController.test.ts

Lines changed: 103 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import assert from 'assert';
2424
import { mockNetwork } from '../../../tests/mock-network';
2525
import { buildInfuraNetworkClientConfiguration } from '../../network-controller/tests/helpers';
2626
import type {
27+
AssetsContractControllerActions,
28+
AssetsContractControllerEvents,
2729
AllowedActions as AssetsContractAllowedActions,
2830
AllowedEvents as AssetsContractAllowedEvents,
2931
} from './AssetsContractController';
@@ -75,8 +77,12 @@ async function setupAssetContractControllers({
7577
let provider: Provider;
7678

7779
const controllerMessenger = new ControllerMessenger<
78-
NetworkControllerActions | AssetsContractAllowedActions,
79-
NetworkControllerEvents | AssetsContractAllowedEvents
80+
| NetworkControllerActions
81+
| AssetsContractControllerActions
82+
| AssetsContractAllowedActions,
83+
| NetworkControllerEvents
84+
| AssetsContractControllerEvents
85+
| AssetsContractAllowedEvents
8086
>();
8187
const networkMessenger = controllerMessenger.getRestricted({
8288
name: 'NetworkController',
@@ -227,10 +233,9 @@ describe('AssetsContractController', () => {
227233
const { assetsContract, messenger } = await setupAssetContractControllers();
228234
assetsContract.provider = undefined;
229235
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),
234239
).rejects.toThrow(MISSING_PROVIDER_ERROR);
235240
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
236241
});
@@ -239,7 +244,9 @@ describe('AssetsContractController', () => {
239244
const { assetsContract, messenger } = await setupAssetContractControllers();
240245
assetsContract.provider = undefined;
241246
await expect(
242-
assetsContract.getERC20TokenDecimals(ERC20_UNI_ADDRESS),
247+
messenger
248+
.call('AssetsContractController:getERC20Standard')
249+
.getTokenDecimals(ERC20_UNI_ADDRESS),
243250
).rejects.toThrow(MISSING_PROVIDER_ERROR);
244251
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
245252
});
@@ -285,14 +292,15 @@ describe('AssetsContractController', () => {
285292
},
286293
],
287294
});
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+
);
296304
expect(UNIBalance.toString(16)).not.toBe('0');
297305
expect(UNINoBalance.toString(16)).toBe('0');
298306
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
@@ -323,11 +331,13 @@ describe('AssetsContractController', () => {
323331
},
324332
],
325333
});
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+
);
331341
expect(tokenId).not.toBe(0);
332342
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
333343
});
@@ -336,7 +346,8 @@ describe('AssetsContractController', () => {
336346
const { assetsContract, messenger } = await setupAssetContractControllers();
337347
assetsContract.provider = undefined;
338348
await expect(
339-
assetsContract.getTokenStandardAndDetails(
349+
messenger.call(
350+
'AssetsContractController:getTokenStandardAndDetails',
340351
ERC20_UNI_ADDRESS,
341352
TEST_ACCOUNT_PUBLIC_ADDRESS,
342353
),
@@ -350,7 +361,8 @@ describe('AssetsContractController', () => {
350361
assetsContract.provider = provider;
351362
const error = 'Unable to determine contract standard';
352363
await expect(
353-
assetsContract.getTokenStandardAndDetails(
364+
messenger.call(
365+
'AssetsContractController:getTokenStandardAndDetails',
354366
'BaDeRc20AdDrEsS',
355367
TEST_ACCOUNT_PUBLIC_ADDRESS,
356368
),
@@ -415,7 +427,8 @@ describe('AssetsContractController', () => {
415427
},
416428
],
417429
});
418-
const standardAndDetails = await assetsContract.getTokenStandardAndDetails(
430+
const standardAndDetails = await messenger.call(
431+
'AssetsContractController:getTokenStandardAndDetails',
419432
ERC721_GODS_ADDRESS,
420433
TEST_ACCOUNT_PUBLIC_ADDRESS,
421434
);
@@ -496,7 +509,8 @@ describe('AssetsContractController', () => {
496509
},
497510
],
498511
});
499-
const standardAndDetails = await assetsContract.getTokenStandardAndDetails(
512+
const standardAndDetails = await messenger.call(
513+
'AssetsContractController:getTokenStandardAndDetails',
500514
ERC1155_ADDRESS,
501515
TEST_ACCOUNT_PUBLIC_ADDRESS,
502516
);
@@ -597,7 +611,8 @@ describe('AssetsContractController', () => {
597611
},
598612
],
599613
});
600-
const standardAndDetails = await assetsContract.getTokenStandardAndDetails(
614+
const standardAndDetails = await messenger.call(
615+
'AssetsContractController:getTokenStandardAndDetails',
601616
ERC20_UNI_ADDRESS,
602617
TEST_ACCOUNT_PUBLIC_ADDRESS,
603618
);
@@ -646,10 +661,9 @@ describe('AssetsContractController', () => {
646661
},
647662
],
648663
});
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');
653667
expect(tokenId).toBe('https://api.godsunchained.com/card/0');
654668
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
655669
});
@@ -699,10 +713,9 @@ describe('AssetsContractController', () => {
699713
},
700714
],
701715
});
702-
const uri = await assetsContract.getERC721TokenURI(
703-
'0x0000000000000000000000000000000000000000',
704-
'0',
705-
);
716+
const uri = await messenger
717+
.call('AssetsContractController:getERC721Standard')
718+
.getTokenURI('0x0000000000000000000000000000000000000000', '0');
706719
expect(uri).toBe('https://api.godsunchained.com/card/0');
707720
expect(errorLogSpy).toHaveBeenCalledTimes(1);
708721
expect(errorLogSpy.mock.calls).toContainEqual([
@@ -737,7 +750,9 @@ describe('AssetsContractController', () => {
737750
},
738751
],
739752
});
740-
const name = await assetsContract.getERC721AssetName(ERC721_GODS_ADDRESS);
753+
const name = await messenger
754+
.call('AssetsContractController:getERC721Standard')
755+
.getAssetName(ERC721_GODS_ADDRESS);
741756
expect(name).toBe('Gods Unchained');
742757
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
743758
});
@@ -767,17 +782,19 @@ describe('AssetsContractController', () => {
767782
},
768783
],
769784
});
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);
773788
expect(symbol).toBe('GODS');
774789
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
775790
});
776791

777792
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();
779794
await expect(
780-
assetsContract.getERC721AssetSymbol(ERC721_GODS_ADDRESS),
795+
messenger
796+
.call('AssetsContractController:getERC721Standard')
797+
.getAssetSymbol(ERC721_GODS_ADDRESS),
781798
).rejects.toThrow(MISSING_PROVIDER_ERROR);
782799
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
783800
});
@@ -807,9 +824,9 @@ describe('AssetsContractController', () => {
807824
},
808825
],
809826
});
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);
813830
expect(Number(decimals)).toBe(18);
814831
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
815832
});
@@ -840,7 +857,9 @@ describe('AssetsContractController', () => {
840857
],
841858
});
842859

843-
const name = await assetsContract.getERC20TokenName(ERC20_DAI_ADDRESS);
860+
const name = await messenger
861+
.call('AssetsContractController:getERC20Standard')
862+
.getTokenName(ERC20_DAI_ADDRESS);
844863

845864
expect(name).toBe('Dai Stablecoin');
846865
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
@@ -871,18 +890,19 @@ describe('AssetsContractController', () => {
871890
},
872891
],
873892
});
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');
878896
expect(tokenId).not.toBe('');
879897
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
880898
});
881899

882900
it('should throw missing provider error when getting ERC-721 NFT ownership', async () => {
883-
const { assetsContract, messenger } = await setupAssetContractControllers();
901+
const { messenger } = await setupAssetContractControllers();
884902
await expect(
885-
assetsContract.getERC721OwnerOf(ERC721_GODS_ADDRESS, '148332'),
903+
messenger
904+
.call('AssetsContractController:getERC721Standard')
905+
.getOwnerOf(ERC721_GODS_ADDRESS, '148332'),
886906
).rejects.toThrow(MISSING_PROVIDER_ERROR);
887907
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
888908
});
@@ -912,7 +932,8 @@ describe('AssetsContractController', () => {
912932
},
913933
],
914934
});
915-
const balances = await assetsContract.getBalancesInSingleCall(
935+
const balances = await messenger.call(
936+
'AssetsContractController:getBalancesInSingleCall',
916937
ERC20_SAI_ADDRESS,
917938
[ERC20_SAI_ADDRESS],
918939
);
@@ -1078,15 +1099,17 @@ describe('AssetsContractController', () => {
10781099
],
10791100
});
10801101

1081-
const balances = await assetsContract.getBalancesInSingleCall(
1102+
const balances = await messenger.call(
1103+
'AssetsContractController:getBalancesInSingleCall',
10821104
ERC20_SAI_ADDRESS,
10831105
[ERC20_SAI_ADDRESS],
10841106
);
10851107
expect(balances[ERC20_SAI_ADDRESS]).toBeDefined();
10861108

10871109
await network.setActiveNetwork(NetworkType.sepolia);
10881110

1089-
const noBalances = await assetsContract.getBalancesInSingleCall(
1111+
const noBalances = await messenger.call(
1112+
'AssetsContractController:getBalancesInSingleCall',
10901113
ERC20_SAI_ADDRESS,
10911114
[ERC20_SAI_ADDRESS],
10921115
);
@@ -1098,13 +1121,15 @@ describe('AssetsContractController', () => {
10981121
const { assetsContract, messenger } = await setupAssetContractControllers();
10991122
assetsContract.provider = undefined;
11001123
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+
),
11081133
).rejects.toThrow(MISSING_PROVIDER_ERROR);
11091134
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
11101135
});
@@ -1135,13 +1160,15 @@ describe('AssetsContractController', () => {
11351160
],
11361161
});
11371162
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+
),
11451172
).rejects.toThrow('contract.transferSingle is not a function');
11461173
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
11471174
});
@@ -1171,23 +1198,19 @@ describe('AssetsContractController', () => {
11711198
},
11721199
],
11731200
});
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);
11791204
expect(Number(balance)).toBeGreaterThan(0);
11801205
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
11811206
});
11821207

11831208
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();
11851210
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),
11911214
).rejects.toThrow(MISSING_PROVIDER_ERROR);
11921215
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
11931216
});
@@ -1218,10 +1241,9 @@ describe('AssetsContractController', () => {
12181241
],
12191242
});
12201243
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);
12251247
expect(uri.toLowerCase()).toStrictEqual(expectedUri);
12261248
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
12271249
});

0 commit comments

Comments
 (0)