5
5
selectedAccountNativeTokenCachedBalanceByChainId ,
6
6
selectAccountTokensAcrossChains ,
7
7
selectNativeEvmAsset ,
8
+ selectStakedEvmAsset ,
8
9
} from './evm' ;
9
10
import { SolScope } from '@metamask/keyring-api' ;
10
11
import { GetByQuery } from '@testing-library/react-native/build/queries/makeQueries' ;
@@ -27,10 +28,7 @@ import {
27
28
POLYGON_CHAIN_ID ,
28
29
} from '@metamask/swaps-controller/dist/constants' ;
29
30
import { AccountsControllerState } from '@metamask/accounts-controller' ;
30
- import { renderFromWei , weiToFiat } from '../../util/number' ;
31
- import { hexToBN } from '@metamask/controller-utils' ;
32
31
import { zeroAddress } from 'ethereumjs-util' ;
33
- import { PreferencesController } from '@metamask/preferences-controller' ;
34
32
35
33
describe ( 'Multichain Selectors' , ( ) => {
36
34
const mockState : RootState = {
@@ -42,11 +40,13 @@ describe('Multichain Selectors', () => {
42
40
chainId : '0x1' ,
43
41
name : 'Ethereum Mainnet' ,
44
42
nativeCurrency : 'ETH' ,
43
+ rpcEndpoints : [ { networkClientId : '0x1' } ] ,
45
44
} ,
46
45
'0x89' : {
47
46
chainId : '0x89' ,
48
47
name : 'Polygon' ,
49
- nativeCurrency : 'MATIC' ,
48
+ nativeCurrency : 'POL' ,
49
+ rpcEndpoints : [ { networkClientId : '0x89' } ] ,
50
50
} ,
51
51
} ,
52
52
} ,
@@ -98,9 +98,13 @@ describe('Multichain Selectors', () => {
98
98
} ,
99
99
CurrencyRateController : {
100
100
currentCurrency : 'USD' ,
101
- conversionRates : {
102
- ETH : 2000 ,
103
- MATIC : 1 ,
101
+ currencyRates : {
102
+ ETH : {
103
+ conversionRate : 2000 ,
104
+ } ,
105
+ POL : {
106
+ conversionRate : 1 ,
107
+ } ,
104
108
} ,
105
109
} ,
106
110
AccountsController : {
@@ -202,17 +206,88 @@ describe('Multichain Selectors', () => {
202
206
203
207
it ( 'should handle multiple chains correctly' , ( ) => {
204
208
const result = selectAccountTokensAcrossChains ( mockState ) ;
209
+ console . log ( 'RESULT: ' , result ) ;
205
210
expect ( result ) . toHaveProperty ( '0x89' ) ;
206
211
const polygonTokens = result [ '0x89' ] ;
207
212
expect ( polygonTokens . length ) . toBeGreaterThan ( 0 ) ;
208
- expect ( polygonTokens . some ( ( token ) => token . symbol === 'MATIC' ) ) . toBe (
209
- true ,
210
- ) ;
213
+ expect ( polygonTokens . some ( ( token ) => token . symbol === 'POL' ) ) . toBe ( true ) ;
211
214
} ) ;
212
215
} ) ;
213
216
214
217
describe ( 'selectNativeEvmAsset' , ( ) => {
215
- it . only ( 'should return undefined if accountBalanceByChainId is not provided' , ( ) => {
218
+ const testState : RootState = {
219
+ engine : {
220
+ backgroundState : {
221
+ ...mockState . engine . backgroundState ,
222
+ AccountTrackerController : {
223
+ accountsByChainId : { } ,
224
+ } ,
225
+ NetworkController : {
226
+ ...mockState . engine . backgroundState . NetworkController ,
227
+ selectedNetworkClientId : '0x1' ,
228
+ } ,
229
+ AccountsController : {
230
+ internalAccounts : {
231
+ selectedAccount : '' ,
232
+ accounts : { } ,
233
+ } ,
234
+ } ,
235
+ } ,
236
+ } ,
237
+ settings : {
238
+ showFiatOnTestnets : true ,
239
+ } ,
240
+ } as unknown as RootState ;
241
+ it ( 'should return undefined if accountBalanceByChainId is not provided' , ( ) => {
242
+ const result = selectNativeEvmAsset ( testState ) ;
243
+ expect ( result ) . toBeUndefined ( ) ;
244
+ } ) ;
245
+
246
+ it ( 'should return the correct native EVM asset structure' , ( ) => {
247
+ const result = selectNativeEvmAsset ( mockState ) ;
248
+
249
+ expect ( result ) . toEqual ( {
250
+ decimals : 18 ,
251
+ name : 'Ethereum' ,
252
+ symbol : 'ETH' ,
253
+ isETH : true ,
254
+ balance : '< 0.00001' ,
255
+ balanceFiat : '$0' ,
256
+ logo : '../images/eth-logo-new.png' ,
257
+ address : zeroAddress ( ) ,
258
+ } ) ;
259
+ } ) ;
260
+
261
+ it ( 'should return asset name as ticker if not ETH' , ( ) => {
262
+ const testStateOverride = {
263
+ ...testState ,
264
+ engine : {
265
+ backgroundState : {
266
+ ...mockState . engine . backgroundState ,
267
+ NetworkController : {
268
+ ...mockState . engine . backgroundState . NetworkController ,
269
+ selectedNetworkClientId : '0x89' ,
270
+ } ,
271
+ } ,
272
+ } ,
273
+ } as unknown as RootState ;
274
+ const result = selectNativeEvmAsset ( testStateOverride ) ;
275
+
276
+ expect ( result ) . toEqual ( {
277
+ decimals : 18 ,
278
+ name : 'POL' ,
279
+ symbol : 'POL' ,
280
+ isETH : true ,
281
+ balance : '< 0.00001' ,
282
+ balanceFiat : '$0' ,
283
+ logo : '../images/eth-logo-new.png' ,
284
+ address : zeroAddress ( ) ,
285
+ } ) ;
286
+ } ) ;
287
+ } ) ;
288
+
289
+ describe ( 'selectStakedEvmAsset' , ( ) => {
290
+ it ( 'should return undefined if accountBalanceByChainId is not provided' , ( ) => {
216
291
const testState : RootState = {
217
292
engine : {
218
293
backgroundState : {
@@ -232,51 +307,91 @@ describe('Multichain Selectors', () => {
232
307
showFiatOnTestnets : true ,
233
308
} ,
234
309
} as unknown as RootState ;
235
- const result = selectNativeEvmAsset ( testState ) ;
310
+
311
+ const result = selectStakedEvmAsset ( testState ) ;
236
312
expect ( result ) . toBeUndefined ( ) ;
237
313
} ) ;
238
314
239
- // it('should return the correct native EVM asset structure', () => {
240
- // const accountBalanceByChainId = { balance: '1000000000000000000' }; // 1 ETH in wei
241
- // const result = selectNativeEvmAsset.resultFunc(
242
- // accountBalanceByChainId,
243
- // 'ETH',
244
- // 3000,
245
- // 'USD',
246
- // );
247
-
248
- // expect(result).toEqual({
249
- // decimals: 18,
250
- // name: 'Ethereum',
251
- // symbol: 'ETH',
252
- // isETH: true,
253
- // balance: '1000000000000000000 ETH', // Mocked `renderFromWei`
254
- // balanceFiat: '3000000000000000000000 USD', // Mocked `weiToFiat`
255
- // logo: '../images/eth-logo-new.png',
256
- // address: zeroAddress(),
257
- // });
258
- // });
259
-
260
- // it('should return asset name as ticker if not ETH', () => {
261
- // const accountBalanceByChainId = { balance: '500000000000000000' }; // 0.5 XYZ
262
- // const result = selectNativeEvmAsset.resultFunc(
263
- // accountBalanceByChainId,
264
- // 'XYZ',
265
- // 2000,
266
- // 'EUR',
267
- // );
268
-
269
- // expect(result).toEqual({
270
- // decimals: 18,
271
- // name: 'XYZ',
272
- // symbol: 'XYZ',
273
- // isETH: true,
274
- // balance: '500000000000000000 ETH',
275
- // balanceFiat: '1000000000000000000000 EUR',
276
- // logo: '../images/eth-logo-new.png',
277
- // address: zeroAddress(),
278
- // });
279
- // });
315
+ it ( 'should return undefined if stakedBalance is missing' , ( ) => {
316
+ const testState : RootState = {
317
+ ...mockState ,
318
+ engine : {
319
+ backgroundState : {
320
+ ...mockState . engine . backgroundState ,
321
+ AccountTrackerController : {
322
+ accountsByChainId : {
323
+ '0x1' : {
324
+ balance : '0x1' , // 1 ETH
325
+ } ,
326
+ } ,
327
+ } ,
328
+ } ,
329
+ } ,
330
+ } as unknown as RootState ;
331
+
332
+ const result = selectStakedEvmAsset ( testState ) ;
333
+ expect ( result ) . toBeUndefined ( ) ;
334
+ } ) ;
335
+
336
+ it ( 'should return undefined if stakedBalance is zero' , ( ) => {
337
+ const testState : RootState = {
338
+ ...mockState ,
339
+ engine : {
340
+ backgroundState : {
341
+ ...mockState . engine . backgroundState ,
342
+ AccountTrackerController : {
343
+ accountsByChainId : {
344
+ '0x1' : {
345
+ balance : '0x1' ,
346
+ stakedBalance : '0x2' ,
347
+ } ,
348
+ } ,
349
+ } ,
350
+ } ,
351
+ } ,
352
+ } as unknown as RootState ;
353
+
354
+ const result = selectStakedEvmAsset ( testState ) ;
355
+ expect ( result ) . toBeUndefined ( ) ;
356
+ } ) ;
357
+
358
+ it ( 'should return undefined if nativeAsset is missing' , ( ) => {
359
+ const testState : RootState = {
360
+ ...mockState ,
361
+ engine : {
362
+ backgroundState : {
363
+ ...mockState . engine . backgroundState ,
364
+ AccountTrackerController : {
365
+ accountsByChainId : {
366
+ '0x1' : {
367
+ balance : '0x1' ,
368
+ stakedBalance : '0x2' ,
369
+ } ,
370
+ } ,
371
+ } ,
372
+ } ,
373
+ } ,
374
+ } as unknown as RootState ;
375
+
376
+ const result = selectStakedEvmAsset ( testState ) ;
377
+ expect ( result ) . toBeUndefined ( ) ;
378
+ } ) ;
379
+
380
+ it ( 'should return the correct staked EVM asset structure' , ( ) => {
381
+ const result = selectStakedEvmAsset ( mockState ) ;
382
+
383
+ expect ( result ) . toEqual ( {
384
+ decimals : 18 ,
385
+ name : 'Staked Ethereum' ,
386
+ symbol : 'ETH' ,
387
+ isETH : true ,
388
+ isStaked : true ,
389
+ balance : '< 0.00001' ,
390
+ balanceFiat : '$0' ,
391
+ logo : '../images/eth-logo-new.png' ,
392
+ address : zeroAddress ( ) ,
393
+ } ) ;
394
+ } ) ;
280
395
} ) ;
281
396
} ) ;
282
397
0 commit comments