From ad73c42b85211273b43fc5a5e1462042f19e5b29 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 12 Jan 2023 13:11:53 +0100 Subject: [PATCH 1/7] Update electrum servers for tests We use public Keep Network's server for integration tests. --- test/config.js | 40 +++++++------- test/integration_test.js | 110 ++++++++++++++++++++------------------- 2 files changed, 77 insertions(+), 73 deletions(-) diff --git a/test/config.js b/test/config.js index 06866ff..1a071b9 100644 --- a/test/config.js +++ b/test/config.js @@ -1,27 +1,29 @@ -const servers = { - tcp: { - protocol: 'tcp', port: '50001', host: 'electrum.bitaroo.net', +const servers = [ + { + protocol: 'tcp', + port: '80', + host: 'electrumx-server.test.tbtc.network', }, - ssl: { - protocol: 'ssl', port: '50002', host: 'electrum.bitaroo.net', + { + protocol: 'ws', + port: '8080', + host: 'electrumx-server.test.tbtc.network', }, - ws: { - protocol: 'ws', port: '50003', host: 'electrumx-server.tbtc.svc.cluster.local', - }, - wss: { - protocol: 'wss', port: '50004', host: 'electrumx-server.tbtc.svc.cluster.local', - }, -} -const serversArray = [ - servers.tcp, - servers.ssl, - // FIXME: WebSocket is commented out for CI, until we find public servers for this protocol. - // electrumServers.ws, - // electrumServers.wss, + // FIXME: The client doesn't work with SSL connection. + // ssl: { + // protocol: "ssl", + // port: "443", + // host: "electrumx-server.test.tbtc.network", + // }, + // FIXME: The client doesn't work with WSS connection. + // wss: { + // protocol: "wss", + // port: "8443", + // host: "electrumx-server.test.tbtc.network", + // }, ] module.exports = { servers, - serversArray, } diff --git a/test/integration_test.js b/test/integration_test.js index 9983596..ec3d57d 100644 --- a/test/integration_test.js +++ b/test/integration_test.js @@ -5,76 +5,78 @@ const assert = chai.assert const fs = require('fs') -const config = require('./config') +const {servers} = require('./config') describe('ElectrumClient', async () => { let txData before(async () => { - txData = JSON.parse(await fs.readFileSync('./test/tx.json', 'utf8')) + txData = JSON.parse(fs.readFileSync('./test/tx.json', 'utf8')) }) - context('when connected', async () => { - config.serversArray.forEach((server) => { - describe(`for ${server.protocol} protocol`, async () => { - let client + describe('for all protocols', async () => { + servers.forEach((server) => { + describe(`${server.protocol}://${server.host}:${server.port}`, async () => { + describe('when connected', async () => { + let client - before(async () => { - client = new ElectrumClient( - server.host, - server.port, - server.protocol, - server.options - ) + before(async () => { + client = new ElectrumClient( + server.host, + server.port, + server.protocol, + server.options, + ) - await client - .connect('test_client' + server.protocol, '1.4.2') - .catch((err) => { - console.error( - `failed to connect with config [${JSON.stringify( - server - )}]: [${err}]` - ) - }) - }) + await client + .connect('test_client' + server.protocol, '1.4.2') + .catch((err) => { + console.error( + `failed to connect with config [${JSON.stringify( + server, + )}]: [${err}]`, + ) + }) + }) - after(async () => { - await client.close() - }) + after(async () => { + await client.close() + }) - it('request returns result', async () => { - const expectedResult = txData.hex - const result = await client.blockchain_transaction_get(txData.hash) + it('request returns result', async () => { + const expectedResult = txData.hex + const result = await client.blockchain_transaction_get(txData.hash) - assert.equal(result, expectedResult, 'unexpected result') + assert.equal(result, expectedResult, 'unexpected result') + }) }) - }) - }) - }) - context('when not connected', async () => { - before(async () => { - const server = config.servers.tcp + describe('when not connected', async () => { + let client - client = new ElectrumClient( - server.host, - server.port, - server.protocol, - server.options - ) - }) + before(async () => { + client = new ElectrumClient( + server.host, + server.port, + server.protocol, + server.options, + ) + }) - it('request throws error', async () => { - await client.blockchain_transaction_get(txData.hash).then( - (value) => { - // onFulfilled - assert.fail('not failed as expected') - }, - (reason) => { - // onRejected - assert.include(reason.toString(), `connection not established`) - } - ) + it('request throws error', async () => { + await client.blockchain_transaction_get(txData.hash).then( + (value) => { + // onFulfilled + assert.fail('not failed as expected') + }, + (reason) => { + // onRejected + assert.include(reason.toString(), `connection not established`) + }, + ) + }) + }) + }) }) }) // TODO: Add tests From 220f188e4adcb3ebeb73198f3acd30ab5aa8ed83 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 12 Jan 2023 13:17:15 +0100 Subject: [PATCH 2/7] Catch JSON parse error Catch JSON parsing error and log it. --- src/socket/socket_client.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/socket/socket_client.js b/src/socket/socket_client.js index a21be7b..a76a4a3 100644 --- a/src/socket/socket_client.js +++ b/src/socket/socket_client.js @@ -69,7 +69,13 @@ class SocketClient { } onMessage(body, n) { - const msg = JSON.parse(body) + let msg + try { + msg = JSON.parse(body) + } catch (e) { + console.error('failed to parse message body: [%s]', body) + return + } if (msg instanceof Array) { ; // don't support batch request } else { From 9882291d1725863ef682c07bef9af56cfb06029d Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 19 Jan 2023 12:04:44 +0100 Subject: [PATCH 3/7] Update config for test servers Added details of the ElectrumX server running for testnet by Keep. --- test/config.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/config.js b/test/config.js index 1a071b9..0cbe6d7 100644 --- a/test/config.js +++ b/test/config.js @@ -1,27 +1,27 @@ +const ELECTRUMX_HOST = '34.70.22.39' // "electrumx-server.test.tbtc.network" + const servers = [ { protocol: 'tcp', port: '80', - host: 'electrumx-server.test.tbtc.network', + host: ELECTRUMX_HOST, }, { protocol: 'ws', port: '8080', - host: 'electrumx-server.test.tbtc.network', + host: ELECTRUMX_HOST, + }, + { + protocol: 'ssl', + port: '443', + host: ELECTRUMX_HOST, }, - - // FIXME: The client doesn't work with SSL connection. - // ssl: { - // protocol: "ssl", - // port: "443", - // host: "electrumx-server.test.tbtc.network", - // }, // FIXME: The client doesn't work with WSS connection. - // wss: { - // protocol: "wss", - // port: "8443", - // host: "electrumx-server.test.tbtc.network", - // }, + { + protocol: 'wss', + port: '8443', + host: ELECTRUMX_HOST, + }, ] module.exports = { From 165ad7371bcfa3a6bf6afdf9f19864f68a151e66 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 19 Jan 2023 12:13:35 +0100 Subject: [PATCH 4/7] Don't catch connection error in test We want the test to fail, instead of catching the connection error. --- test/integration_test.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/test/integration_test.js b/test/integration_test.js index ec3d57d..f978f6c 100644 --- a/test/integration_test.js +++ b/test/integration_test.js @@ -28,15 +28,7 @@ describe('ElectrumClient', async () => { server.options, ) - await client - .connect('test_client' + server.protocol, '1.4.2') - .catch((err) => { - console.error( - `failed to connect with config [${JSON.stringify( - server, - )}]: [${err}]`, - ) - }) + await client.connect('test_client' + server.protocol, '1.4.2') }) after(async () => { From d05c3c62987d53d76d654b14916fb910b8fa5271 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 19 Jan 2023 12:14:04 +0100 Subject: [PATCH 5/7] Update details of testnet tx data --- test/tx.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tx.json b/test/tx.json index 6997a67..6f00fad 100644 --- a/test/tx.json +++ b/test/tx.json @@ -1,4 +1,4 @@ { - "hash": "d60033c5cf5c199208a9c656a29967810c4e428c22efb492fdd816e6a0a1e548", - "hex": "010000000001011746bd867400f3494b8f44c24b83e1aa58c4f0ff25b4a61cffeffd4bc0f9ba300000000000ffffffff024897070000000000220020a4333e5612ab1a1043b25755c89b16d55184a42f81799e623e6bc39db8539c180000000000000000166a14edb1b5c2f39af0fec151732585b1049b07895211024730440220276e0ec78028582054d86614c65bc4bf85ff5710b9d3a248ca28dd311eb2fa6802202ec950dd2a8c9435ff2d400cc45d7a4854ae085f49e05cc3f503834546d410de012103732783eef3af7e04d3af444430a629b16a9261e4025f52bf4d6d026299c37c7400000000" + "hash": "bfb696b574ef93041270db405fc9e692d25a68bb3c5011cbeb17d4e9e002f176", + "hex": "02000000000101f04ac24a78b061ffdb0fd19c6a18c01b0b2a690f728407646016269dae423b370000000000feffffff0270170000000000001600142167c4e195229053971e1c934d8ec018d0151dd41287410000000000160014521edf677ef1ff12d363d4204756bec1a9d7cd050247304402200b489a2c86e39aeb0b442665f1edeb4a46f92bdc6cef94f22c7961501f711d57022024a2e37049bf63e607c280af31200426df6e53410d963220b761ba860b7637b00121030d176fac399c01095d4648e77c47dd04c5c946d57779795fab6f6e4e473e025cb3d22400" } From 415858671cc56f4bd412c4d81dd492932cf646e5 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Sat, 21 Jan 2023 11:14:48 +0100 Subject: [PATCH 6/7] Update electrum host address in tests Address of electrum server for testnet maintained by Keep Network. --- test/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/config.js b/test/config.js index 0cbe6d7..ee1dbce 100644 --- a/test/config.js +++ b/test/config.js @@ -1,4 +1,4 @@ -const ELECTRUMX_HOST = '34.70.22.39' // "electrumx-server.test.tbtc.network" +const ELECTRUMX_HOST = 'electrumx-server.test.tbtc.network' const servers = [ { From c3de62fd0f42b84ea10e8cd0fa147ff1c5015e4a Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 26 Jan 2023 13:15:40 +0100 Subject: [PATCH 7/7] Add more test servers Here we add more tests servers for integration tests. --- test/config.js | 63 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/test/config.js b/test/config.js index ee1dbce..e88bbd8 100644 --- a/test/config.js +++ b/test/config.js @@ -1,26 +1,65 @@ -const ELECTRUMX_HOST = 'electrumx-server.test.tbtc.network' +const TBTC_ELECTRUMX_HOST = 'electrumx-server.test.tbtc.network' +const BLOCKSTREAM_ELECTRS_HOST = 'electrum.blockstream.info' const servers = [ + // TODO: Enable all protocols test for test.tbtc.network servers once they are + // publicly exposed. + // { + // protocol: 'tcp', + // port: '80', + // host: TBTC_ELECTRUMX_HOST, + // }, + // { + // protocol: 'ssl', + // port: '443', + // host: TBTC_ELECTRUMX_HOST, + // }, + // { + // protocol: 'ws', + // port: '8080', + // host: TBTC_ELECTRUMX_HOST, + // }, + + { + protocol: 'wss', + port: '8443', + host: TBTC_ELECTRUMX_HOST, + }, + // electrumx tcp { + host: 'electrum1.cipig.net', + port: '10068', protocol: 'tcp', - port: '80', - host: ELECTRUMX_HOST, }, + // electrumx ssl { - protocol: 'ws', - port: '8080', - host: ELECTRUMX_HOST, + host: 'testnet.qtornado.com', + port: '51002', + protocol: 'ssl', }, + // electrs-esplora tcp { + protocol: 'tcp', + port: '60001', + host: BLOCKSTREAM_ELECTRS_HOST, + }, + // electrs-esplora ssl + { + host: 'electrum.blockstream.info', + port: '60002', protocol: 'ssl', - port: '443', - host: ELECTRUMX_HOST, }, - // FIXME: The client doesn't work with WSS connection. + // fulcrum tcp { - protocol: 'wss', - port: '8443', - host: ELECTRUMX_HOST, + host: 'testnet.aranguren.org', + port: 51001, + protocol: 'tcp', + }, + // fulcrum ssl + { + host: 'testnet.aranguren.org', + port: 51002, + protocol: 'ssl', }, ]