From d0be00b907380cb8f3354538f2046d06f2d4f3c2 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 21 Jan 2023 09:53:50 +0100 Subject: [PATCH] remixd script --- .circleci/config.yml | 42 +++++++++++++++- apps/remix-ide/ci/remixd_test.sh | 23 +++++++++ libs/remixd/src/services/foundryClient.ts | 61 +++++++++++++---------- 3 files changed, 99 insertions(+), 27 deletions(-) create mode 100644 apps/remix-ide/ci/remixd_test.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index bce1337067..c782528c08 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -76,6 +76,43 @@ jobs: - run: node dist/libs/remix-tests/bin/remix-tests ./libs/remix-tests/tests/examples_0/assert_ok_test.sol - run: yarn run test:libs + remixd: + docker: + - image: cimg/node:14.17.6-browsers + resource_class: + xlarge + working_directory: ~/remix-project + steps: + - browser-tools/install-browser-tools + - run: + command: | + google-chrome --version + firefox --version + geckodriver --version + chromedriver --version + rm LICENSE.chromedriver 2> /dev/null + - checkout + - attach_workspace: + at: . + - run: unzip ./persist/dist.zip + + - restore_cache: + keys: + - v1-deps-{{ checksum "yarn.lock" }} + - run: yarn + - run: yarn run downloadsolc_assets_e2e && yarn run downloadsolc_assets_dist + - run: ls -la ./dist/apps/remix-ide/assets/js + - run: yarn run selenium-install || yarn run selenium-install + - run: + name: Start Selenium + command: yarn run selenium + background: true + - run: ./apps/remix-ide/ci/remixd_test.sh + - store_test_results: + path: ./reports/tests + - store_artifacts: + path: ./reports/screenshots + remix-ide-browser: docker: - image: cimg/node:14.17.6-browsers @@ -273,6 +310,9 @@ workflows: matrix: parameters: script: ["browser_tests_plugin_api.sh", "browser_tests_etherscan_plugin.sh", "browser_tests_vyper_plugin.sh"] + - remixd: + requires: + - build - remix-ide-browser: requires: - build @@ -316,4 +356,4 @@ workflows: branches: only: remix_beta -# VS Code Extension Version: 1.5.0 \ No newline at end of file +# VS Code Extension Version: 1.5.1 \ No newline at end of file diff --git a/apps/remix-ide/ci/remixd_test.sh b/apps/remix-ide/ci/remixd_test.sh new file mode 100644 index 0000000000..573db6d238 --- /dev/null +++ b/apps/remix-ide/ci/remixd_test.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -e + +BUILD_ID=${CIRCLE_BUILD_NUM:-${TRAVIS_JOB_NUMBER}} +echo "$BUILD_ID" +TEST_EXITCODE=0 + +# install foundry +curl -L https://foundry.paradigm.xyz | bash +foundryup +forge init foundry +ls -la foundry + +sleep 5 + +yarn run build:e2e + +echo "$TEST_EXITCODE" +if [ "$TEST_EXITCODE" -eq 1 ] +then + exit 1 +fi diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index 5f9fbc02e3..85b5a9319b 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -14,6 +14,8 @@ export class FoundryClient extends PluginClient { warnlog: boolean buildPath: string cachePath: string + logTimeout: NodeJS.Timeout + processingTimeout: NodeJS.Timeout constructor(private readOnly = false) { super() @@ -36,12 +38,13 @@ export class FoundryClient extends PluginClient { this.listenOnFoundryCompilation() } else { console.log('Foundry out folder doesn\'t exist... waiting for the first compilation.') - this.listenOFoundryFolder() + this.listenOnFoundryFolder() } - } - listenOFoundryFolder() { + + + listenOnFoundryFolder() { try { this.watcher = chokidar.watch(this.currentSharedFolder, { depth: 1, ignorePermissionErrors: true, ignoreInitial: true }) // watch for new folders @@ -55,7 +58,7 @@ export class FoundryClient extends PluginClient { } } - compile(configPath: string) { + compile() { return new Promise((resolve, reject) => { if (this.readOnly) { const errMsg = '[Foundry Compilation]: Cannot compile in read-only mode' @@ -82,9 +85,19 @@ export class FoundryClient extends PluginClient { }) } + checkPath() { + console.log('checkPath', fs.existsSync(this.buildPath), fs.existsSync(this.cachePath), fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) + if (!fs.existsSync(this.buildPath) || !fs.existsSync(this.cachePath)) { + this.listenOnFoundryFolder() + return false + } + if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) return false + return true + } + private async processArtifact() { + if (!this.checkPath()) return const folderFiles = await fs.readdir(this.buildPath) // "out" folder - if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) return try { const cache = JSON.parse(await fs.readFile(join(this.cachePath, 'solidity-files-cache.json'), { encoding: 'utf-8' })) // name of folders are file names @@ -102,24 +115,32 @@ export class FoundryClient extends PluginClient { await this.readContract(path, compilationResult, cache) this.emit('compilationFinished', compilationResult.compilationTarget, { sources: compilationResult.input }, 'soljson', compilationResult.output, compilationResult.solcVersion) } - if (!this.warnlog) { + + clearTimeout(this.logTimeout) + this.logTimeout = setTimeout(() => { // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'receiving compilation result from Foundry' }) - this.warnlog = true - } + this.call('terminal', 'log', { type: 'log', value: 'receiving compilation result from Foundry' }), 1000 + }) + } catch (e) { console.log(e) } } + async triggerProcessArtifact() { + // prevent multiple calls + clearTimeout(this.processingTimeout) + this.processingTimeout = setTimeout(async () => await this.processArtifact(), 1000) + } + listenOnFoundryCompilation() { try { this.watcher = chokidar.watch(this.cachePath, { depth: 0, ignorePermissionErrors: true, ignoreInitial: true }) - this.watcher.on('change', async (f: string) => this.processArtifact()) - this.watcher.on('add', async (f: string) => this.processArtifact()) + this.watcher.on('change', async () => await this.triggerProcessArtifact()) + this.watcher.on('add', async () => await this.triggerProcessArtifact()) // process the artifact on activation - setTimeout(() => this.processArtifact(), 1000) + this.triggerProcessArtifact() } catch (e) { console.log(e) } @@ -188,19 +209,7 @@ export class FoundryClient extends PluginClient { } async sync() { - console.log('syncing from Foundry') - if (fs.existsSync(this.buildPath) && fs.existsSync(this.cachePath)) { - if (!fs.existsSync(join(this.cachePath, 'solidity-files-cache.json'))) { - console.log('No compilation data found') - // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'No compilation data found' }) - } else{ - this.processArtifact() - // @ts-ignore - this.call('terminal', 'log', { type: 'log', value: 'synced with Foundry' }) - } - } else { - this.listenOFoundryFolder() - } + console.log('syncing Foundry with Remix...') + this.processArtifact() } }