UNPKG

postchain-client

Version:

Client library for accessing a Postchain node through REST.

51 lines 2.91 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 { server } from "../../../mocks/servers"; import { exampleOperation, mockSignatureProvider } from "../../common/mocks"; import { ChainConfirmationLevel, TransactionEvent } from "../../../src/blockchainClient/enums"; import { getTestsClient } from "../../common/setups"; import { Web3PromiEvent } from "../../../src/promiEvent/promiEvents"; let client; describe("signAndSendUniqueTransaction emits events", () => { beforeAll(() => __awaiter(void 0, void 0, void 0, function* () { server.listen(); client = yield getTestsClient(); })); afterEach(() => { server.resetHandlers(); jest.restoreAllMocks(); jest.clearAllMocks(); }); it("emits all expected transaction events in the correct order", () => __awaiter(void 0, void 0, void 0, function* () { const mockSendTransactionEvent = new Web3PromiEvent(resolve => { setTimeout(() => { const mockReceipt = {}; mockSendTransactionEvent.emit(TransactionEvent.DappReceived, mockReceipt); mockSendTransactionEvent.emit(TransactionEvent.DappConfirmed, mockReceipt); mockSendTransactionEvent.emit(TransactionEvent.ClusterAnchoringConfirmation, mockReceipt); mockSendTransactionEvent.emit(TransactionEvent.SystemAnchoringConfirmation, mockReceipt); resolve(mockReceipt); }, 10); }); jest.spyOn(client, "sendTransaction").mockImplementation(() => mockSendTransactionEvent); const promiEvent = client.signAndSendUniqueTransaction(exampleOperation, mockSignatureProvider, true, undefined, ChainConfirmationLevel.SystemAnchoring); const promiEventSpy = jest.spyOn(promiEvent, "emit"); yield promiEvent; const emittedEvents = promiEventSpy.mock.calls.map(call => call[0]); expect(emittedEvents).toEqual([ TransactionEvent.Signed, TransactionEvent.DappReceived, TransactionEvent.DappConfirmed, TransactionEvent.ClusterAnchoringConfirmation, TransactionEvent.SystemAnchoringConfirmation, ]); })); }); //# sourceMappingURL=signAndSendUniqueTransactionPromiEvents.test.js.map