UNPKG

@ledgerhq/coin-aptos

Version:
81 lines 3.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const network_1 = require("../../network"); const constants_1 = require("../../constants"); const api_1 = require("../../api"); jest.mock("@aptos-labs/ts-sdk"); let mockedAptosApi; jest.mock("../../network"); jest.mock("../../config", () => ({ setCoinConfig: jest.fn(), })); const mockAptosConfig = {}; describe("getBalance", () => { beforeEach(() => { mockedAptosApi = jest.mocked(network_1.AptosAPI); }); afterEach(() => { jest.resetAllMocks(); }); it("should return balance with value 10", async () => { mockedAptosApi.mockImplementation(() => ({ getBalances: jest.fn().mockResolvedValue([{ contractAddress: constants_1.APTOS_ASSET_ID, amount: 10n }]), })); const api = (0, api_1.createApi)(mockAptosConfig); const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906"; expect(await api.getBalance(accountAddress)).toStrictEqual([ { value: 10n, asset: { type: "native" } }, ]); }); it("should return empty array when no contract_address and no data", async () => { mockedAptosApi.mockImplementation(() => ({ getBalances: jest.fn().mockResolvedValue([]), })); const accountAddress = "0xno_contract_and_no_data"; const api = (0, api_1.createApi)(mockAptosConfig); expect(await api.getBalance(accountAddress)).toStrictEqual([]); }); it("should return balance with 'native' contract_address (APTOS_ASSET_ID)", async () => { mockedAptosApi.mockImplementation(() => ({ getBalances: jest.fn().mockResolvedValue([{ contractAddress: constants_1.APTOS_ASSET_ID, amount: 15n }]), })); const api = (0, api_1.createApi)(mockAptosConfig); const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906"; expect(await api.getBalance(accountAddress)).toStrictEqual([ { value: 15n, asset: { type: "native" } }, ]); }); it("should return token balance when contract_address is a coin token", async () => { const TOKEN_ASSET_ID = "0x1::my_token::Token"; mockedAptosApi.mockImplementation(() => ({ getBalances: jest.fn().mockResolvedValue([{ contractAddress: TOKEN_ASSET_ID, amount: 25n }]), })); const api = (0, api_1.createApi)(mockAptosConfig); const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906"; expect(await api.getBalance(accountAddress)).toStrictEqual([ { value: 25n, asset: { type: "token", contractAddress: TOKEN_ASSET_ID, standard: constants_1.TOKEN_TYPE.COIN }, }, ]); }); it("should return token balance when contract_address is a fungible_asset token", async () => { const TOKEN_ASSET_ID = "0x1"; mockedAptosApi.mockImplementation(() => ({ getBalances: jest.fn().mockResolvedValue([{ contractAddress: TOKEN_ASSET_ID, amount: 25n }]), })); const api = (0, api_1.createApi)(mockAptosConfig); const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906"; expect(await api.getBalance(accountAddress)).toStrictEqual([ { value: 25n, asset: { type: "token", contractAddress: TOKEN_ASSET_ID, standard: constants_1.TOKEN_TYPE.FUNGIBLE_ASSET, }, }, ]); }); }); //# sourceMappingURL=getBalance.unit.test.js.map