@ledgerhq/coin-aptos
Version:
Ledger Aptos Coin integration
63 lines • 3.29 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const getBalances_1 = require("../../logic/getBalances");
const constants_1 = require("../../constants");
describe("getBalance", () => {
it("should return balance with value 10", async () => {
const mockAptosClient = {
getBalances: jest.fn().mockResolvedValue([{ contractAddress: constants_1.APTOS_ASSET_ID, amount: 10n }]),
};
const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906";
const balances = await (0, getBalances_1.getBalances)(mockAptosClient, accountAddress);
expect(balances).toStrictEqual([{ value: 10n, asset: { type: "native" } }]);
});
it("should return empty array when no contract_address and no data", async () => {
const mockAptosClient = {
getBalances: jest.fn().mockResolvedValue([]),
};
const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906";
const balances = await (0, getBalances_1.getBalances)(mockAptosClient, accountAddress);
expect(balances).toStrictEqual([]);
});
it("should return balance with 'native' contract_address (APTOS_ASSET_ID)", async () => {
const mockAptosClient = {
getBalances: jest.fn().mockResolvedValue([{ contractAddress: constants_1.APTOS_ASSET_ID, amount: 10n }]),
};
const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906";
const balances = await (0, getBalances_1.getBalances)(mockAptosClient, accountAddress);
expect(balances).toStrictEqual([{ value: 10n, asset: { type: "native" } }]);
});
it("should return token balance when contract_address is a coin token", async () => {
const TOKEN_ASSET_ID = "0x1::my_token::Token";
const mockAptosClient = {
getBalances: jest.fn().mockResolvedValue([{ contractAddress: TOKEN_ASSET_ID, amount: 25n }]),
};
const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906";
const balances = await (0, getBalances_1.getBalances)(mockAptosClient, accountAddress);
expect(balances).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";
const mockAptosClient = {
getBalances: jest.fn().mockResolvedValue([{ contractAddress: TOKEN_ASSET_ID, amount: 25n }]),
};
const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906";
const balances = await (0, getBalances_1.getBalances)(mockAptosClient, accountAddress);
expect(balances).toStrictEqual([
{
value: 25n,
asset: {
type: "token",
contractAddress: TOKEN_ASSET_ID,
standard: constants_1.TOKEN_TYPE.FUNGIBLE_ASSET,
},
},
]);
});
});
//# sourceMappingURL=getBalances.test.js.map