@@ -21,7 +21,6 @@ import {
2121
2222import type { SnapClient } from '../../clients/snap/SnapClient' ;
2323import { Network } from '../../constants' ;
24- import type { NativeAsset } from '../../entities/assets' ;
2524import type { TronKeyringAccount } from '../../entities/keyring-account' ;
2625import type { ILogger } from '../../utils/logger' ;
2726import { mockLogger } from '../../utils/mockLogger' ;
@@ -119,9 +118,7 @@ type WithAccountsServiceCallback = (payload: {
119118 > ;
120119 mockConfigProvider : jest . Mocked < Pick < ConfigProvider , 'get' > > ;
121120 mockLogger : ILogger ;
122- mockAssetsService : jest . Mocked <
123- Pick < AssetsService , 'fetchAssetsAndBalancesForAccount' | 'saveMany' >
124- > ;
121+ mockAssetsService : jest . Mocked < Pick < AssetsService , 'syncSnapOwnedAssets' > > ;
125122 mockSnapClient : jest . Mocked <
126123 Pick < SnapClient , 'getBip32Entropy' | 'listEntropySources' >
127124 > ;
@@ -268,10 +265,9 @@ async function withAccountsService(
268265 } ;
269266
270267 const mockAssetsService : jest . Mocked <
271- Pick < AssetsService , 'fetchAssetsAndBalancesForAccount' | 'saveMany '>
268+ Pick < AssetsService , 'syncSnapOwnedAssets ' >
272269 > = {
273- fetchAssetsAndBalancesForAccount : jest . fn ( ) . mockResolvedValue ( [ ] ) ,
274- saveMany : jest . fn ( ) . mockResolvedValue ( undefined ) ,
270+ syncSnapOwnedAssets : jest . fn ( ) . mockResolvedValue ( undefined ) ,
275271 } ;
276272
277273 const mockTransactionsService : jest . Mocked <
@@ -1194,7 +1190,7 @@ describe('AccountsService', () => {
11941190 } ) ;
11951191
11961192 describe ( 'synchronizeAssets' , ( ) => {
1197- it ( 'calls fetch for each account and scope, then saveMany ' , async ( ) => {
1193+ it ( 'calls syncSnapOwnedAssets with accounts and active networks ' , async ( ) => {
11981194 const account : TronKeyringAccount = {
11991195 id : 'sync-asset-id' ,
12001196 address : 'TSyncAsset12345678901234567' ,
@@ -1206,42 +1202,22 @@ describe('AccountsService', () => {
12061202 derivationPath : "m/44'/195'/0'/0/0" ,
12071203 index : 0 ,
12081204 } ;
1209- const mockAssets : NativeAsset [ ] = [
1210- {
1211- assetType : `${ Network . Mainnet } /slip44:195` ,
1212- keyringAccountId : 'sync-asset-id' ,
1213- network : Network . Mainnet ,
1214- symbol : 'TRX' ,
1215- decimals : 6 ,
1216- rawAmount : '1000000' ,
1217- uiAmount : '1' ,
1218- iconUrl : '' ,
1219- } ,
1220- ] ;
12211205
12221206 await withAccountsService (
12231207 async ( { accountsService, mockConfigProvider, mockAssetsService } ) => {
12241208 mockConfigProvider . get . mockReturnValue ( {
12251209 ...MOCK_CONFIG ,
12261210 activeNetworks : [ Network . Mainnet , Network . Shasta ] ,
12271211 } ) ;
1228- mockAssetsService . fetchAssetsAndBalancesForAccount . mockResolvedValue (
1229- mockAssets ,
1230- ) ;
12311212
12321213 await accountsService . synchronizeAssets ( [ account ] ) ;
12331214
1234- expect (
1235- mockAssetsService . fetchAssetsAndBalancesForAccount ,
1236- ) . toHaveBeenCalledTimes ( 2 ) ;
1237- expect (
1238- mockAssetsService . fetchAssetsAndBalancesForAccount ,
1239- ) . toHaveBeenCalledWith ( Network . Mainnet , account ) ;
1240- expect (
1241- mockAssetsService . fetchAssetsAndBalancesForAccount ,
1242- ) . toHaveBeenCalledWith ( Network . Shasta , account ) ;
1243- expect ( mockAssetsService . saveMany ) . toHaveBeenCalledWith (
1244- expect . arrayContaining ( mockAssets ) ,
1215+ expect ( mockAssetsService . syncSnapOwnedAssets ) . toHaveBeenCalledTimes (
1216+ 1 ,
1217+ ) ;
1218+ expect ( mockAssetsService . syncSnapOwnedAssets ) . toHaveBeenCalledWith (
1219+ [ account ] ,
1220+ [ Network . Mainnet , Network . Shasta ] ,
12451221 ) ;
12461222 } ,
12471223 ) ;
@@ -1266,10 +1242,10 @@ describe('AccountsService', () => {
12661242
12671243 await accountsService . synchronizeAssets ( [ account ] ) ;
12681244
1269- expect (
1270- mockAssetsService . fetchAssetsAndBalancesForAccount ,
1271- ) . not . toHaveBeenCalled ( ) ;
1272- expect ( mockAssetsService . saveMany ) . toHaveBeenCalledWith ( [ ] ) ;
1245+ expect ( mockAssetsService . syncSnapOwnedAssets ) . toHaveBeenCalledWith (
1246+ [ account ] ,
1247+ [ ] ,
1248+ ) ;
12731249 } ,
12741250 ) ;
12751251 } ) ;
@@ -1358,9 +1334,10 @@ describe('AccountsService', () => {
13581334
13591335 await accountsService . synchronize ( [ account ] ) ;
13601336
1361- expect (
1362- mockAssetsService . fetchAssetsAndBalancesForAccount ,
1363- ) . toHaveBeenCalledWith ( Network . Mainnet , account ) ;
1337+ expect ( mockAssetsService . syncSnapOwnedAssets ) . toHaveBeenCalledWith (
1338+ [ account ] ,
1339+ [ Network . Mainnet ] ,
1340+ ) ;
13641341 expect (
13651342 mockTransactionsService . fetchNewTransactionsForAccount ,
13661343 ) . toHaveBeenCalledWith ( Network . Mainnet , account ) ;
0 commit comments