@ledgerhq/coin-aptos
Version:
Ledger Aptos Coin integration
66 lines • 2.46 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ts_sdk_1 = require("@aptos-labs/ts-sdk");
const api_1 = require("../../api");
const config_1 = __importDefault(require("../../config"));
jest.mock("@aptos-labs/ts-sdk");
let mockedAptos;
jest.mock("../../config", () => ({
setCoinConfig: jest.fn(),
}));
const mockAptosConfig = {};
describe("createApi", () => {
it("should set the coin config value", () => {
const setCoinConfigSpy = jest.spyOn(config_1.default, "setCoinConfig");
(0, api_1.createApi)(mockAptosConfig);
const config = setCoinConfigSpy.mock.calls[0][0]();
expect(setCoinConfigSpy).toHaveBeenCalled();
expect(config).toEqual(expect.objectContaining({
...mockAptosConfig,
status: { type: "active" },
}));
});
it("should return an API object with alpaca api methods", () => {
const api = (0, api_1.createApi)(mockAptosConfig);
// Check that methods are set with what we expect
expect(api.broadcast).toBeDefined();
expect(api.combine).toBeDefined();
expect(api.craftTransaction).toBeDefined();
expect(api.estimateFees).toBeDefined();
expect(api.getBalance).toBeDefined();
expect(api.lastBlock).toBeDefined();
expect(api.listOperations).toBeDefined();
});
});
describe("lastBlock", () => {
beforeEach(() => {
mockedAptos = jest.mocked(ts_sdk_1.Aptos);
});
afterEach(() => {
jest.resetAllMocks();
});
it("returns the last block information", async () => {
mockedAptos.mockImplementation(() => ({
getLedgerInfo: jest.fn().mockReturnValue({
block_height: "123",
}),
getBlockByHeight: jest.fn().mockReturnValue({
block_height: "123",
block_hash: "123hash",
block_timestamp: "1746021098623892",
first_version: "1",
last_version: "1",
}),
}));
const api = (0, api_1.createApi)(mockAptosConfig);
expect(await api.lastBlock()).toStrictEqual({
height: 123,
hash: "123hash",
time: new Date(1746021098623892 / 1_000),
});
});
});
//# sourceMappingURL=index.test.js.map