UNPKG

@ledgerhq/coin-algorand

Version:
93 lines 4.01 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const state_1 = require("@ledgerhq/cryptoassets/state"); const synchronization_1 = require("./synchronization"); const api_1 = __importDefault(require("./api")); const bignumber_js_1 = __importDefault(require("bignumber.js")); describe("Synchronization", () => { beforeAll(() => { (0, state_1.setCryptoAssetsStore)({ findTokenById: async (id) => { switch (id) { case "algorand/asa/1": return { id, ticker: "USDC" }; case "algorand/asa/2": return { id, ticker: "USDT" }; default: return undefined; } }, }); }); describe("getAccountShape", () => { it("preserves the order of existing token accounts", async () => { jest.spyOn(api_1.default, "getAccount").mockResolvedValue({ balance: new bignumber_js_1.default(10), assets: [ { assetId: "1", balance: new bignumber_js_1.default(4) }, { assetId: "2", balance: new bignumber_js_1.default(5) }, ], }); jest.spyOn(api_1.default, "getAccountTransactions").mockResolvedValue([]); const result = await (0, synchronization_1.getAccountShape)({ address: "address", initialAccount: { subAccounts: [ { id: "js:2:algorand:address:+2", type: "TokenAccount", token: { id: "algorand/asa/2", ticker: "USDT" }, }, { id: "js:2:algorand:address:+1", type: "TokenAccount", token: { id: "algorand/asa/1", ticker: "USDC" }, }, ], }, currency: { id: "algorand" }, derivationMode: "", }, {}); expect(result).toMatchObject({ id: "js:2:algorand:address:", xpub: "address", balance: new bignumber_js_1.default(10), subAccounts: [ expect.objectContaining({ id: "js:2:algorand:address:+2" }), expect.objectContaining({ id: "js:2:algorand:address:+1" }), ], }); }); it("uses the order of input assets if no token accounts exist yet", async () => { jest.spyOn(api_1.default, "getAccount").mockResolvedValue({ balance: new bignumber_js_1.default(10), assets: [ { assetId: "1", balance: new bignumber_js_1.default(4) }, { assetId: "2", balance: new bignumber_js_1.default(5) }, ], }); jest.spyOn(api_1.default, "getAccountTransactions").mockResolvedValue([]); const result = await (0, synchronization_1.getAccountShape)({ address: "address", initialAccount: { subAccounts: [], }, currency: { id: "algorand" }, derivationMode: "", }, {}); expect(result).toMatchObject({ id: "js:2:algorand:address:", xpub: "address", balance: new bignumber_js_1.default(10), subAccounts: [ expect.objectContaining({ id: "js:2:algorand:address:+1" }), expect.objectContaining({ id: "js:2:algorand:address:+2" }), ], }); }); }); }); //# sourceMappingURL=synchronization.test.js.map