From 7b2f275766edb8b662893525e1759e63e7836a25 Mon Sep 17 00:00:00 2001 From: Corey Phillips Date: Tue, 20 Oct 2020 11:47:07 -0400 Subject: [PATCH] Added basic tests for the start/stop helpers methods. --- test/electrum-client-helpers-test.js | 62 ++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test/electrum-client-helpers-test.js diff --git a/test/electrum-client-helpers-test.js b/test/electrum-client-helpers-test.js new file mode 100644 index 0000000..c8f7124 --- /dev/null +++ b/test/electrum-client-helpers-test.js @@ -0,0 +1,62 @@ +const assert = require("assert"); +const { describe, it } = require("mocha"); +const helpers = require("../helpers"); + +const network = "bitcoinTestnet"; +const peer = { host: "bitcoin.lukechilds.co", port: "50002", protocol: "ssl" }; +const customPeers = [peer]; + +describe("electrum-client-helpers", () => { + + describe("helpers.start: Connect to random peer.", () => { + let connectResponse = { error: true, data: "" }; + it("Should return a connect response object.", async () => { + connectResponse = await helpers.start({ network }); + //console.log("Random Peer Start Response:", connectResponse); + assert.strictEqual(typeof connectResponse, "object"); + assert.strictEqual(typeof connectResponse.data, "object"); + assert.strictEqual(typeof connectResponse.error, "boolean"); + }); + it("Should return connected peer info.", () => { + assert(Number(connectResponse.data.port) > 0); + assert.strictEqual(typeof connectResponse.data.host, "string"); + }); + }); + + describe("helpers.stop: Disconnect from peer.", () => { + let disconnectResponse = { error: true, data: "" }; + it("Should disconnect from specified network peer.", async () => { + disconnectResponse = await helpers.stop({ network }); + //console.log("Disconnect Response:", disconnectResponse); + assert.strictEqual(typeof disconnectResponse, "object"); + assert.strictEqual(typeof disconnectResponse.error, "boolean"); + assert.strictEqual(disconnectResponse.error, false); + }); + }); + + describe("helpers.start: Connect to custom/pre-defined peer", () => { + const expectedResponse = { + error: false, + data: { port: peer.port, host: peer.host }, + //id: 0.29098913884072286, + method: 'connectToPeer', + customPeers: [peer], + network + } + + let connectResponse = { error: true, data: "" }; + it("Return a connect response object.", async () => { + connectResponse = await helpers.start({ network, customPeers }); + //console.log("Custom Peer Start Response:", connectResponse); + assert.strictEqual(typeof connectResponse, "object"); + assert.strictEqual(typeof connectResponse.data, "object"); + assert.strictEqual(typeof connectResponse.error, "boolean"); + }); + it("Should return connected peer info.", () => { + assert("id" in connectResponse); + delete connectResponse.id; + assert.deepStrictEqual(connectResponse, expectedResponse); + }); + }); + +});