UNPKG

@ledgerhq/coin-tron

Version:
75 lines 3.11 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const logic_1 = require("../logic"); const config_1 = __importDefault(require("../config")); const _1 = require("."); jest.mock("../config", () => ({ setCoinConfig: jest.fn(), })); jest.mock("../logic", () => ({ broadcast: jest.fn(), combine: jest.fn(), craftTransaction: jest.fn(), estimateFees: jest.fn(), getBalance: jest.fn(), listOperations: jest.fn(), lastBlock: jest.fn(), })); describe("createApi", () => { const mockTronConfig = { explorer: { url: "iamaurl" } }; let setCoinConfigSpy; it("should set the coin config value", () => { setCoinConfigSpy = jest.spyOn(config_1.default, "setCoinConfig"); (0, _1.createApi)(mockTronConfig); const config = setCoinConfigSpy.mock.calls[0][0](); expect(setCoinConfigSpy).toHaveBeenCalled(); expect(config).toEqual(expect.objectContaining({ ...mockTronConfig, status: { type: "active" }, })); }); it("should return an API object with alpaca api methods", () => { const api = (0, _1.createApi)(mockTronConfig); // Check that methods are set with what we expect expect(api.broadcast).toBe(logic_1.broadcast); expect(api.combine).toBe(logic_1.combine); expect(api.craftTransaction).toBe(logic_1.craftTransaction); expect(api.estimateFees).toBe(logic_1.estimateFees); expect(api.getBalance).toBe(logic_1.getBalance); expect(api.lastBlock).toBe(logic_1.lastBlock); expect(api.listOperations).toBe(logic_1.listOperations); }); it("should pass parameters well", async () => { const api = (0, _1.createApi)(mockTronConfig); const intent = { type: "send", sender: "sender", recipient: "recipient", amount: BigInt(10), asset: { standard: "trc10", tokenId: "1002000", }, }; // Simulate calling all methods await api.broadcast("transaction"); api.combine("tx", "signature", "pubkey"); await api.craftTransaction(intent); await api.estimateFees(intent); await api.getBalance("address"); await api.lastBlock(); await api.listOperations("address", {}); // Test that each of the methods was called with correct arguments expect(logic_1.broadcast).toHaveBeenCalledWith("transaction"); expect(logic_1.combine).toHaveBeenCalledWith("tx", "signature", "pubkey"); expect(logic_1.estimateFees).toHaveBeenCalledWith(intent); expect(logic_1.craftTransaction).toHaveBeenCalledWith(intent); expect(logic_1.getBalance).toHaveBeenCalledWith("address"); expect(logic_1.lastBlock).toHaveBeenCalled(); expect(logic_1.listOperations).toHaveBeenCalledWith("address", {}); }); }); //# sourceMappingURL=index.test.js.map