From 4c21c87060e8f720a7574b54c2697c747377409e Mon Sep 17 00:00:00 2001 From: kevkevin Date: Fri, 3 Feb 2023 09:00:33 -0600 Subject: [PATCH 01/11] test: adding proxy nodes to the test case In this change we're adding the proxy nodes and checking if they are in the nodes file, If they do exsist then we'll try and join the tribe --- src/tests/controllers/tribe3Messages.test.ts | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/tests/controllers/tribe3Messages.test.ts b/src/tests/controllers/tribe3Messages.test.ts index b04a7d576..b490781a3 100644 --- a/src/tests/controllers/tribe3Messages.test.ts +++ b/src/tests/controllers/tribe3Messages.test.ts @@ -18,6 +18,17 @@ test('test-10-tribe3Msgs: create tribe, two nodes join tribe, send messages, 2 n }) export async function tribe3Msgs(t, node1, node2, node3) { + //This is checking if the proxy nodes exist and if they + // do then we'll use them + let useProxyNodes = false + let proxyNode1 = null + let proxyNode2 = null + if (nodes.length > 4) { + useProxyNodes = true + proxyNode1 = nodes[3] + proxyNode2 = nodes[4] + } + // if running "no-alice" version with local relay const internalTribeHost = node1.ip.includes('host.docker.internal') ? config.tribeHost @@ -27,6 +38,7 @@ export async function tribe3Msgs(t, node1, node2, node3) { t.truthy(node3, 'this test requires three nodes') console.log(`${node1.alias} and ${node2.alias} and ${node3.alias}`) + console.log(`also using proxy ${proxyNode1.alias}, ${proxyNode2.alias}`) //NODE1 CREATES A TRIBE let tribe = await createTribe(t, node1) @@ -42,6 +54,16 @@ export async function tribe3Msgs(t, node1, node2, node3) { let join2 = await joinTribe(t, node3, tribe) t.true(join2, 'node3 should join tribe') + if (useProxyNodes) { + //PROXYNODE1 JOINS TRIBE CREATED BY NODE1 + let joinProxy1 = await joinTribe(t, proxyNode1, tribe) + t.true(joinProxy1, 'proxyNode1 should join tribe') + + //PROXYNODE2 JOINS TRIBE CREATED BY NODE1 + let proxyJoin2 = await joinTribe(t, proxyNode2, tribe) + t.true(proxyJoin2, 'proxyNode2 should join tribe') + } + //NODE1 SENDS A TEXT MESSAGE IN TRIBE const text = randomText() let tribeMessage = await sendTribeMessage(t, node1, tribe, text) From caaf74594c8b575df60f39e80e385487049f870f Mon Sep 17 00:00:00 2001 From: kevkevin Date: Fri, 3 Feb 2023 09:21:30 -0600 Subject: [PATCH 02/11] test: updated the version of node to 12.15 since it seems test failing --- .github/workflows/integration_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index 3c9cbf434..88bcab921 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -55,7 +55,7 @@ jobs: path: relay - uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 12.15 - name: Build Relay working-directory: ./relay run: | From e26c62337384ed217b0550c1189b3d65224d7959 Mon Sep 17 00:00:00 2001 From: kevkevin Date: Fri, 3 Feb 2023 09:30:39 -0600 Subject: [PATCH 03/11] test: checking messages from proxy nodes and npm version downgrade --- .github/workflows/integration_test.yml | 2 +- src/tests/controllers/tribe3Messages.test.ts | 49 ++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index 88bcab921..a5ab69c37 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -59,7 +59,7 @@ jobs: - name: Build Relay working-directory: ./relay run: | - npm install -g npm@latest && npm install && npm run build && docker build -t sphinxlightning/sphinx-relay . + npm install && npm run build && docker build -t sphinxlightning/sphinx-relay . - name: Checkout stack run: | git clone https://github.com/stakwork/sphinx-stack.git stack diff --git a/src/tests/controllers/tribe3Messages.test.ts b/src/tests/controllers/tribe3Messages.test.ts index b490781a3..e51a468ef 100644 --- a/src/tests/controllers/tribe3Messages.test.ts +++ b/src/tests/controllers/tribe3Messages.test.ts @@ -130,6 +130,55 @@ export async function tribe3Msgs(t, node1, node2, node3) { ) t.true(n2check2, 'node2 should have read and decrypted node3 message') + if (useProxyNodes) { + //proxyNode1 SENDS A TEXT MESSAGE IN TRIBE + const text4 = randomText() + let tribeMessage4 = await sendTribeMessage(t, proxyNode2, tribe, text4) + + //CHECK THAT proxyNode1'S DECRYPTED MESSAGE IS SAME AS INPUT From node1's point of view + const n1check3 = await checkMessageDecryption( + t, + node1, + tribeMessage4.uuid, + text4 + ) + t.true( + n1check3, + "node1 should have read and decrypted proxyNode1's message" + ) + + //CHECK THAT NODE2'S DECRYPTED MESSAGE IS SAME AS INPUT + const n4check2 = await checkMessageDecryption( + t, + proxyNode1, + tribeMessage2.uuid, + text2 + ) + t.true(n4check2, 'proxyNode1 should have read and decrypted node2 message') + + //PROXYNODE2 SENDS A TEXT MESSAGE IN TRIBE + const text5 = randomText() + let tribeMessage5 = await sendTribeMessage(t, proxyNode2, tribe, text5) + + //CHECK THAT NODE3'S DECRYPTED MESSAGE IS SAME AS INPUT AS NODE1 + const n5check2 = await checkMessageDecryption( + t, + node1, + tribeMessage5.uuid, + text5 + ) + t.true(n5check2, 'node1 should have read and decrypted node3 message') + + //CHECK THAT NODE2'S DECRYPTED MESSAGE IS SAME AS INPUT + const n5check3 = await checkMessageDecryption( + t, + proxyNode2, + tribeMessage2.uuid, + text2 + ) + t.true(n5check3, 'node2 should have read and decrypted node3 message') + } + /***** Here we want to create a new message channel for a tribe ******/ From 12af829b06a48c797e5b118862bbf819d0a45192 Mon Sep 17 00:00:00 2001 From: kevkevin Date: Fri, 3 Feb 2023 09:42:07 -0600 Subject: [PATCH 04/11] depends: reverting back version of jscryptor --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e27aa31a5..8dbbb1d82 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "jasmine": "^3.5.0", "jest": "^28.1.3", "js-sha256": "^0.9.0", - "jscryptor-2": "0.0.2", + "jscryptor-2": "0.0.1", "lodash": "^4.17.21", "long": "^3.2.0", "lsat-js": "^2.0.0", From 1c995e7fe41a41d43673d28587a76ce45a8ec772 Mon Sep 17 00:00:00 2001 From: kevkevin Date: Fri, 3 Feb 2023 09:49:14 -0600 Subject: [PATCH 05/11] test: added empty node config since null isnt suitable --- src/tests/controllers/tribe3Messages.test.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/tests/controllers/tribe3Messages.test.ts b/src/tests/controllers/tribe3Messages.test.ts index e51a468ef..b555b4dc3 100644 --- a/src/tests/controllers/tribe3Messages.test.ts +++ b/src/tests/controllers/tribe3Messages.test.ts @@ -9,6 +9,20 @@ import { getCheckNewMsgs, getTribeByUuid, getCheckTribe } from '../utils/get' import nodes from '../nodes' +const emptyNodeConfig = { + alias: '', + pubkey: '', + ip: '', + external_ip: '', + authToken: '', + transportToken: '', + contact_key: '', + privkey: '', + exported_keys: '', + pin: '', + routeHint: '', +} + /* npx ava test-10-tribe3Msgs.js --verbose --serial --timeout=2m */ @@ -21,8 +35,8 @@ export async function tribe3Msgs(t, node1, node2, node3) { //This is checking if the proxy nodes exist and if they // do then we'll use them let useProxyNodes = false - let proxyNode1 = null - let proxyNode2 = null + let proxyNode1 = emptyNodeConfig + let proxyNode2 = emptyNodeConfig if (nodes.length > 4) { useProxyNodes = true proxyNode1 = nodes[3] From 5ba53be26388605647dcbdef22fd81e25d7a3331 Mon Sep 17 00:00:00 2001 From: kevkevin Date: Fri, 3 Feb 2023 10:09:28 -0600 Subject: [PATCH 06/11] test: this should break the tribeMessages test --- src/utils/tribes.ts | 112 ++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 57 deletions(-) diff --git a/src/utils/tribes.ts b/src/utils/tribes.ts index 41d124c2a..08cb47b10 100644 --- a/src/utils/tribes.ts +++ b/src/utils/tribes.ts @@ -56,68 +56,66 @@ async function initializeClient( host: string, onMessage?: (topic: string, message: Buffer) => void ): Promise { - return new Promise(async (resolve) => { - let connected = false - async function reconnect() { - try { - const pwd = await genSignedTimestamp(pubkey) - if (connected) return - const url = mqttURL(host) - const cl = mqtt.connect(url, { - username: pubkey, - password: pwd, - reconnectPeriod: 0, // dont auto reconnect + let connected = false + async function reconnect() { + try { + const pwd = await genSignedTimestamp(pubkey) + if (connected) return + const url = mqttURL(host) + const cl = mqtt.connect(url, { + username: pubkey, + password: pwd, + reconnectPeriod: 0, // dont auto reconnect + }) + sphinxLogger.info(`try to connect: ${url}`, logging.Tribes) + cl.on('connect', async function () { + // first check if its already connected to this host (in case it takes a long time) + connected = true + if ( + clients[pubkey] && + clients[pubkey][host] && + clients[pubkey][host].connected + ) { + resolve(clients[pubkey][host]) + return + } + sphinxLogger.info(`connected!`, logging.Tribes) + if (!clients[pubkey]) clients[pubkey] = {} + clients[pubkey][host] = cl // ADD TO MAIN STATE + cl.on('close', function (e) { + sphinxLogger.info(`CLOSE ${e}`, logging.Tribes) + // setTimeout(() => reconnect(), 2000); + connected = false + if (clients[pubkey] && clients[pubkey][host]) { + delete clients[pubkey][host] + } }) - sphinxLogger.info(`try to connect: ${url}`, logging.Tribes) - cl.on('connect', async function () { - // first check if its already connected to this host (in case it takes a long time) - connected = true - if ( - clients[pubkey] && - clients[pubkey][host] && - clients[pubkey][host].connected - ) { - resolve(clients[pubkey][host]) - return + cl.on('error', function (e) { + sphinxLogger.error(`error: ${e.message}`, logging.Tribes) + }) + cl.on('message', function (topic, message) { + // console.log("============>>>>> GOT A MSG", topic, message) + if (onMessage) onMessage(topic, message) + }) + cl.subscribe(`${pubkey}/#`, function (err) { + if (err) + sphinxLogger.error(`error subscribing ${err}`, logging.Tribes) + else { + sphinxLogger.info(`subscribed! ${pubkey}/#`, logging.Tribes) + resolve(cl) } - sphinxLogger.info(`connected!`, logging.Tribes) - if (!clients[pubkey]) clients[pubkey] = {} - clients[pubkey][host] = cl // ADD TO MAIN STATE - cl.on('close', function (e) { - sphinxLogger.info(`CLOSE ${e}`, logging.Tribes) - // setTimeout(() => reconnect(), 2000); - connected = false - if (clients[pubkey] && clients[pubkey][host]) { - delete clients[pubkey][host] - } - }) - cl.on('error', function (e) { - sphinxLogger.error(`error: ${e.message}`, logging.Tribes) - }) - cl.on('message', function (topic, message) { - // console.log("============>>>>> GOT A MSG", topic, message) - if (onMessage) onMessage(topic, message) - }) - cl.subscribe(`${pubkey}/#`, function (err) { - if (err) - sphinxLogger.error(`error subscribing ${err}`, logging.Tribes) - else { - sphinxLogger.info(`subscribed! ${pubkey}/#`, logging.Tribes) - resolve(cl) - } - }) }) - } catch (e) { - sphinxLogger.error(`error initializing ${e}`, logging.Tribes) - } + }) + } catch (e) { + sphinxLogger.error(`error initializing ${e}`, logging.Tribes) } - while (true) { - if (!connected) { - reconnect() - } - await sleep(5000 + Math.round(Math.random() * 8000)) + } + while (true) { + if (!connected) { + reconnect() } - }) + await sleep(5000 + Math.round(Math.random() * 8000)) + } } async function lazyClient( From ea81894e8202669c5822c6db15a14d554beab670 Mon Sep 17 00:00:00 2001 From: kevkevin Date: Fri, 3 Feb 2023 10:22:47 -0600 Subject: [PATCH 07/11] test: resolve -> return --- src/utils/tribes.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/tribes.ts b/src/utils/tribes.ts index 08cb47b10..cbd58e1c7 100644 --- a/src/utils/tribes.ts +++ b/src/utils/tribes.ts @@ -76,7 +76,7 @@ async function initializeClient( clients[pubkey][host] && clients[pubkey][host].connected ) { - resolve(clients[pubkey][host]) + return clients[pubkey][host] return } sphinxLogger.info(`connected!`, logging.Tribes) @@ -102,7 +102,7 @@ async function initializeClient( sphinxLogger.error(`error subscribing ${err}`, logging.Tribes) else { sphinxLogger.info(`subscribed! ${pubkey}/#`, logging.Tribes) - resolve(cl) + return cl } }) }) From 66413a9475f27a84f0756b6b4bdced20de5bc8bd Mon Sep 17 00:00:00 2001 From: kevkevin Date: Fri, 3 Feb 2023 11:13:48 -0600 Subject: [PATCH 08/11] test: print nodes.json test: typo fix --- .github/workflows/integration_test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index a5ab69c37..968934b2f 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -78,9 +78,7 @@ jobs: working-directory: ./stack run: | sleep 240; - docker-compose ps - docker logs meme.sphinx - docker logs dave.sphinx + cat stack/relay/NODES.json docker wait stack_relaysetup_1; - name: copy file uses: canastro/copy-file-action@master From 1eaa60db02f1c2ccace882eca0b92fe6a38091ad Mon Sep 17 00:00:00 2001 From: kevkevin Date: Fri, 3 Feb 2023 12:04:17 -0600 Subject: [PATCH 09/11] test: correct path --- .github/workflows/integration_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index 968934b2f..054500f6c 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -78,7 +78,7 @@ jobs: working-directory: ./stack run: | sleep 240; - cat stack/relay/NODES.json + cat ./relay/NODES.json docker wait stack_relaysetup_1; - name: copy file uses: canastro/copy-file-action@master From 6a8a3e6aa1d03792770392bcc10cffa0542632db Mon Sep 17 00:00:00 2001 From: kevkevin Date: Mon, 6 Feb 2023 16:15:48 -0600 Subject: [PATCH 10/11] workflow: added the stack branch I wanted to test on --- .github/workflows/integration_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index 054500f6c..833d7a205 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -62,7 +62,7 @@ jobs: npm install && npm run build && docker build -t sphinxlightning/sphinx-relay . - name: Checkout stack run: | - git clone https://github.com/stakwork/sphinx-stack.git stack + git clone -b proxyFeat/multipleProxyUsers https://github.com/kevkevinpal/sphinx-stack.git stack - name: give permissions working-directory: ./stack run: | From 249301bdbc089a213c3704c8433e119953ee2fb4 Mon Sep 17 00:00:00 2001 From: kevkevin Date: Fri, 10 Feb 2023 14:02:31 -0600 Subject: [PATCH 11/11] test: updated back to the master branch --- .github/workflows/integration_test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index f98aaf940..2d8684467 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -63,7 +63,7 @@ jobs: npm install && npm run build && docker build -t sphinxlightning/sphinx-relay . - name: Checkout stack run: | - git clone -b proxyFeat/multipleProxyUsers https://github.com/kevkevinpal/sphinx-stack.git stack + git clone https://github.com/stakwork/sphinx-stack.git stack - name: give permissions working-directory: ./stack run: | @@ -79,7 +79,8 @@ jobs: working-directory: ./stack run: | sleep 240; - cat ./relay/NODES.json + cat ./relay/NODES.json; + docker ps; docker wait stack_relaysetup_1; - name: copy file uses: canastro/copy-file-action@master