From 36f768645f555001b051207577170dec59c5556f Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Mon, 30 Aug 2021 18:31:43 +0530 Subject: [PATCH 1/7] show logs for methods not having any assert --- apps/remix-ide/src/app/tabs/test-tab.js | 2 ++ libs/remix-tests/src/testRunner.ts | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 6750efde55..030745e5d1 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -278,6 +278,8 @@ module.exports = class TestTab extends ViewPlugin { `) } + } else if (result.type === 'logOnly') { + if (result.hhLogs && result.hhLogs.length) this.printHHLogs(result.hhLogs, result.value) } } diff --git a/libs/remix-tests/src/testRunner.ts b/libs/remix-tests/src/testRunner.ts index 47b44d708b..c3a800c1d8 100644 --- a/libs/remix-tests/src/testRunner.ts +++ b/libs/remix-tests/src/testRunner.ts @@ -338,6 +338,17 @@ export function runTest (testName: string, testObject: any, contractDetails: Com testCallback(undefined, resp) passingNum += 1 timePassed += time + } else if (hhLogs) { + const resp: TestResultInterface = { + type: 'logOnly', + value: changeCase.sentenceCase(func.name), + filename: testObject.filename, + time: time, + context: testName, + hhLogs + } + testCallback(undefined, resp) + timePassed += time } return next() From 3c35257e7de2306bc5249a477108659670c29879 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 31 Aug 2021 12:53:46 +0530 Subject: [PATCH 2/7] show logs for method call --- libs/remix-tests/src/testRunner.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/remix-tests/src/testRunner.ts b/libs/remix-tests/src/testRunner.ts index c3a800c1d8..ffc2cecde4 100644 --- a/libs/remix-tests/src/testRunner.ts +++ b/libs/remix-tests/src/testRunner.ts @@ -244,8 +244,15 @@ export function runTest (testName: string, testObject: any, contractDetails: Com const method = testObject.methods[func.name].apply(testObject.methods[func.name], []) const startTime = Date.now() if (func.constant) { - method.call(sendParams).then((result) => { + sendParams = {} + const tagTimestamp = 'remix_tests_tag' + Date.now() + sendParams.timestamp = tagTimestamp + method.call(sendParams).then(async (result) => { const time = (Date.now() - startTime) / 1000.0 + let tagTxHash + let hhLogs + if (web3.eth && web3.eth.getHashFromTagBySimulator) tagTxHash = await web3.eth.getHashFromTagBySimulator(tagTimestamp) + if (web3.eth && web3.eth.getHHLogsForTx) hhLogs = await web3.eth.getHHLogsForTx(tagTxHash) if (result) { const resp: TestResultInterface = { type: 'testPass', @@ -254,6 +261,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com time: time, context: testName } + if (hhLogs) resp.hhLogs = hhLogs testCallback(undefined, resp) passingNum += 1 timePassed += time @@ -266,6 +274,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com errMsg: 'function returned false', context: testName } + if (hhLogs) resp.hhLogs = hhLogs testCallback(undefined, resp) failureNum += 1 timePassed += time From e90747a13500732ae7a77e7a3afbb236eb085793 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 30 Aug 2021 11:27:46 +0200 Subject: [PATCH 3/7] fix loading compiler in unit testing --- .../src/compiler/compiler-utils.ts | 18 +++++++++++++++--- .../src/lib/compiler-container.tsx | 18 +++++++----------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/libs/remix-solidity/src/compiler/compiler-utils.ts b/libs/remix-solidity/src/compiler/compiler-utils.ts index da3bc487b3..7e19ae7d8a 100644 --- a/libs/remix-solidity/src/compiler/compiler-utils.ts +++ b/libs/remix-solidity/src/compiler/compiler-utils.ts @@ -12,9 +12,21 @@ export const pathToURL = {} * @param version is the version of compiler with or without 'soljson-v' prefix and .js postfix */ export function urlFromVersion (version) { - if (!version.startsWith('soljson-v')) version = 'soljson-v' + version - if (!version.endsWith('.js')) version = version + '.js' - return `${pathToURL[version]}/${version}` + let url + if (version === 'builtin') { + let location: string | Location = window.document.location + let path = location.pathname + if (!path.startsWith('/')) path = '/' + path + location = `${location.protocol}//${location.host}${path}assets/js` + if (location.endsWith('index.html')) location = location.substring(0, location.length - 10) + if (!location.endsWith('/')) location += '/' + url = `${location}soljson.js` + } else { + if (!version.startsWith('soljson-v')) version = 'soljson-v' + version + if (!version.endsWith('.js')) version = version + '.js' + url = `${pathToURL[version]}/${version}` + } + return url } /** diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index 9469121adf..80b1004ab6 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -333,19 +333,15 @@ export const CompilerContainer = (props: CompilerContainerProps) => { updateCurrentVersion(selectedVersion) url = customUrl api.setParameters({ version: selectedVersion }) - } else if (selectedVersion === 'builtin') { - let location: string | Location = window.document.location - let path = location.pathname - if (!path.startsWith('/')) path = '/' + path - location = `${location.protocol}//${location.host}${path}assets/js` - if (location.endsWith('index.html')) location = location.substring(0, location.length - 10) - if (!location.endsWith('/')) location += '/' - url = location + 'soljson.js' } else { - if (selectedVersion.indexOf('soljson') !== 0 || helper.checkSpecialChars(selectedVersion)) { - return console.log('loading ' + selectedVersion + ' not allowed') + if (helper.checkSpecialChars(selectedVersion)) { + return console.log('loading ' + selectedVersion + ' not allowed, special chars not allowed.') + } + if (selectedVersion === 'builtin' || selectedVersion.indexOf('soljson') === 0) { + url = urlFromVersion(selectedVersion) + } else { + return console.log('loading ' + selectedVersion + ' not allowed, version should start with "soljson"') } - url = `${urlFromVersion(selectedVersion)}` } // Workers cannot load js on "file:"-URLs and we get a From 4631d6e55d0ffd0b46fe9af807464a1dea9d022f Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 30 Aug 2021 13:14:31 +0200 Subject: [PATCH 4/7] e2e test: unittesting with local compiler --- .circleci/config.yml | 2 + .../src/tests/solidityUnittests.spec.ts | 54 ++++++++++++------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a7cae9785e..9d0791cd7e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -105,6 +105,7 @@ jobs: steps: - checkout - run: npm install + - run: npm run downloadsolc_assets - run: npx nx build remix-ide --with-deps - run: name: Download Selenium @@ -171,6 +172,7 @@ jobs: steps: - checkout - run: npm install + - run: npm run downloadsolc_assets - run: npx nx build remix-ide --with-deps - run: name: Download Selenium diff --git a/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts b/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts index 2c3a43ebc4..a46781eaea 100644 --- a/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts +++ b/apps/remix-ide-e2e/src/tests/solidityUnittests.spec.ts @@ -166,27 +166,41 @@ module.exports = { .verify.attributeEquals('*[data-id="uiPathInput"]', 'value', 'tests') }, - 'Solidity Unittests': function (browser: NightwatchBrowser) { - runTests(browser) - } -} + 'Solidity Unit tests Basic': function (browser: NightwatchBrowser) { + browser + .waitForElementPresent('*[data-id="verticalIconsKindfilePanel"]') + .clickLaunchIcon('filePanel') + .click('*[data-id="treeViewLitreeViewItemcontracts"]') + .openFile('contracts/3_Ballot.sol') + .clickLaunchIcon('solidityUnitTesting') + .pause(2000) + .verify.attributeEquals('*[data-id="uiPathInput"]', 'value', 'tests') + .scrollAndClick('#runTestsTabRunAction') + .waitForElementVisible('*[data-id="testTabSolidityUnitTestsOutputheader"]', 120000) + .waitForElementPresent('#solidityUnittestsOutput div[class^="testPass"]', 60000) + .waitForElementContainsText('#solidityUnittestsOutput', '/tests/4_Ballot_test.sol', 60000) + .waitForElementContainsText('#solidityUnittestsOutput', '✓ Check winning proposal', 60000) + .waitForElementContainsText('#solidityUnittestsOutput', '✓ Check winnin proposal with return value', 60000) + }, -function runTests (browser: NightwatchBrowser) { - browser - .waitForElementPresent('*[data-id="verticalIconsKindfilePanel"]') - .clickLaunchIcon('filePanel') - .click('*[data-id="treeViewLitreeViewItemcontracts"]') - .openFile('contracts/3_Ballot.sol') - .clickLaunchIcon('solidityUnitTesting') - .pause(2000) - .verify.attributeEquals('*[data-id="uiPathInput"]', 'value', 'tests') - .scrollAndClick('#runTestsTabRunAction') - .waitForElementVisible('*[data-id="testTabSolidityUnitTestsOutputheader"]', 120000) - .waitForElementPresent('#solidityUnittestsOutput div[class^="testPass"]', 60000) - .waitForElementContainsText('#solidityUnittestsOutput', '/tests/4_Ballot_test.sol', 60000) - .waitForElementContainsText('#solidityUnittestsOutput', '✓ Check winning proposal', 60000) - .waitForElementContainsText('#solidityUnittestsOutput', '✓ Check winnin proposal with return value', 60000) - .end() + 'Solidity Unit tests Basic Basic with local compiler': function (browser: NightwatchBrowser) { + browser + .clickLaunchIcon('solidity') + .setSolidityCompilerVersion('builtin') + .openFile('contracts/3_Ballot.sol') + .clickLaunchIcon('pluginManager') + .scrollAndClick('[data-id="pluginManagerComponentDeactivateButtonsolidityUnitTesting"]') + .pause(2000) + .scrollAndClick('[data-id="pluginManagerComponentActivateButtonsolidityUnitTesting"]') + .clickLaunchIcon('solidityUnitTesting') + .scrollAndClick('#runTestsTabRunAction') + .waitForElementVisible('*[data-id="testTabSolidityUnitTestsOutputheader"]', 120000) + .waitForElementPresent('#solidityUnittestsOutput div[class^="testPass"]', 60000) + .waitForElementContainsText('#solidityUnittestsOutput', '/tests/4_Ballot_test.sol', 60000) + .waitForElementContainsText('#solidityUnittestsOutput', '✓ Check winning proposal', 60000) + .waitForElementContainsText('#solidityUnittestsOutput', '✓ Check winnin proposal with return value', 60000) + .end() + } } const sources = [ From b2eebb1bb8b41d796d0e6a2158d7b2439e657690 Mon Sep 17 00:00:00 2001 From: lianahus Date: Tue, 31 Aug 2021 12:47:04 +0200 Subject: [PATCH 5/7] adding block.basefee only if there us baseFeePerGas available --- .../debugger-ui/src/lib/vm-debugger/global-variables.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx index db26cf980b..973cc9bd79 100644 --- a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx @@ -5,7 +5,6 @@ import { BN } from 'ethereumjs-util' export const GlobalVariables = ({ block, receipt, tx }) => { // see https://docs.soliditylang.org/en/latest/units-and-global-variables.html#block-and-transaction-properties const globals = { - 'block.basefee': (new BN(block.baseFeePerGas.replace('0x', ''), 'hex')).toString(10) + ` Wei (${block.baseFeePerGas})`, 'block.chainid': tx.chainId, 'block.coinbase': block.miner, 'block.difficulty': block.difficulty, @@ -17,6 +16,9 @@ export const GlobalVariables = ({ block, receipt, tx }) => { 'msg.value': tx.value + ' Wei', 'tx.origin': tx.from } + if (block.baseFeePerGas) + globals['block.basefee'] = (new BN(block.baseFeePerGas.replace('0x', ''), 'hex')).toString(10) + ` Wei (${block.baseFeePerGas})` + return (
From 8b049b8164e8078de6623777cf8e49dfa04481fa Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Tue, 31 Aug 2021 13:06:59 +0200 Subject: [PATCH 6/7] linter --- .../debugger-ui/src/lib/vm-debugger/global-variables.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx index 973cc9bd79..8a2d05c618 100644 --- a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx @@ -16,8 +16,9 @@ export const GlobalVariables = ({ block, receipt, tx }) => { 'msg.value': tx.value + ' Wei', 'tx.origin': tx.from } - if (block.baseFeePerGas) + if (block.baseFeePerGas) { globals['block.basefee'] = (new BN(block.baseFeePerGas.replace('0x', ''), 'hex')).toString(10) + ` Wei (${block.baseFeePerGas})` + ) return (
From 5c08cdd58fc4acf1f7245e92d2604bf36d5ef557 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Tue, 31 Aug 2021 13:34:26 +0200 Subject: [PATCH 7/7] typo --- .../debugger-ui/src/lib/vm-debugger/global-variables.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx index 8a2d05c618..98713182cd 100644 --- a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx @@ -18,7 +18,7 @@ export const GlobalVariables = ({ block, receipt, tx }) => { } if (block.baseFeePerGas) { globals['block.basefee'] = (new BN(block.baseFeePerGas.replace('0x', ''), 'hex')).toString(10) + ` Wei (${block.baseFeePerGas})` - ) + } return (