From f5b22d4835a092043a611f2f22d4374b848adcd0 Mon Sep 17 00:00:00 2001 From: Gorden Jin Date: Fri, 20 Mar 2026 02:02:48 +0000 Subject: [PATCH] Remove iroh --- install/package.json | 1 - test/iroh.js | 77 -------------------------------------------- 2 files changed, 78 deletions(-) delete mode 100644 test/iroh.js diff --git a/install/package.json b/install/package.json index 7dcce532a9..c9a8816640 100644 --- a/install/package.json +++ b/install/package.json @@ -175,7 +175,6 @@ "grunt": "1.6.1", "grunt-contrib-watch": "1.1.0", "husky": "8.0.3", - "iroh": "^0.3.0", "jsdom": "27.4.0", "lint-staged": "16.2.7", "mocha": "11.7.5", diff --git a/test/iroh.js b/test/iroh.js deleted file mode 100644 index 0b056ed6b5..0000000000 --- a/test/iroh.js +++ /dev/null @@ -1,77 +0,0 @@ -'use strict'; - -const assert = require('assert'); -const fs = require('fs'); -const path = require('path'); -const Iroh = require('iroh'); - -// Read and extract the endorse body from the real file — nothing is copied here -const apiSource = fs.readFileSync( - path.join(__dirname, '../src/api/posts.js'), 'utf8' -); -const endorseMatch = apiSource.match(/postsAPI\.endorse = async function[\s\S]*?\n\};/); -assert.ok(endorseMatch, 'Could not locate postsAPI.endorse in src/api/posts.js'); -const rawSource = endorseMatch[0]; -const bodyStart = rawSource.indexOf('{'); -const bodyEnd = rawSource.lastIndexOf('};'); -// Strip 'await ': acorn 5 (ecmaVersion 6) cannot parse async expressions -const syncBody = rawSource.slice(bodyStart + 1, bodyEnd).replace(/\bawait /g, ''); - -// Build self-contained IIFE code for Iroh. -// All mock dependencies are literal values inside the code string — zero external scope. -function buildCode(dataLiteral, canResult) { - return '(function(caller, data, privileges, posts, websockets) {\n' + - syncBody + '\n' + - '})({ uid: 1 }, ' + dataLiteral + ',\n' + - ' { global: { can: function() { return ' + canResult + '; } } },\n' + - ' { exists: function() { return true; }, setPostField: function() {}, getPostField: function() { return 10; } },\n' + - ' { in: function() { return { emit: function() {} }; } });'; -} - -describe('Iroh dynamic analysis: postsAPI.endorse', () => { - it('should parse the endorse function body without error', () => { - const calls = []; - var stage; - - assert.doesNotThrow( - () => stage = new Iroh.Stage(buildCode('{ pid: 42 }', 'true')), // eslint-disable-line no-new - 'Iroh failed to parse endorse function body' - ); - - stage.addListener(Iroh.FUNCTION).on('enter', (e) => { calls.push(e.value); }); - eval(stage.script); - assert.notEqual(calls.length, 0); - }); - - // Iroh.IF 'enter' fires when the condition is TRUE (block is entered). - // 'fire' never emits for IF in Iroh v0.3.0; use 'enter' instead. - - it('should fire IF when data is missing (first guard)', () => { - const branches = []; - const stage = new Iroh.Stage(buildCode('null', 'true')); - stage.addListener(Iroh.IF).on('enter', (e) => { branches.push(e.value); }); - try { - // eslint-disable-next-line no-eval - eval(stage.script); - } catch (e) { - if (!e.message.includes('invalid-data')) throw e; - } - assert.strictEqual(branches.length, 1); - assert.strictEqual(branches[0], true); - }); - - it('should fire IF when caller lacks privilege (second guard)', () => { - const branches = []; - const stage = new Iroh.Stage(buildCode('{ pid: 42 }', 'false')); // no privilege - stage.addListener(Iroh.IF).on('enter', (e) => { branches.push(e.value); }); - try { - // eslint-disable-next-line no-eval - eval(stage.script); - } catch (e) { - if (!e.message.includes('no-privileges')) throw e; - } - // First guard skipped (data valid), second guard fires - assert.strictEqual(branches.length, 1); - assert.strictEqual(branches[0], true); - }); -}); \ No newline at end of file