Skip to content
2 changes: 1 addition & 1 deletion eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
"count": 1
}
},
"packages/tron-wallet-snap/src/services/assets/AssetsService.ts": {
"packages/tron-wallet-snap/src/services/assets/adapters/SnapAssetsAdapter.ts": {
"import-x/no-extraneous-dependencies": {
"count": 2
}
Expand Down
2 changes: 1 addition & 1 deletion packages/tron-wallet-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/internal-snaps.git"
},
"source": {
"shasum": "0TZh63x04Gncx8UgHBoWnQ4RmX6kmTL6RmJTyqgJ7G8=",
"shasum": "v/z/ZIpUZySW36sgXifEyUGKQXotRHLvezPeeP2xQAk=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2830,4 +2830,79 @@ describe('AssetsService', () => {
});
});
});

describe('facade delegation', () => {
it('delegates repository reads and market helpers to SnapAssetsAdapter', async () => {
await withAssetsService(
async ({ assetsService, mockAssetsRepository, mockPriceApiClient }) => {
const asset: AssetEntity = {
assetType: KnownCaip19Id.TrxMainnet,
keyringAccountId: mockAccount.id,
network: Network.Mainnet,
symbol: 'TRX',
decimals: 6,
rawAmount: '1',
uiAmount: '1',
};

mockAssetsRepository.getByAccountId.mockResolvedValue([asset]);
mockAssetsRepository.getByAccountIdAndAssetTypes.mockResolvedValue([
asset,
]);
mockAssetsRepository.getByAccountIdAndAssetType.mockResolvedValue(
asset,
);
mockPriceApiClient.getFiatExchangeRates.mockResolvedValue({
usd: { value: 1 },
});
mockPriceApiClient.getMultipleSpotPrices.mockResolvedValue(
createSpotPrices({
[KnownCaip19Id.TrxMainnet]: {
id: KnownCaip19Id.TrxMainnet,
price: 1,
},
}),
);

expect(AssetsService.isFiat('eip155:1/erc20:0x0')).toBe(false);
expect(AssetsService.isFiat('swift:0/iso4217:usd')).toBe(true);
expect(AssetsService.hasChanged(asset, [])).toBe(true);
expect(AssetsService.hasChanged(asset, [asset])).toBe(false);

expect(
await assetsService.getAccountAssets(mockAccount.id),
).toStrictEqual([asset]);
expect(
await assetsService.getAccountAssetsByIDs(mockAccount.id, [
KnownCaip19Id.TrxMainnet,
]),
).toStrictEqual([asset]);
expect(
await assetsService.getAccountAssetByID(
mockAccount.id,
KnownCaip19Id.TrxMainnet,
),
).toStrictEqual(asset);
const byKeyringAccountId = await assetsService.getByKeyringAccountId(
mockAccount.id,
);
expect(
byKeyringAccountId.some(
(savedAsset) => savedAsset.assetType === KnownCaip19Id.TrxMainnet,
),
).toBe(true);
const marketData = await assetsService.getMultipleTokensMarketData([
{
asset: KnownCaip19Id.TrxMainnet,
unit: 'swift:0/iso4217:usd',
},
]);
expect(marketData[KnownCaip19Id.TrxMainnet]).toBeDefined();
expect(assetsService.cacheTtlsMilliseconds.historicalPrices).toBe(
3600000,
);
},
);
});
});
});
Loading
Loading