UNPKG

@ledgerhq/coin-tron

Version:
58 lines 2.32 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const msw_1 = require("msw"); const node_1 = require("msw/node"); const types_fixture_1 = require("./types.fixture"); const config_1 = __importDefault(require("../config")); const _1 = require("."); const TRON_BASE_URL_TEST = "https://httpbin.org"; const handlers = [ msw_1.http.get(`${TRON_BASE_URL_TEST}/v1/accounts/:addr/transactions`, () => { // const url = new URL(request.url); // const _ = url.searchParams.get("get_detail"); return msw_1.HttpResponse.json(types_fixture_1.TRANSACTION_FIXTURE); }), msw_1.http.get(`${TRON_BASE_URL_TEST}/v1/accounts/:addr/transactions/trc20`, () => { // const url = new URL(request.url); // const _ = url.searchParams.get("get_detail"); return msw_1.HttpResponse.json(types_fixture_1.TRC20_FIXTURE); }), msw_1.http.get(`${TRON_BASE_URL_TEST}/wallet/gettransactioninfobyid`, ({ request }) => { const url = new URL(request.url); const value = url.searchParams.get("value") ?? "UNKNOWN"; return msw_1.HttpResponse.json((0, types_fixture_1.TRANSACTION_DETAIL_FIXTURE)(value)); }), ]; const mockServer = (0, node_1.setupServer)(...handlers); describe("fetchTronAccountTxs", () => { beforeAll(() => { config_1.default.setCoinConfig(() => ({ status: { type: "active", }, explorer: { url: TRON_BASE_URL_TEST, }, })); mockServer.listen(); }); beforeEach(() => { mockServer.resetHandlers(); }); afterAll(() => { mockServer.close(); }); it("convert correctly operations from the blockchain", async () => { // WHEN const results = await (0, _1.fetchTronAccountTxs)("ADDRESS", txs => txs.length < 100, {}); // THEN const tx = results.find(tx => tx.blockHeight === 62258698); expect(tx).toBeDefined(); expect(tx.from).toEqual("TQ7pF3NTDL2Tjz5rdJ6ECjQWjaWHpLZJMH"); expect(tx.to).toEqual("TAVrrARNdnjHgCGMQYeQV7hv4PSu7mVsMj"); }); }); //# sourceMappingURL=index.test.js.map