@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
40 lines • 2.13 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const currencies_1 = require("../currencies");
const account_1 = require("@ledgerhq/coin-framework/mocks/account");
const serialization_1 = require("./serialization");
const version_1 = require("../wallet-api/version");
const constants_1 = require("../wallet-api/constants");
const index_1 = require("@ledgerhq/coin-framework/crypto-assets/index");
const solana_spl_epjfwdd5aufqssqem2qn1xzybapc8g4weggkzwytdt1v_json_1 = __importDefault(require("../__fixtures__/solana-spl-epjfwdd5aufqssqem2qn1xzybapc8g4weggkzwytdt1v.json"));
(0, version_1.setWalletAPIVersion)(constants_1.WALLET_API_VERSION);
(0, currencies_1.setSupportedCurrencies)(["solana"]);
const Solana = (0, currencies_1.getCryptoCurrencyById)("solana");
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const USDC = solana_spl_epjfwdd5aufqssqem2qn1xzybapc8g4weggkzwytdt1v_json_1.default;
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
(0, index_1.setCryptoAssetsStore)({
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 = (0, account_1.genAccount)("mocked-account-1", { currency: Solana });
const tokenAcc = (0, account_1.genTokenAccount)(1, acc, USDC);
tokenAcc.state = "initialized";
acc.subAccounts = [tokenAcc];
const accRaw = (0, serialization_1.toAccountRaw)(acc);
expect(accRaw.subAccounts?.[0]?.state).toBe("initialized");
const deserializedAcc = (0, serialization_1.fromAccountRaw)(accRaw);
expect(deserializedAcc.subAccounts?.[0]?.state).toBe("initialized");
});
});
//# sourceMappingURL=serialization.test.js.map