@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
35 lines • 1.79 kB
JavaScript
import { getCryptoCurrencyById, setSupportedCurrencies } from "../currencies";
import { genAccount, genTokenAccount } from "@ledgerhq/coin-framework/mocks/account";
import { toAccountRaw, fromAccountRaw } from "./serialization";
import { setWalletAPIVersion } from "../wallet-api/version";
import { WALLET_API_VERSION } from "../wallet-api/constants";
import { setCryptoAssetsStore as setCryptoAssetsStoreForCoinFramework } from "@ledgerhq/coin-framework/crypto-assets/index";
import solanaSplTokenData from "../__fixtures__/solana-spl-epjfwdd5aufqssqem2qn1xzybapc8g4weggkzwytdt1v.json";
setWalletAPIVersion(WALLET_API_VERSION);
setSupportedCurrencies(["solana"]);
const Solana = getCryptoCurrencyById("solana");
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const USDC = solanaSplTokenData;
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
setCryptoAssetsStoreForCoinFramework({
findTokenById: (id) => {
if (id === "solana/spl/epjfwdd5aufqssqem2qn1xzybapc8g4weggkzwytdt1v") {
return USDC;
}
return undefined;
},
findTokenByAddressInCurrency: (_, __) => undefined,
});
describe("serialization", () => {
test("TokenAccount extra fields should be serialized/deserialized", () => {
const acc = genAccount("mocked-account-1", { currency: Solana });
const tokenAcc = genTokenAccount(1, acc, USDC);
tokenAcc.state = "initialized";
acc.subAccounts = [tokenAcc];
const accRaw = toAccountRaw(acc);
expect(accRaw.subAccounts?.[0]?.state).toBe("initialized");
const deserializedAcc = fromAccountRaw(accRaw);
expect(deserializedAcc.subAccounts?.[0]?.state).toBe("initialized");
});
});
//# sourceMappingURL=serialization.test.js.map