diff --git a/apps/remix-ide-e2e/src/tests/remixd-dyn.test.ts b/apps/remix-ide-e2e/src/tests/remixd-dyn.test.ts deleted file mode 100644 index ca627e727e..0000000000 --- a/apps/remix-ide-e2e/src/tests/remixd-dyn.test.ts +++ /dev/null @@ -1,178 +0,0 @@ -'use strict' -import { NightwatchBrowser } from 'nightwatch' -import { writeFileSync } from 'fs' -import { join } from 'path' -import { spawn } from 'child_process' -import init from '../helpers/init' -import * as hardhatCompilation from '../helpers/hardhat_compilation_7839ba878952cc00ff316061405f273a.json' -import * as hardhat_compilation_Lock_dbg from '../helpers/hardhat_compilation_Lock.dbg.json' -import * as hardhat_compilation_Lock from '../helpers/hardhat_compilation_Lock.json' - -import * as foundryCompilation from '../helpers/foundry_compilation.json' -import * as truffle_compilation from '../helpers/truffle_compilation.json' - - -module.exports = { - '@disabled': true, - before: function (browser, done) { - init(browser, done) - }, - - '@sources': function () { - return [] - }, - - 'Should listen on compilation result from hardhat #group1': function (browser: NightwatchBrowser) { - let remixd - browser.perform((done) => { - remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts/hardhat')) - console.log('working directory', process.cwd()) - connectRemixd(browser, done) - }) - .perform((done) => { - console.log('generating compilation result') - writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/build-info/7839ba878952cc00ff316061405f273a.json', JSON.stringify(hardhatCompilation)) - writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/contracts/Lock.sol/Lock.json', JSON.stringify(hardhat_compilation_Lock)) - writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/contracts/Lock.sol/Lock.dbg.json', JSON.stringify(hardhat_compilation_Lock_dbg)) - done() - }) - .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from hardhat').before(60000) - - browser.clickLaunchIcon('filePanel') - .openFile('contracts/Lock.sol') - .clickLaunchIcon('udapp') - .selectContract('Lock') - .createContract('1') - .expect.element('*[data-id="terminalJournal"]').text.to.contain('Unlock time should be in the future').before(60000) - - browser.perform(() => { - remixd.kill() - }) - }, - - 'Should load compilation result from hardhat when remixd connects #group2': function (browser: NightwatchBrowser) { - // artifacts/build-info/c7062fdd360381a85af23eeef31c98f8.json has already been created - let remixd - browser - .perform((done) => { - writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/contracts/Lock.sol/Lock.dbg.json', JSON.stringify(hardhat_compilation_Lock_dbg)) - writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/contracts/Lock.sol/Lock.json', JSON.stringify(hardhat_compilation_Lock)) - writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/build-info/7839ba878952cc00ff316061405f273a.json', JSON.stringify(hardhatCompilation)) - done() - }) - .perform((done) => { - remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts/hardhat')) - console.log('working directory', process.cwd()) - connectRemixd(browser, done) - }) - .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from hardhat').before(60000) - - browser.clickLaunchIcon('filePanel') - .openFile('contracts/Lock.sol') - .clickLaunchIcon('udapp') - .selectContract('Lock') - .createContract('1') - .expect.element('*[data-id="terminalJournal"]').text.to.contain('Unlock time should be in the future').before(60000) - - browser.perform(() => { - remixd.kill() - }) - }, - - 'Should listen on compilation result from foundry #group3': function (browser: NightwatchBrowser) { - let remixd - browser.perform((done) => { - remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts/foundry')) - console.log('working directory', process.cwd()) - connectRemixd(browser, done) - }) - .perform((done) => { - writeFileSync('./apps/remix-ide/contracts/foundry/out/Counter.sol/Counter.json', JSON.stringify(foundryCompilation)) - done() - }) - .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from foundry').before(60000) - - let contractAaddress - browser.clickLaunchIcon('filePanel') - .openFile('src/Counter.sol') - .clickLaunchIcon('udapp') - .selectContract('Counter') - .createContract('') - .getAddressAtPosition(0, (address) => { - console.log(contractAaddress) - contractAaddress = address - }) - .clickInstance(0) - .clickFunction('increment - transact (not payable)') - .perform((done) => { - browser.testConstantFunction(contractAaddress, 'number - call', null, '0:\nuint256: 1').perform(() => { - done() - }) - }) - - browser.perform(() => { - remixd.kill() - }) - }, - - 'Should listen on compilation result from truffle #group4': function (browser: NightwatchBrowser) { - let remixd - browser.perform((done) => { - remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts/truffle')) - console.log('working directory', process.cwd()) - connectRemixd(browser, done) - }) - .perform((done) => { - writeFileSync('./apps/remix-ide/contracts/truffle/build/contracts/Migrations.json', JSON.stringify(truffle_compilation)) - done() - }) - .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from truffle').before(60000) - - browser.clickLaunchIcon('filePanel') - .openFile('contracts/Migrations.sol') - .clickLaunchIcon('udapp') - .selectContract('Migrations') - .createContract('') - .testFunction('last', - { - status: 'true Transaction mined and execution succeed' - }) - - browser.perform(() => { - remixd.kill() - }) - } -} - -function spawnRemixd (path: string) { - const remixd = spawn('yarn run remixd', [`-s ${path}`], { cwd: process.cwd(), shell: true }) - remixd.stdout.on('data', function(data) { - console.log('stdout: ' + data.toString()) - }) - remixd.stderr.on('err', function(data) { - console.log('err: ' + data.toString()) - }) - return remixd -} - -function connectRemixd (browser: NightwatchBrowser, done: any) { - const browserName = browser.options.desiredCapabilities.browserName - if (browserName === 'safari' || browserName === 'internet explorer') { - console.log('do not run remixd test for ' + browserName + ': sauce labs doesn\'t seems to handle websocket') - browser.end() - done() - return - } - - browser - .pause(5000) - .waitForElementVisible('#icon-panel', 2000) - .clickLaunchIcon('filePanel') - .clickLaunchIcon('pluginManager') - .scrollAndClick('#pluginManager *[data-id="pluginManagerComponentActivateButtonremixd"]') - .waitForElementVisible('*[data-id="remixdConnect-modal-footer-ok-react"]', 2000) - .pause(2000) - .click('*[data-id="remixdConnect-modal-footer-ok-react"]') - .pause(5000) - .perform(() => done()) -} diff --git a/apps/remix-ide-e2e/src/tests/remixd.test.ts b/apps/remix-ide-e2e/src/tests/remixd.test.ts index 4aebbf1ac9..8caadc8b17 100644 --- a/apps/remix-ide-e2e/src/tests/remixd.test.ts +++ b/apps/remix-ide-e2e/src/tests/remixd.test.ts @@ -1,6 +1,16 @@ 'use strict' import { NightwatchBrowser } from 'nightwatch' import init from '../helpers/init' +import { join } from 'path' +import { spawn } from 'child_process' +import { writeFileSync } from 'fs' +import * as hardhatCompilation from '../helpers/hardhat_compilation_7839ba878952cc00ff316061405f273a.json' +import * as hardhat_compilation_Lock_dbg from '../helpers/hardhat_compilation_Lock.dbg.json' +import * as hardhat_compilation_Lock from '../helpers/hardhat_compilation_Lock.json' + +import * as foundryCompilation from '../helpers/foundry_compilation.json' +import * as truffle_compilation from '../helpers/truffle_compilation.json' + const assetsTestContract = `import "./contract.sol"; contract Assets { @@ -53,36 +63,60 @@ module.exports = { '@sources': function () { return sources }, - 'start Remixd': function (browser) { - startRemixd(browser) - - }, 'run Remixd tests #group4': function (browser) { - runTests(browser) + let remixd + browser.perform((done) => { + remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts')) + console.log('working directory', process.cwd()) + connectRemixd(browser, done) + }) + .perform((done) => { + runTests(browser, done) + }) + .perform(() => { + remixd.kill() + }) }, 'Import from node_modules #group1': function (browser) { /* when a relative import is used (i.e import "openzeppelin-solidity/contracts/math/SafeMath.sol") remix (as well as truffle) try to resolve it against the node_modules and installed_contracts folder. */ - - browser.waitForElementVisible('#icon-panel', 2000) + let remixd + browser.perform((done) => { + remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts')) + console.log('working directory', process.cwd()) + connectRemixd(browser, done) + }) + .waitForElementVisible('#icon-panel', 2000) .clickLaunchIcon('filePanel') .click('[data-path="ballot.sol"]') .addFile('test_import_node_modules.sol', sources[3]['test_import_node_modules.sol']) .clickLaunchIcon('solidity') .setSolidityCompilerVersion('soljson-v0.5.0+commit.1d4f565a.js') .testContracts('test_import_node_modules.sol', sources[3]['test_import_node_modules.sol'], ['SafeMath']) + .perform(() => { + remixd.kill() + }) }, 'Import from node_modules and reference a github import #group2': function (browser) { - browser.waitForElementVisible('#icon-panel', 2000) + let remixd + browser.perform((done) => { + remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts')) + console.log('working directory', process.cwd()) + connectRemixd(browser, done) + }) + .waitForElementVisible('#icon-panel', 2000) .clickLaunchIcon('filePanel') .addFile('test_import_node_modules_with_github_import.sol', sources[4]['test_import_node_modules_with_github_import.sol']) .clickLaunchIcon('solidity') .setSolidityCompilerVersion('soljson-v0.8.0+commit.c7dfd78e.js') // open-zeppelin moved to pragma ^0.8.0 .testContracts('test_import_node_modules_with_github_import.sol', sources[4]['test_import_node_modules_with_github_import.sol'], ['ERC20', 'test11']) + .perform(() => { + remixd.kill() + }) }, - 'Static Analysis run with remixd #group3': function (browser) { + 'Static Analysis run with remixd #group3': '' + function (browser) { browser.testContracts('test_static_analysis_with_remixd_and_hardhat.sol', sources[5]['test_static_analysis_with_remixd_and_hardhat.sol'], ['test5']).pause(2000) .clickLaunchIcon('solidityStaticAnalysis') /* @@ -108,34 +142,135 @@ module.exports = { .journalLastChildIncludes('On branch ') }, - 'Close Remixd #group3': function (browser) { + 'Close Remixd #group3': '' + function (browser) { browser .clickLaunchIcon('pluginManager') .scrollAndClick('#pluginManager *[data-id="pluginManagerComponentDeactivateButtonremixd"]') - } -} + }, -function startRemixd (browser: NightwatchBrowser) { - const browserName = browser.options.desiredCapabilities.browserName - if (browserName === 'safari' || browserName === 'internet explorer') { - console.log('do not run remixd test for ' + browserName + ': sauce labs doesn\'t seems to handle websocket') - browser.end() - return - } + 'Should listen on compilation result from hardhat #group5': function (browser: NightwatchBrowser) { + let remixd + browser.perform((done) => { + remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts/hardhat')) + console.log('working directory', process.cwd()) + connectRemixd(browser, done) + }) + .perform((done) => { + console.log('generating compilation result') + writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/build-info/7839ba878952cc00ff316061405f273a.json', JSON.stringify(hardhatCompilation)) + writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/contracts/Lock.sol/Lock.json', JSON.stringify(hardhat_compilation_Lock)) + writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/contracts/Lock.sol/Lock.dbg.json', JSON.stringify(hardhat_compilation_Lock_dbg)) + done() + }) + .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from hardhat').before(60000) + + browser.clickLaunchIcon('filePanel') + .openFile('contracts/Lock.sol') + .clickLaunchIcon('udapp') + .selectContract('Lock') + .createContract('1') + .expect.element('*[data-id="terminalJournal"]').text.to.contain('Unlock time should be in the future').before(60000) - browser - .waitForElementVisible('#icon-panel', 2000) - .clickLaunchIcon('filePanel') - .clickLaunchIcon('pluginManager') - .scrollAndClick('#pluginManager *[data-id="pluginManagerComponentActivateButtonremixd"]') - .waitForElementVisible('*[data-id="remixdConnect-modal-footer-ok-react"]', 2000) - .pause(2000) - .click('*[data-id="remixdConnect-modal-footer-ok-react"]') - .pause(10000) - // .click('*[data-id="workspacesModalDialog-modal-footer-ok-react"]') + browser.perform(() => { + remixd.kill() + }) + }, + + 'Should load compilation result from hardhat when remixd connects #group6': function (browser: NightwatchBrowser) { + // artifacts/build-info/c7062fdd360381a85af23eeef31c98f8.json has already been created + let remixd + browser + .perform((done) => { + writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/contracts/Lock.sol/Lock.dbg.json', JSON.stringify(hardhat_compilation_Lock_dbg)) + writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/contracts/Lock.sol/Lock.json', JSON.stringify(hardhat_compilation_Lock)) + writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/build-info/7839ba878952cc00ff316061405f273a.json', JSON.stringify(hardhatCompilation)) + done() + }) + .perform((done) => { + remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts/hardhat')) + console.log('working directory', process.cwd()) + connectRemixd(browser, done) + }) + .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from hardhat').before(60000) + + browser.clickLaunchIcon('filePanel') + .openFile('contracts/Lock.sol') + .clickLaunchIcon('udapp') + .selectContract('Lock') + .createContract('1') + .expect.element('*[data-id="terminalJournal"]').text.to.contain('Unlock time should be in the future').before(60000) + + browser.perform(() => { + remixd.kill() + }) + }, + + 'Should listen on compilation result from foundry #group7': function (browser: NightwatchBrowser) { + let remixd + browser.perform((done) => { + remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts/foundry')) + console.log('working directory', process.cwd()) + connectRemixd(browser, done) + }) + .perform((done) => { + writeFileSync('./apps/remix-ide/contracts/foundry/out/Counter.sol/Counter.json', JSON.stringify(foundryCompilation)) + done() + }) + .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from foundry').before(60000) + + let contractAaddress + browser.clickLaunchIcon('filePanel') + .openFile('src/Counter.sol') + .clickLaunchIcon('udapp') + .selectContract('Counter') + .createContract('') + .getAddressAtPosition(0, (address) => { + console.log(contractAaddress) + contractAaddress = address + }) + .clickInstance(0) + .clickFunction('increment - transact (not payable)') + .perform((done) => { + browser.testConstantFunction(contractAaddress, 'number - call', null, '0:\nuint256: 1').perform(() => { + done() + }) + }) + + browser.perform(() => { + remixd.kill() + }) + }, + + 'Should listen on compilation result from truffle #group8': function (browser: NightwatchBrowser) { + let remixd + browser.perform((done) => { + remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts/truffle')) + console.log('working directory', process.cwd()) + connectRemixd(browser, done) + }) + .perform((done) => { + writeFileSync('./apps/remix-ide/contracts/truffle/build/contracts/Migrations.json', JSON.stringify(truffle_compilation)) + done() + }) + .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from truffle').before(60000) + + browser.clickLaunchIcon('filePanel') + .openFile('contracts/Migrations.sol') + .clickLaunchIcon('udapp') + .selectContract('Migrations') + .createContract('') + .testFunction('last', + { + status: 'true Transaction mined and execution succeed' + }) + + browser.perform(() => { + remixd.kill() + }) + } } -function runTests (browser: NightwatchBrowser) { +function runTests (browser: NightwatchBrowser, done: any) { const browserName = browser.options.desiredCapabilities.browserName browser.clickLaunchIcon('filePanel') .waitForElementVisible('[data-path="folder1"]') @@ -167,6 +302,7 @@ function runTests (browser: NightwatchBrowser) { .waitForElementVisible('[data-path="folder1/renamed_contract_' + browserName + '.sol"]') // check if renamed file is preset .waitForElementNotPresent('[data-path="folder1/contract_' + browserName + '.sol"]') // check if renamed (old) file is not present .waitForElementNotPresent('[data-path="folder1/contract_' + browserName + '_toremove.sol"]') // check if removed (old) file is not present + .perform(done) // .click('[data-path="folder1/renamed_contract_' + browserName + '.sol"]') } @@ -182,3 +318,37 @@ function testImportFromRemixd (browser: NightwatchBrowser, callback: VoidFunctio .verifyContracts(['Assets', 'gmbh']) .perform(() => { callback() }) } + +function spawnRemixd (path: string) { + const remixd = spawn('yarn run remixd', [`-s ${path}`], { cwd: process.cwd(), shell: true }) + remixd.stdout.on('data', function(data) { + console.log('stdout: ' + data.toString()) + }) + remixd.stderr.on('err', function(data) { + console.log('err: ' + data.toString()) + }) + return remixd +} + +function connectRemixd (browser: NightwatchBrowser, done: any) { + const browserName = browser.options.desiredCapabilities.browserName + if (browserName === 'safari' || browserName === 'internet explorer') { + console.log('do not run remixd test for ' + browserName + ': sauce labs doesn\'t seems to handle websocket') + browser.end() + done() + return + } + + browser + .pause(5000) + .waitForElementVisible('#icon-panel', 2000) + .clickLaunchIcon('filePanel') + .clickLaunchIcon('pluginManager') + .scrollAndClick('#pluginManager *[data-id="pluginManagerComponentActivateButtonremixd"]') + .waitForElementVisible('*[data-id="remixdConnect-modal-footer-ok-react"]', 2000) + .pause(2000) + .click('*[data-id="remixdConnect-modal-footer-ok-react"]') + .pause(5000) + .perform(() => done()) +} + diff --git a/apps/remix-ide/ci/browser_test.sh b/apps/remix-ide/ci/browser_test.sh index 1ae86c2319..65f5960a9b 100755 --- a/apps/remix-ide/ci/browser_test.sh +++ b/apps/remix-ide/ci/browser_test.sh @@ -11,7 +11,6 @@ TEST_EXITCODE=0 yarn run ganache-cli & yarn run serve:production & echo 'sharing folder: ' $PWD '/apps/remix-ide/contracts' & -yarn run remixd -s ./apps/remix-ide/contracts & sleep 5 diff --git a/apps/remix-ide/ci/flaky.sh b/apps/remix-ide/ci/flaky.sh index 0b6cfd011f..df38c62885 100755 --- a/apps/remix-ide/ci/flaky.sh +++ b/apps/remix-ide/ci/flaky.sh @@ -21,7 +21,6 @@ TEST_EXITCODE=0 yarn run ganache-cli & yarn run serve:production & echo 'sharing folder: ' $PWD '/apps/remix-ide/contracts' & -yarn run remixd -s ./apps/remix-ide/contracts & npx nx serve remix-ide-e2e-src-local-plugin & sleep 5