UNPKG

postchain-client

Version:

Client library for accessing a Postchain node through REST.

62 lines 3.43 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { CONFIGURED_POLL_COUNT, exampleOperation, mockTransactionReceipts, } from "../../common/mocks"; import { server } from "../../../mocks/servers"; import { errorHandler } from "../../../mocks/handlers"; import * as utils from "../../../src/blockchainClient/utils"; import { getTestsClient } from "../../common/setups"; describe("measures polling interval", () => { beforeAll(() => __awaiter(void 0, void 0, void 0, function* () { server.listen(); })); beforeEach(() => { jest.clearAllMocks(); }); afterEach(() => { server.resetHandlers(); jest.restoreAllMocks(); }); it("of sendTransaction for Unknown status", () => __awaiter(void 0, void 0, void 0, function* () { const clientWithConfiguredDappPolling = yield getTestsClient({ dappStatusPolling: utils.setStatusPolling({ interval: 1000, count: CONFIGURED_POLL_COUNT, }), }); const getTransactionStatusSpy = jest.spyOn(clientWithConfiguredDappPolling, "getTransactionStatus"); jest.spyOn(utils, "getAnchoringClientAndSystemChainRid").mockResolvedValue({ anchoringClient: clientWithConfiguredDappPolling, systemAnchoringChainBridString: clientWithConfiguredDappPolling.config.blockchainRid, }); server.use(errorHandler.statusUnknown); const promise = clientWithConfiguredDappPolling.sendTransaction(exampleOperation); yield utils.sleep(100); expect(getTransactionStatusSpy).toHaveBeenCalledTimes(1); yield utils.sleep(1000); expect(getTransactionStatusSpy).toHaveBeenCalledTimes(2); yield utils.sleep(1000); expect(getTransactionStatusSpy).toHaveBeenCalledTimes(3); expect(yield promise).toEqual(mockTransactionReceipts.unknown); expect(getTransactionStatusSpy).toHaveBeenCalledTimes(CONFIGURED_POLL_COUNT); }), 10000); it("sendTransaction receives Waiting status after reaching default (20) poll count", () => __awaiter(void 0, void 0, void 0, function* () { const client = yield getTestsClient(); const getTransactionStatusSpy = jest.spyOn(client, "getTransactionStatus"); jest.spyOn(utils, "getAnchoringClientAndSystemChainRid").mockResolvedValue({ anchoringClient: client, systemAnchoringChainBridString: client.config.blockchainRid, }); server.use(errorHandler.statusWaiting); const response = yield client.sendTransaction(exampleOperation); expect(response).toEqual(mockTransactionReceipts.waiting); expect(getTransactionStatusSpy).toHaveBeenCalledTimes(20); }), 20000); }); //# sourceMappingURL=statusPollIntervals.test.js.map