From a58d455931d97fb132dbca334d1adeea82752f21 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Wed, 8 Nov 2023 16:25:30 -0800 Subject: [PATCH] Add tests --- package-lock.json | 188 ++++++++---------- .../src/build/build-subscribe-events.test.js | 26 +++ .../sdk/src/build/build-subscription.test.js | 20 ++ packages/sdk/src/interaction/interaction.js | 2 +- packages/transport-http/src/send-http.js | 2 +- ...ibe-events.js => send-subscribe-events.js} | 17 +- .../src/send-subscribe-events.test.js | 102 ++++++++++ 7 files changed, 238 insertions(+), 119 deletions(-) create mode 100644 packages/sdk/src/build/build-subscribe-events.test.js create mode 100644 packages/sdk/src/build/build-subscription.test.js rename packages/transport-http/src/{subscribe-events.js => send-subscribe-events.js} (76%) create mode 100644 packages/transport-http/src/send-subscribe-events.test.js diff --git a/package-lock.json b/package-lock.json index a99a790d8..a1597fc80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19575,19 +19575,19 @@ }, "packages/config": { "name": "@onflow/config", - "version": "1.2.0-typescript.0", + "version": "1.2.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6", - "@onflow/util-actor": "^1.3.0-typescript.0", - "@onflow/util-invariant": "^1.2.0-typescript.0", - "@onflow/util-logger": "^1.3.0-typescript.0", + "@onflow/util-actor": "^1.3.0", + "@onflow/util-invariant": "^1.2.0", + "@onflow/util-logger": "^1.3.0", "eslint": "^8.34.0", "eslint-plugin-jsdoc": "^40.0.0" }, "devDependencies": { "@babel/preset-typescript": "^7.22.11", - "@onflow/fcl-bundle": "^1.4.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", "@types/estree": "^1.0.1", "@types/jest": "^29.5.4", "@typescript-eslint/eslint-plugin": "^6.5.0", @@ -19705,27 +19705,27 @@ }, "packages/fcl": { "name": "@onflow/fcl", - "version": "1.8.0-typescript.0", + "version": "1.8.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6", - "@onflow/config": "^1.2.0-typescript.0", + "@onflow/config": "^1.2.0", "@onflow/interaction": "0.0.11", - "@onflow/rlp": "^1.2.0-typescript.0", - "@onflow/sdk": "^1.3.0-typescript.0", - "@onflow/types": "^1.2.0-typescript.0", - "@onflow/util-actor": "^1.3.0-typescript.0", - "@onflow/util-address": "^1.2.0-typescript.0", - "@onflow/util-invariant": "^1.2.0-typescript.0", - "@onflow/util-logger": "^1.3.0-typescript.0", + "@onflow/rlp": "^1.2.0", + "@onflow/sdk": "^1.3.0", + "@onflow/types": "^1.2.0", + "@onflow/util-actor": "^1.3.0", + "@onflow/util-address": "^1.2.0", + "@onflow/util-invariant": "^1.2.0", + "@onflow/util-logger": "^1.3.0", "@onflow/util-semver": "^1.0.0", - "@onflow/util-template": "^1.2.0-typescript.0", - "@onflow/util-uid": "^1.2.0-typescript.0", + "@onflow/util-template": "^1.2.0", + "@onflow/util-uid": "^1.2.0", "cross-fetch": "^3.1.6" }, "devDependencies": { - "@onflow/fcl-bundle": "^1.4.0-typescript.0", - "@onflow/typedefs": "^1.2.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", + "@onflow/typedefs": "^1.2.0", "@types/estree": "^1.0.1", "@types/node": "^18.13.0", "eslint": "^8.35.0", @@ -19761,7 +19761,7 @@ }, "packages/fcl-bundle": { "name": "@onflow/fcl-bundle", - "version": "1.4.0-typescript.0", + "version": "1.4.0", "license": "Apache-2.0", "dependencies": { "@babel/plugin-transform-runtime": "^7.18.2", @@ -19791,25 +19791,25 @@ }, "packages/fcl-wc": { "name": "@onflow/fcl-wc", - "version": "5.0.0-typescript.0", + "version": "5.0.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.9", - "@onflow/config": "^1.2.0-typescript.0", - "@onflow/util-invariant": "^1.2.0-typescript.0", - "@onflow/util-logger": "^1.3.0-typescript.0", + "@onflow/config": "^1.2.0", + "@onflow/util-invariant": "^1.2.0", + "@onflow/util-logger": "^1.3.0", "@walletconnect/modal": "^2.4.7", "@walletconnect/sign-client": "^2.8.1", "@walletconnect/types": "^2.8.1", "@walletconnect/utils": "^2.8.1" }, "devDependencies": { - "@onflow/fcl-bundle": "^1.4.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", "better-sqlite3": "^7.6.2", "jest": "^29.5.0" }, "peerDependencies": { - "@onflow/fcl": "^1.8.0-typescript.0" + "@onflow/fcl": "^1.8.0" } }, "packages/fcl/node_modules/eslint-plugin-jsdoc": { @@ -20348,7 +20348,7 @@ }, "packages/rlp": { "name": "@onflow/rlp", - "version": "1.2.0-typescript.0", + "version": "1.2.0", "license": "MPL-2.0", "dependencies": { "@babel/runtime": "^7.18.6", @@ -20356,7 +20356,7 @@ }, "devDependencies": { "@babel/preset-typescript": "^7.22.5", - "@onflow/fcl-bundle": "^1.4.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", "@types/jest": "^29.5.3", "@typescript-eslint/eslint-plugin": "^6.4.0", "@typescript-eslint/parser": "^6.4.0", @@ -20454,25 +20454,25 @@ }, "packages/sdk": { "name": "@onflow/sdk", - "version": "1.3.0-typescript.0", + "version": "1.3.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6", - "@onflow/config": "^1.2.0-typescript.0", - "@onflow/rlp": "^1.2.0-typescript.0", - "@onflow/transport-http": "^1.8.0-typescript.0", - "@onflow/util-actor": "^1.3.0-typescript.0", - "@onflow/util-address": "^1.2.0-typescript.0", - "@onflow/util-invariant": "^1.2.0-typescript.0", - "@onflow/util-logger": "^1.3.0-typescript.0", - "@onflow/util-template": "^1.2.0-typescript.0", + "@onflow/config": "^1.2.0", + "@onflow/rlp": "^1.2.0", + "@onflow/transport-http": "^1.8.0", + "@onflow/util-actor": "^1.3.0", + "@onflow/util-address": "^1.2.0", + "@onflow/util-invariant": "^1.2.0", + "@onflow/util-logger": "^1.3.0", + "@onflow/util-template": "^1.2.0", "deepmerge": "^4.2.2", "sha3": "^2.1.4", "uuid": "^9.0.1" }, "devDependencies": { - "@onflow/fcl-bundle": "^1.4.0-typescript.0", - "@onflow/typedefs": "^1.2.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", + "@onflow/typedefs": "^1.2.0", "eslint": "^8.35.0", "eslint-plugin-jsdoc": "^40.0.1", "jest": "^29.5.0", @@ -20560,21 +20560,21 @@ }, "packages/transport-grpc": { "name": "@onflow/transport-grpc", - "version": "1.3.0-typescript.0", + "version": "1.3.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6", "@improbable-eng/grpc-web": "^0.14.0", "@improbable-eng/grpc-web-node-http-transport": "^0.14.0", "@onflow/protobuf": "^1.2.1", - "@onflow/rlp": "^1.2.0-typescript.0", - "@onflow/util-address": "^1.2.0-typescript.0", - "@onflow/util-invariant": "^1.2.0-typescript.0", - "@onflow/util-template": "^1.2.0-typescript.0" + "@onflow/rlp": "^1.2.0", + "@onflow/util-address": "^1.2.0", + "@onflow/util-invariant": "^1.2.0", + "@onflow/util-template": "^1.2.0" }, "devDependencies": { - "@onflow/fcl-bundle": "^1.4.0-typescript.0", - "@onflow/sdk": "^1.3.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", + "@onflow/sdk": "^1.3.0", "jest": "^29.5.0" } }, @@ -20602,34 +20602,34 @@ }, "packages/transport-http": { "name": "@onflow/transport-http", - "version": "1.8.0-typescript.0", + "version": "1.8.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6", - "@onflow/util-address": "^1.2.0-typescript.0", - "@onflow/util-invariant": "^1.2.0-typescript.0", - "@onflow/util-logger": "^1.3.0-typescript.0", - "@onflow/util-template": "^1.2.0-typescript.0", + "@onflow/util-address": "^1.2.0", + "@onflow/util-invariant": "^1.2.0", + "@onflow/util-logger": "^1.3.0", + "@onflow/util-template": "^1.2.0", "abort-controller": "^3.0.0", "cross-fetch": "^3.1.6" }, "devDependencies": { - "@onflow/fcl-bundle": "^1.4.0-typescript.0", - "@onflow/rlp": "^1.2.0-typescript.0", - "@onflow/sdk": "^1.3.0-typescript.0", - "@onflow/types": "^1.2.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", + "@onflow/rlp": "^1.2.0", + "@onflow/sdk": "^1.3.0", + "@onflow/types": "^1.2.0", "jest": "^29.5.0" } }, "packages/typedefs": { "name": "@onflow/typedefs", - "version": "1.2.0-typescript.0", + "version": "1.2.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6" }, "devDependencies": { - "@onflow/fcl-bundle": "^1.4.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", "@types/node": "^18.13.0", "eslint": "^8.33.0", "eslint-plugin-jsdoc": "^39.7.5", @@ -20652,15 +20652,15 @@ }, "packages/types": { "name": "@onflow/types", - "version": "1.2.0-typescript.0", + "version": "1.2.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6", - "@onflow/util-logger": "^1.3.0-typescript.0" + "@onflow/util-logger": "^1.3.0" }, "devDependencies": { "@babel/preset-typescript": "^7.22.5", - "@onflow/fcl-bundle": "^1.4.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", "@types/jest": "^29.5.3", "@typescript-eslint/eslint-plugin": "^6.4.0", "@typescript-eslint/parser": "^6.4.0", @@ -20682,21 +20682,6 @@ "node": ">=16" } }, - "packages/types/node_modules/@onflow/util-logger": { - "version": "1.3.0", - "license": "Apache-2.0", - "dependencies": { - "@babel/runtime": "^7.18.6" - }, - "peerDependencies": { - "@onflow/util-config": ">1.1.1" - }, - "peerDependenciesMeta": { - "@onflow/util-config": { - "optional": true - } - } - }, "packages/types/node_modules/comment-parser": { "version": "1.4.0", "dev": true, @@ -20773,7 +20758,7 @@ }, "packages/util-actor": { "name": "@onflow/util-actor", - "version": "1.3.0-typescript.0", + "version": "1.3.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6", @@ -20781,7 +20766,7 @@ }, "devDependencies": { "@babel/preset-typescript": "^7.22.5", - "@onflow/fcl-bundle": "^1.4.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", "@types/jest": "^29.5.3", "@typescript-eslint/eslint-plugin": "^6.4.0", "@typescript-eslint/parser": "^6.4.0", @@ -20879,15 +20864,15 @@ }, "packages/util-address": { "name": "@onflow/util-address", - "version": "1.2.0-typescript.0", + "version": "1.2.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6" }, "devDependencies": { "@babel/preset-typescript": "^7.22.5", - "@onflow/fcl-bundle": "^1.4.0-typescript.0", - "@onflow/types": "^1.2.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", + "@onflow/types": "^1.2.0", "@types/jest": "^29.5.3", "@types/node": "^18.13.0", "@typescript-eslint/eslint-plugin": "^6.4.0", @@ -20999,17 +20984,17 @@ }, "packages/util-encode-key": { "name": "@onflow/util-encode-key", - "version": "1.2.0-typescript.0", + "version": "1.2.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6", - "@onflow/rlp": "^1.2.0-typescript.0", - "@onflow/util-invariant": "^1.2.0-typescript.0" + "@onflow/rlp": "^1.2.0", + "@onflow/util-invariant": "^1.2.0" }, "devDependencies": { "@babel/preset-typescript": "^7.22.5", - "@onflow/fcl-bundle": "^1.4.0-typescript.0", - "@onflow/types": "^1.2.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", + "@onflow/types": "^1.2.0", "@types/jest": "^29.5.3", "@types/node": "^18.13.0", "@typescript-eslint/eslint-plugin": "^6.4.0", @@ -21121,15 +21106,15 @@ }, "packages/util-invariant": { "name": "@onflow/util-invariant", - "version": "1.2.0-typescript.0", + "version": "1.2.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6" }, "devDependencies": { "@babel/preset-typescript": "^7.22.5", - "@onflow/fcl-bundle": "^1.4.0-typescript.0", - "@onflow/types": "^1.2.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", + "@onflow/types": "^1.2.0", "@types/jest": "^29.5.3", "@typescript-eslint/eslint-plugin": "^6.4.0", "@typescript-eslint/parser": "^6.4.0", @@ -21227,14 +21212,14 @@ }, "packages/util-logger": { "name": "@onflow/util-logger", - "version": "1.3.0-typescript.0", + "version": "1.3.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6" }, "devDependencies": { "@babel/preset-typescript": "^7.22.5", - "@onflow/fcl-bundle": "^1.4.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", "@types/jest": "^29.5.3", "@typescript-eslint/eslint-plugin": "^6.4.0", "@typescript-eslint/parser": "^6.4.0", @@ -21352,15 +21337,15 @@ }, "packages/util-template": { "name": "@onflow/util-template", - "version": "1.2.0-typescript.0", + "version": "1.2.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6", - "@onflow/util-logger": "^1.3.0-typescript.0" + "@onflow/util-logger": "^1.3.0" }, "devDependencies": { "@babel/preset-typescript": "^7.22.5", - "@onflow/fcl-bundle": "^1.4.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", "@types/jest": "^29.5.3", "@typescript-eslint/eslint-plugin": "^6.4.0", "@typescript-eslint/parser": "^6.4.0", @@ -21382,21 +21367,6 @@ "node": ">=16" } }, - "packages/util-template/node_modules/@onflow/util-logger": { - "version": "1.3.0", - "license": "Apache-2.0", - "dependencies": { - "@babel/runtime": "^7.18.6" - }, - "peerDependencies": { - "@onflow/util-config": ">1.1.1" - }, - "peerDependenciesMeta": { - "@onflow/util-config": { - "optional": true - } - } - }, "packages/util-template/node_modules/comment-parser": { "version": "1.4.0", "dev": true, @@ -21473,14 +21443,14 @@ }, "packages/util-uid": { "name": "@onflow/util-uid", - "version": "1.2.0-typescript.0", + "version": "1.2.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6" }, "devDependencies": { "@babel/preset-typescript": "^7.22.5", - "@onflow/fcl-bundle": "^1.4.0-typescript.0", + "@onflow/fcl-bundle": "^1.4.0", "@types/jest": "^29.5.3", "@typescript-eslint/eslint-plugin": "^6.4.0", "@typescript-eslint/parser": "^6.4.0", diff --git a/packages/sdk/src/build/build-subscribe-events.test.js b/packages/sdk/src/build/build-subscribe-events.test.js new file mode 100644 index 000000000..3d4dec385 --- /dev/null +++ b/packages/sdk/src/build/build-subscribe-events.test.js @@ -0,0 +1,26 @@ +import {interaction} from "../interaction/interaction.js" +import {subscribeEvents} from "./build-subscribe-events.js" + +describe("Subscribe Events", () => { + test("Subscribe Events", async () => { + let ix = await subscribeEvents({ + startBlockId: "abc123", + startHeight: 1, + eventTypes: ["A.7e60df042a9c0868.FlowToken.TokensWithdrawn"], + addresses: ["0x1", "0x2"], + contracts: ["A.7e60df042a9c0868.FlowToken"], + heartbeatInterval: 1000, + })(interaction()) + + expect(ix.subscribeEvents.startBlockId).toBe("abc123") + expect(ix.subscribeEvents.startHeight).toBe(1) + expect(ix.subscribeEvents.eventTypes).toEqual([ + "A.7e60df042a9c0868.FlowToken.TokensWithdrawn", + ]) + expect(ix.subscribeEvents.addresses).toEqual(["0x1", "0x2"]) + expect(ix.subscribeEvents.contracts).toEqual([ + "A.7e60df042a9c0868.FlowToken", + ]) + expect(ix.subscribeEvents.heartbeatInterval).toBe(1000) + }) +}) diff --git a/packages/sdk/src/build/build-subscription.test.js b/packages/sdk/src/build/build-subscription.test.js new file mode 100644 index 000000000..a13d65303 --- /dev/null +++ b/packages/sdk/src/build/build-subscription.test.js @@ -0,0 +1,20 @@ +import {interaction} from "../interaction/interaction.js" +import {subscription} from "./build-subscription.js" + +describe("Build Subscription", () => { + test("build subscription", async () => { + const onData = () => {} + const onError = () => {} + const onComplete = () => {} + + let ix = await subscription({ + onData, + onError, + onComplete, + })(interaction()) + + expect(ix.subscription.onData).toBe(onData) + expect(ix.subscription.onError).toBe(onError) + expect(ix.subscription.onComplete).toBe(onComplete) + }) +}) diff --git a/packages/sdk/src/interaction/interaction.js b/packages/sdk/src/interaction/interaction.js index db9f127ee..518c5504c 100644 --- a/packages/sdk/src/interaction/interaction.js +++ b/packages/sdk/src/interaction/interaction.js @@ -116,7 +116,7 @@ const IX = `{ "onData":null, "onError":null, "onComplete":null - }, + } }` const KEYS = new Set(Object.keys(JSON.parse(IX))) diff --git a/packages/transport-http/src/send-http.js b/packages/transport-http/src/send-http.js index 15a115d1b..f4334f88e 100644 --- a/packages/transport-http/src/send-http.js +++ b/packages/transport-http/src/send-http.js @@ -5,7 +5,7 @@ import {sendGetTransaction} from "./send-get-transaction.js" import {sendExecuteScript} from "./send-execute-script.js" import {sendGetAccount} from "./send-get-account.js" import {sendGetEvents} from "./send-get-events.js" -import {sendSubscribeEvents} from "./subscribe-events.js" +import {sendSubscribeEvents} from "./send-subscribe-events.js" import {sendGetBlock} from "./send-get-block.js" import {sendGetBlockHeader} from "./send-get-block-header.js" import {sendGetCollection} from "./send-get-collection.js" diff --git a/packages/transport-http/src/subscribe-events.js b/packages/transport-http/src/send-subscribe-events.js similarity index 76% rename from packages/transport-http/src/subscribe-events.js rename to packages/transport-http/src/send-subscribe-events.js index 0bfa0d528..4e3f27aad 100644 --- a/packages/transport-http/src/subscribe-events.js +++ b/packages/transport-http/src/send-subscribe-events.js @@ -1,5 +1,5 @@ import {invariant} from "@onflow/util-invariant" -import {subscribeWs as defaultSubscribeWs} from "./http-request.js" +import {subscribeWs as defaultSubscribeWs} from "./subscribe-ws" function constructData(ix, context, data) { let ret = context.response() @@ -32,7 +32,7 @@ function constructResponse(ix, context, callback) { return ret } -export async function subscribeEvents(ix, context = {}, opts = {}) { +export async function sendSubscribeEvents(ix, context = {}, opts = {}) { invariant(opts.node, `SDK Send Get Events Error: opts.node must be defined.`) invariant( context.response, @@ -42,25 +42,26 @@ export async function subscribeEvents(ix, context = {}, opts = {}) { context.Buffer, `SDK Send Get Events Error: context.Buffer must be defined.` ) - invariant(onData, `SDK Send Get Events Error: opts.onData must be defined.`) ix = await ix const subscribeWs = opts.subscribeWs || defaultSubscribeWs - const onData = opts.onData + const {onData, onError, onComplete} = ix.subscription const unsubscribe = subscribeWs({ hostname: opts.node, path: `/v1/subscribe_events`, params: { - start_block_id: ix.subscribeEvents.start_block_id, - start_height: ix.subscribeEvents.start_height, - event_types: ix.subscribeEvents.event_types, + start_block_id: ix.subscribeEvents.startBlockId, + start_height: ix.subscribeEvents.startHeight, + event_types: ix.subscribeEvents.eventTypes, addresses: ix.subscribeEvents.addresses, contracts: ix.subscribeEvents.contracts, - heartbeat_interval: ix.subscribeEvents.heartbeat_interval, + heartbeat_interval: ix.subscribeEvents.heartbeatInterval, }, onData: handleData, + onError, + onComplete, }) function handleData(data) { diff --git a/packages/transport-http/src/send-subscribe-events.test.js b/packages/transport-http/src/send-subscribe-events.test.js new file mode 100644 index 000000000..078db3d08 --- /dev/null +++ b/packages/transport-http/src/send-subscribe-events.test.js @@ -0,0 +1,102 @@ +import {sendSubscribeEvents} from "./send-subscribe-events" +import {Buffer} from "@onflow/rlp" +import { + build, + subscribeEvents, + subscription, + resolve, + response as responseADT, +} from "@onflow/sdk" + +describe("Subscribe Events", () => { + let subscribeWsMock + + let onData + let onError + let onComplete + + let unsubscribe + let response + + beforeEach(async () => { + subscribeWsMock = jest.fn() + + onData = jest.fn() + onError = jest.fn() + onComplete = jest.fn() + + unsubscribe = jest.fn() + + subscribeWsMock.mockReturnValue({ + unsubscribeCallback: unsubscribe, + }) + + const response = await sendSubscribeEvents( + await resolve( + await build([ + subscribeEvents({ + startBlockId: "abc123", + startHeight: 1, + eventTypes: ["A.7e60df042a9c0868.FlowToken.TokensWithdrawn"], + addresses: ["0x1", "0x2"], + contracts: ["A.7e60df042a9c0868.FlowToken"], + heartbeatInterval: 1000, + }), + subscription({ + onData, + onError, + onComplete, + }), + ]) + ), + { + response: responseADT, + Buffer, + }, + { + subscribeWs: subscribeWsMock, + node: "localhost", + } + ) + }) + + test("calls subscribeWs with correct params", async () => { + expect(subscribeWsMock.mock.calls.length).toEqual(1) + + const httpRequestMockArgs = httpRequestMock.mock.calls[0] + + expect(httpRequestMockArgs.length).toEqual(1) + + const valueSent = httpRequestMock.mock.calls[0][0] + + expect(valueSent.hostname).toBe("localhost") + expect(valueSent.path).toBe("/v1/subscribe_events") + expect(valueSent.params).toEqual({ + start_block_id: "abc123", + start_height: 1, + event_types: ["A.7e60df042a9c0868.FlowToken.TokensWithdrawn"], + addresses: ["0x1", "0x2"], + contracts: ["A.7e60df042a9c0868.FlowToken"], + heartbeat_interval: 1000, + }) + }) + + test("calls onData with response ADT formatted data", async () => { + const data = {foo: "bar"} + + // Similate WS message + subscribeWsMock.mock.calls[0][0].onData(data) + + expect(onData.mock.calls.length).toEqual(1) + expect(onData.mock.calls[0][0]).toEqual({ + tag: "SubscribeEvents", + data: data, + }) + }) + + test("calling response.unsubscribeCallback calls subscribeWs unsubscribe", async () => { + response.unsubscribeCallback() + + expect(unsubscribe.mock.calls.length).toEqual(1) + }) +})