Skip to content

Commit bf46c69

Browse files
wip
1 parent 7fd50fd commit bf46c69

File tree

18 files changed

+91
-158
lines changed

18 files changed

+91
-158
lines changed

libs/coin-modules/coin-evm/src/__tests__/fixtures/accounts.fixtures.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import BigNumber from "bignumber.js";
2-
import { hashes as localTokensHashesByChainId } from "@ledgerhq/cryptoassets/data/evm/index";
32
import { ERC20Token } from "@ledgerhq/cryptoassets/types";
43
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
54
import { AccountShapeInfo } from "@ledgerhq/coin-framework/bridge/jsHelpers";
6-
import { CryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/type";
7-
import { setCryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/index";
8-
import usdtTokenData from "../../__fixtures__/scroll_sepolia-erc20-mock_usdt.json";
9-
import newTokenData from "../../__fixtures__/scroll_sepolia-erc20-new_token_mock.json";
5+
import * as legacyTokens from "@ledgerhq/cryptoassets/tokens";
6+
import { CryptoAssetsStore } from "@ledgerhq/types-live/lib/crypto-assets/type";
7+
import { setCryptoAssetsStore as setCryptoAssetsStoreForCoinFramework } from "@ledgerhq/coin-framework/crypto-assets/index";
108
import { makeOperation } from "./common.fixtures";
119

1210
export const currency = getCryptoCurrencyById("scroll_sepolia");
@@ -22,10 +20,6 @@ export const fakeToken: ERC20Token = [
2220
false, // delisted
2321
];
2422

25-
export const localCALHash =
26-
localTokensHashesByChainId[
27-
currency.ethereumLikeInfo!.chainId as keyof typeof localTokensHashesByChainId
28-
];
2923
export const getAccountShapeParameters: AccountShapeInfo = {
3024
address: "0xkvn",
3125
currency,
@@ -34,19 +28,12 @@ export const getAccountShapeParameters: AccountShapeInfo = {
3428
index: 0,
3529
};
3630

31+
//TODO change implementation when new CryptoAssesStore implemented with DADA
3732
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
38-
setCryptoAssetsStore({
39-
findTokenById: (id: string) => {
40-
if (id === "scroll_sepolia/erc20/mock_usdt") {
41-
return usdtTokenData;
42-
} else if (id === "scroll_sepolia/erc20/new_token_mock") {
43-
return newTokenData;
44-
}
45-
46-
return undefined;
47-
},
48-
findTokenByAddressInCurrency: (_address: string, _currencyId: string) => undefined,
49-
} as unknown as CryptoAssetsStore);
33+
setCryptoAssetsStoreForCoinFramework({
34+
findTokenById: legacyTokens.findTokenById,
35+
findTokenByAddressInCurrency: legacyTokens.findTokenByAddressInCurrency,
36+
} as CryptoAssetsStore);
5037

5138
export const TMUSDTTransaction = makeOperation({
5239
hash: "anyHash",

libs/coin-modules/coin-evm/src/__tests__/fixtures/common.fixtures.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ import { encodeNftId } from "@ledgerhq/coin-framework/nft/nftId";
1515
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
1616
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
1717
import { Account, DerivationMode, Operation, ProtoNFT, TokenAccount } from "@ledgerhq/types-live";
18+
import { setCryptoAssetsStore as setCryptoAssetsStoreForCoinFramework } from "@ledgerhq/coin-framework/crypto-assets/index";
19+
import * as legacyTokens from "@ledgerhq/cryptoassets/tokens";
20+
import { CryptoAssetsStore } from "@ledgerhq/types-live/lib/crypto-assets/type";
21+
22+
//TODO change implementation when new CryptoAssesStore implemented with DADA
23+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
24+
setCryptoAssetsStoreForCoinFramework({
25+
findTokenById: legacyTokens.findTokenById,
26+
findTokenByAddressInCurrency: legacyTokens.findTokenByAddressInCurrency,
27+
} as CryptoAssetsStore);
1828

1929
export const makeAccount = (
2030
address: string,

libs/coin-modules/coin-evm/src/__tests__/fixtures/synchronization.fixtures.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import BigNumber from "bignumber.js";
44
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
55
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
66
import { encodeSubOperationId } from "@ledgerhq/coin-framework/operation";
7-
import { setCryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/index";
8-
import { CryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/type";
7+
import { CryptoAssetsStore } from "@ledgerhq/types-live/lib/crypto-assets/type";
8+
import * as legacyTokens from "@ledgerhq/cryptoassets/tokens";
99
import * as logic from "../../logic";
1010
import { getCoinConfig } from "../../config";
11-
import usdCoinTokenData from "../../__fixtures__/ethereum-erc20-usd__coin.json";
12-
import usdTetherTokenData from "../../__fixtures__/ethereum-erc20-usd_tether__erc20_.json";
11+
import { getCryptoAssetsStore, setCryptoAssetsStore } from "../../cryptoAssetsStore";
1312
import {
1413
makeAccount,
1514
makeNft,
@@ -18,6 +17,12 @@ import {
1817
makeTokenAccount,
1918
} from "./common.fixtures";
2019

20+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
21+
setCryptoAssetsStore({
22+
findTokenById: legacyTokens.findTokenById,
23+
findTokenByAddressInCurrency: legacyTokens.findTokenByAddressInCurrency,
24+
} as CryptoAssetsStore);
25+
2126
jest.useFakeTimers().setSystemTime(new Date("2014-04-21"));
2227

2328
export const currency: CryptoCurrency = Object.freeze({
@@ -57,11 +62,13 @@ export const swapHistory = [
5762
},
5863
];
5964

65+
//Object.freeze(getTokenById("ethereum/erc20/usd__coin")),
66+
//Object.freeze(getTokenById("ethereum/erc20/usd_tether__erc20_")),
6067
export const tokenCurrencies = [
6168
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
62-
Object.freeze(usdCoinTokenData as unknown as TokenCurrency),
69+
getCryptoAssetsStore().findTokenById("ethereum/erc20/usd__coin") as TokenCurrency,
6370
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
64-
Object.freeze(usdTetherTokenData as unknown as TokenCurrency),
71+
getCryptoAssetsStore().findTokenById("ethereum/erc20/usd_tether__erc20_") as TokenCurrency,
6572
];
6673

6774
export const tokenAccount = {
@@ -99,20 +106,6 @@ export const coinOperations = [
99106
}),
100107
];
101108

102-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
103-
setCryptoAssetsStore({
104-
findTokenById: (id: string) => {
105-
if (id === "ethereum/erc20/usd__coin") {
106-
return usdCoinTokenData;
107-
} else if (id === "ethereum/erc20/usd_tether__erc20_") {
108-
return usdTetherTokenData;
109-
}
110-
111-
return undefined;
112-
},
113-
findTokenByAddressInCurrency: (_address: string, _currencyId: string) => undefined,
114-
} as unknown as CryptoAssetsStore);
115-
116109
export const tokenOperations = [
117110
makeOperation({
118111
hash: coinOperations[0].hash, // on purpose to make this token op a subOp of coinOp 1

libs/coin-modules/coin-evm/src/__tests__/unit/accounts.unit.test.ts

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import axios, { AxiosResponse } from "axios";
33
import { tokens as localTokensByChainId } from "@ledgerhq/cryptoassets/data/evm/index";
44
import { fromAccountRaw, toAccountRaw } from "@ledgerhq/coin-framework/serialization/account";
55
import { decodeTokenAccountId } from "@ledgerhq/coin-framework/account";
6-
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
7-
import { getCryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/index";
6+
import { __clearAllLists } from "@ledgerhq/cryptoassets/tokens";
87
import * as etherscanAPI from "../../network/explorer/etherscan";
98
import { __resetCALHash, getCALHash } from "../../logic";
109
import { getAccountShape } from "../../bridge/synchronization";
@@ -18,10 +17,6 @@ import {
1817
NTMTransaction,
1918
TMUSDTTransaction,
2019
} from "../fixtures/accounts.fixtures";
21-
import usdtTokenData from "../../__fixtures__/scroll_sepolia-erc20-mock_usdt.json";
22-
23-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
24-
const USDT_TOKEN = usdtTokenData as unknown as TokenCurrency;
2520

2621
jest.mock("axios");
2722
const mockedAxios = jest.mocked(axios);
@@ -37,6 +32,7 @@ describe("EVM Family", () => {
3732
beforeEach(() => {
3833
jest.restoreAllMocks();
3934

35+
__clearAllLists();
4036
__resetCALHash();
4137

4238
jest.spyOn(etherscanAPI?.default, "getLastOperations").mockImplementation(() =>
@@ -71,9 +67,6 @@ describe("EVM Family", () => {
7167
});
7268

7369
it("should add an account and find no token account without a preload first", async () => {
74-
const store = getCryptoAssetsStore();
75-
jest.spyOn(store, "findTokenById").mockImplementation((_id: string) => undefined);
76-
7770
const { subAccounts } = await getAccountShape(getAccountShapeParameters, {
7871
paginationConfig: {},
7972
});
@@ -82,15 +75,6 @@ describe("EVM Family", () => {
8275
});
8376

8477
it("should preload currency and add an account with 1 token account in it when there is nothing new in remote CAL", async () => {
85-
const store = getCryptoAssetsStore();
86-
jest.spyOn(store, "findTokenById").mockImplementation((id: string) => {
87-
if (id === "scroll_sepolia/erc20/mock_usdt") {
88-
return USDT_TOKEN;
89-
}
90-
91-
return undefined;
92-
});
93-
9478
mockedAxios.get.mockImplementationOnce(() => {
9579
throw new axios.AxiosError("", "", undefined, undefined, { status: 304 } as AxiosResponse);
9680
});
@@ -206,15 +190,6 @@ describe("EVM Family", () => {
206190
});
207191

208192
it("should preload again a currency and get the same account with 2 tokens accounts even with a failing CAL service", async () => {
209-
const store = getCryptoAssetsStore();
210-
jest.spyOn(store, "findTokenById").mockImplementation((id: string) => {
211-
if (id === "scroll_sepolia/erc20/mock_usdt") {
212-
return USDT_TOKEN;
213-
}
214-
215-
return undefined;
216-
});
217-
218193
mockedAxios.get.mockImplementationOnce(async (url, { params } = {}) => {
219194
if (
220195
url === "https://crypto-assets-service.api.ledger.com/v1/tokens" &&
@@ -265,15 +240,6 @@ describe("EVM Family", () => {
265240
});
266241

267242
it("should hydrate the tokens necessary to deserialize an account with 1 token account when there is nothing new in remote CAL", async () => {
268-
const store = getCryptoAssetsStore();
269-
jest.spyOn(store, "findTokenById").mockImplementation((id: string) => {
270-
if (id === "scroll_sepolia/erc20/mock_usdt") {
271-
return USDT_TOKEN;
272-
}
273-
274-
return undefined;
275-
});
276-
277243
const preloaded = await preload(currency);
278244
await hydrate(preloaded, currency);
279245
const account = await getAccountShape(getAccountShapeParameters, {
@@ -286,6 +252,7 @@ describe("EVM Family", () => {
286252
}));
287253
const serializedAccount = toAccountRaw(account as any);
288254

255+
__clearAllLists();
289256
await hydrate(preloaded, currency);
290257

291258
const deserializeAccount = fromAccountRaw(serializedAccount);
@@ -334,6 +301,7 @@ describe("EVM Family", () => {
334301
}));
335302
const serializedAccount = toAccountRaw(account as any);
336303

304+
__clearAllLists();
337305
await hydrate(preloaded, currency);
338306

339307
const deserializeAccount = fromAccountRaw(serializedAccount);

libs/coin-modules/coin-evm/src/__tests__/unit/adapters/etherscan.unit.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import BigNumber from "bignumber.js";
22
import { encodeAccountId, encodeTokenAccountId } from "@ledgerhq/coin-framework/account/index";
33
import { Operation } from "@ledgerhq/types-live";
44
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
5-
import { setCryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/index";
6-
import { CryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/type";
5+
import { CryptoAssetsStore } from "@ledgerhq/types-live/lib/crypto-assets/type";
76
import {
87
etherscanERC1155EventToOperations,
98
etherscanERC20EventToOperations,
@@ -21,6 +20,7 @@ import {
2120
import usdCoinTokenData from "../../../__fixtures__/ethereum-erc20-usd__coin.json";
2221
import outUsdCoinTokenData from "../../../__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-OUT-i0.json";
2322
import inUsdCoinTokenData from "../../../__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-IN-i0.json";
23+
import { setCryptoAssetsStore } from "../../../cryptoAssetsStore";
2424

2525
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
2626
const USD_COIN_TOKEN = usdCoinTokenData as unknown as TokenCurrency;
@@ -44,7 +44,7 @@ describe("EVM Family", () => {
4444
}
4545
return undefined;
4646
},
47-
} as unknown as CryptoAssetsStore);
47+
} as CryptoAssetsStore);
4848
});
4949

5050
it("should convert an etherscan-like smart contract creation operation (from their API) to a Ledger Live Operation", () => {

libs/coin-modules/coin-evm/src/__tests__/unit/adapters/ledger.unit.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import BigNumber from "bignumber.js";
22
import { Operation } from "@ledgerhq/types-live";
33
import { encodeAccountId, encodeTokenAccountId } from "@ledgerhq/coin-framework/account/index";
44
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
5-
import { setCryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/index";
6-
import { CryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/type";
5+
import { CryptoAssetsStore } from "@ledgerhq/types-live/lib/crypto-assets/type";
76
import {
87
ledgerERC1155EventToOperations,
98
ledgerERC20EventToOperations,
@@ -19,6 +18,7 @@ import {
1918
LedgerExplorerOperation,
2019
} from "../../../types";
2120
import usdCoinTokenData from "../../../__fixtures__/ethereum-erc20-usd__coin.json";
21+
import { setCryptoAssetsStore } from "../../../cryptoAssetsStore";
2222

2323
const accountId = encodeAccountId({
2424
type: "js",
@@ -742,7 +742,7 @@ describe("EVM Family", () => {
742742
? undefined
743743
: tokenCurrency;
744744
},
745-
} as unknown as CryptoAssetsStore);
745+
} as CryptoAssetsStore);
746746
});
747747

748748
it("should return an empty array for an unknown token", () => {

libs/coin-modules/coin-evm/src/__tests__/unit/api/explorer/etherscan.unit.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import axios from "axios";
33
import { delay } from "@ledgerhq/live-promise";
44
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
55
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
6-
import { setCryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/index";
7-
import { CryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/type";
6+
import { CryptoAssetsStore } from "@ledgerhq/types-live/lib/crypto-assets/type";
87
import { EtherscanLikeExplorerUsedIncorrectly } from "../../../../errors";
98
import * as ETHERSCAN_API from "../../../../network/explorer/etherscan";
109
import { makeAccount } from "../../../fixtures/common.fixtures";
@@ -23,13 +22,14 @@ import {
2322
etherscanOperationToOperations,
2423
} from "../../../../adapters";
2524
import { getCoinConfig } from "../../../../config";
25+
import { setCryptoAssetsStore } from "../../../../cryptoAssetsStore";
2626

2727
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
2828
setCryptoAssetsStore({
2929
findTokenByAddressInCurrency: (_address: string, _currencyId: string) => {
3030
return undefined;
3131
},
32-
} as unknown as CryptoAssetsStore);
32+
} as CryptoAssetsStore);
3333

3434
jest.mock("axios");
3535
jest.mock("@ledgerhq/live-promise");

libs/coin-modules/coin-evm/src/__tests__/unit/api/explorer/ledger.unit.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { delay } from "@ledgerhq/live-promise";
66
import { getEnv, setEnv } from "@ledgerhq/live-env";
77
import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
88
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
9-
import { setCryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/index";
10-
import { CryptoAssetsStore } from "@ledgerhq/coin-framework/crypto-assets/type";
9+
import { CryptoAssetsStore } from "@ledgerhq/types-live/lib/crypto-assets/type";
1110
import { LedgerExplorerUsedIncorrectly } from "../../../../errors";
1211
import * as LEDGER_API from "../../../../network/explorer/ledger";
1312
import {
@@ -18,6 +17,7 @@ import {
1817
} from "../../../fixtures/explorer/ledger.fixtures";
1918
import { getCoinConfig } from "../../../../config";
2019
import tokenData from "../../../../__fixtures__/ethereum-erc20-usd__coin.json";
20+
import { setCryptoAssetsStore } from "../../../../cryptoAssetsStore";
2121

2222
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
2323
setCryptoAssetsStore({
@@ -27,7 +27,7 @@ setCryptoAssetsStore({
2727
}
2828
return undefined;
2929
},
30-
} as unknown as CryptoAssetsStore);
30+
} as CryptoAssetsStore);
3131

3232
jest.mock("axios");
3333
jest.mock("@ledgerhq/live-promise");

0 commit comments

Comments
 (0)