From 814099493fe626e620c0bfd504a7b0b46dacb1ff Mon Sep 17 00:00:00 2001 From: filip mertens Date: Tue, 8 Mar 2022 11:15:10 +0100 Subject: [PATCH 1/8] don't use look behinds --- libs/remix-ui/search/src/lib/context/context.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index e8ce76e287..c6d36532e6 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -208,11 +208,11 @@ export const SearchProvider = ({ const files = await getDirectory('/', plugin) const pathFilter: any = {} if (state.include){ - const includeWithGlobalExpression = state.include.replaceAll(/(? i.trim()) } if (state.exclude){ - const excludeWithGlobalExpression = state.exclude.replaceAll(/(? i.trim()) } const filteredFiles = files.filter(filePathFilter(pathFilter)).map(file => { From 7d1eb940d35f34dc784da947a0f37628cdbe4f36 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 10 Mar 2022 11:57:37 +0530 Subject: [PATCH 2/8] e2e for mocha testing added --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index f56dccf174..129ec1bc1c 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -104,7 +104,7 @@ module.exports = { .click('[data-id="treeViewDivtreeViewItemcontracts"]') .openFile('contracts/2_Owner.sol') .clickLaunchIcon('solidity') - .click('*[data-id="compilerContainerCompileBtn"]').pause(5000) // compile Owner + .click('*[data-id="compilerContainerCompileBtn"]').pause(20000) // compile Owner .executeScript('remix.execute(\'deployWithEthersJs.js\')') .waitForElementContainsText('*[data-id="terminalJournal"]', 'Contract Address:', 60000) .waitForElementContainsText('*[data-id="terminalJournal"]', '0xd9145CCE52D386f254917e481eB44e9943F39138', 60000) @@ -119,6 +119,28 @@ module.exports = { .waitForElementContainsText('*[data-id="terminalJournal"]', 'newOwner', 60000) .waitForElementContainsText('*[data-id="terminalJournal"]', '0xd9145CCE52D386f254917e481eB44e9943F39138', 60000) }, + 'Run tests using Mocha script and check result is logged in the terminal #group4': function (browser: NightwatchBrowser) { + browser + .click('*[data-id="treeViewDivtreeViewItem"]') + .addFile('scripts/storage.test.js', { content: storageMochaTests }) + .pause(1000) + .click('[data-id="treeViewDivtreeViewItemcontracts"]') + .openFile('contracts/1_Storage.sol') + .clickLaunchIcon('solidity') + .click('*[data-id="compilerContainerCompileBtn"]') + .pause(10000) // compile Storage + .executeScript('remix.execute(\'scripts/storage.test.js\')') + .pause(5000) + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Running tests....') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'storage contract Address:') + .waitForElementContainsText('*[data-id="terminalJournal"]', '✓ test initial value') + .waitForElementContainsText('*[data-id="terminalJournal"]', '✓ test updating and retrieving updated value') + .waitForElementContainsText('*[data-id="terminalJournal"]', '✘ fail test updating and retrieving updated value') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Expected: 55') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Actual: 56') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Message: incorrect number: expected 56 to equal 55') + .waitForElementContainsText('*[data-id="terminalJournal"]', '2 passing, 1 failing') + }, 'Should print hardhat logs #group4': function (browser: NightwatchBrowser) { browser @@ -261,6 +283,44 @@ const deployWithEthersJs = ` } })()` +const storageMochaTests = ` +const { expect } = require("chai"); + +describe("Storage", function () { + it("test initial value", async function () { + // Make sure contract is compiled and artifacts are generated + const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'contracts/artifacts/Storage.json')) + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner() + let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer); + let storage = await Storage.deploy(); + console.log('storage contract Address: ' + storage.address); + await storage.deployed() + expect((await storage.retrieve()).toNumber()).to.equal(0); + }); + + it("test updating and retrieving updated value", async function () { + const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'contracts/artifacts/Storage.json')) + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner() + let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer); + let storage = await Storage.deploy(); + await storage.deployed() + const setValue = await storage.store(56); + await setValue.wait(); + expect((await storage.retrieve()).toNumber()).to.equal(56); + }); + + it("fail test updating and retrieving updated value", async function () { + const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'contracts/artifacts/Storage.json')) + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner() + let Storage = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer); + let storage = await Storage.deploy(); + await storage.deployed() + const setValue = await storage.store(56); + await setValue.wait(); + expect((await storage.retrieve()).toNumber(), 'incorrect number').to.equal(55); + }); +});` + const hardhatLog = ` // SPDX-License-Identifier: GPL-3.0 From 11529f0b2de923abc5c6cce6e3401024e4c9d999 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 10 Mar 2022 12:37:56 +0530 Subject: [PATCH 3/8] fix e2e --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index 129ec1bc1c..c574eef214 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -119,12 +119,11 @@ module.exports = { .waitForElementContainsText('*[data-id="terminalJournal"]', 'newOwner', 60000) .waitForElementContainsText('*[data-id="terminalJournal"]', '0xd9145CCE52D386f254917e481eB44e9943F39138', 60000) }, - 'Run tests using Mocha script and check result is logged in the terminal #group4': function (browser: NightwatchBrowser) { + 'Run tests using Mocha script and check result logging in the terminal #group4': function (browser: NightwatchBrowser) { browser .click('*[data-id="treeViewDivtreeViewItem"]') .addFile('scripts/storage.test.js', { content: storageMochaTests }) .pause(1000) - .click('[data-id="treeViewDivtreeViewItemcontracts"]') .openFile('contracts/1_Storage.sol') .clickLaunchIcon('solidity') .click('*[data-id="compilerContainerCompileBtn"]') From e8bdb01d2b6bd57fd1086abd9faa11f4c41518bd Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 10 Mar 2022 13:31:20 +0530 Subject: [PATCH 4/8] pause --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index c574eef214..a71cffd13b 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -104,7 +104,7 @@ module.exports = { .click('[data-id="treeViewDivtreeViewItemcontracts"]') .openFile('contracts/2_Owner.sol') .clickLaunchIcon('solidity') - .click('*[data-id="compilerContainerCompileBtn"]').pause(20000) // compile Owner + .click('*[data-id="compilerContainerCompileBtn"]').pause(5000) // compile Owner .executeScript('remix.execute(\'deployWithEthersJs.js\')') .waitForElementContainsText('*[data-id="terminalJournal"]', 'Contract Address:', 60000) .waitForElementContainsText('*[data-id="terminalJournal"]', '0xd9145CCE52D386f254917e481eB44e9943F39138', 60000) @@ -127,9 +127,9 @@ module.exports = { .openFile('contracts/1_Storage.sol') .clickLaunchIcon('solidity') .click('*[data-id="compilerContainerCompileBtn"]') - .pause(10000) // compile Storage + .pause(2000) // compile Storage .executeScript('remix.execute(\'scripts/storage.test.js\')') - .pause(5000) + .pause(1000) .waitForElementContainsText('*[data-id="terminalJournal"]', 'Running tests....') .waitForElementContainsText('*[data-id="terminalJournal"]', 'storage contract Address:') .waitForElementContainsText('*[data-id="terminalJournal"]', '✓ test initial value') From ad3870af0e2fbdce197a7aebb4e0697e6ab1f77a Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 10 Mar 2022 09:27:38 +0100 Subject: [PATCH 5/8] fix decoding events --- libs/remix-lib/src/execution/eventsDecoder.ts | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/libs/remix-lib/src/execution/eventsDecoder.ts b/libs/remix-lib/src/execution/eventsDecoder.ts index 4622b245fd..cdb794fd71 100644 --- a/libs/remix-lib/src/execution/eventsDecoder.ts +++ b/libs/remix-lib/src/execution/eventsDecoder.ts @@ -56,21 +56,22 @@ export class EventsDecoder { return eventsABI } - _event (hash: string, eventsABI: Record, contractName: string) { - const events = eventsABI[contractName] - if (!events) return null - - if (events[hash]) { - const event = events[hash] - for (const input of event.inputs) { - if (input.type === 'function') { - input.type = 'bytes24' - input.baseType = 'bytes24' + _event (hash, eventsABI) { + // get all the events responding to that hash. + const contracts = [] + for (const k in eventsABI) { + if (eventsABI[k][hash]) { + const event = eventsABI[k][hash] + for (const input of event.inputs) { + if (input.type === 'function') { + input.type = 'bytes24' + input.baseType = 'bytes24' + } } + contracts.push(event) } - return event } - return null + return contracts } _stringifyBigNumber (value): string { @@ -95,16 +96,23 @@ export class EventsDecoder { // [address, topics, mem] const log = logs[i] const topicId = log.topics[0] - const eventAbi = this._event(topicId.replace('0x', ''), eventsABI, contractName) - if (eventAbi) { - const decodedlog = eventAbi.abi.parseLog(log) - const decoded = {} - for (const v in decodedlog.args) { - decoded[v] = this._stringifyEvent(decodedlog.args[v]) + const eventAbis = this._event(topicId.replace('0x', ''), eventsABI) + for (const eventAbi of eventAbis) { + try { + if (eventAbi) { + const decodedlog = eventAbi.abi.parseLog(log) + const decoded = {} + for (const v in decodedlog.args) { + decoded[v] = this._stringifyEvent(decodedlog.args[v]) + } + events.push({ from: log.address, topic: topicId, event: eventAbi.event, args: decoded }) + } else { + events.push({ from: log.address, data: log.data, topics: log.topics }) + } + break // if one of the iteration is successful + } catch (e) { + continue } - events.push({ from: log.address, topic: topicId, event: eventAbi.event, args: decoded }) - } else { - events.push({ from: log.address, data: log.data, topics: log.topics }) } } cb(null, { decoded: events, raw: logs }) From 39b07226d758dd441b04fd11ee4094ab7163d329 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 10 Mar 2022 11:20:11 +0100 Subject: [PATCH 6/8] fix regex --- .../search/src/lib/context/context.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index c6d36532e6..bbc3c72795 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -202,18 +202,28 @@ export const SearchProvider = ({ } }, []) + //*.sol, **/*.txt, contracts/* + const setGlobalExpression = (paths: string) => { + const results = [] + paths.split(',').forEach(path => { + path = path.trim() + if(path.startsWith('*.')) path = path.replace(/(\*\.)/g, '**/*.') + if(path.endsWith('/*') && !path.endsWith('/**/*')) path = path.replace(/(\*)/g, '**/*.*') + results.push(path) + }) + return results + } + useEffect(() => { if (state.find) { (async () => { const files = await getDirectory('/', plugin) const pathFilter: any = {} if (state.include){ - const includeWithGlobalExpression = state.include.replaceAll(/(\*\.)/g, '**/*.') - pathFilter.include = includeWithGlobalExpression.split(',').map(i => i.trim()) + pathFilter.include = setGlobalExpression(state.include) } if (state.exclude){ - const excludeWithGlobalExpression = state.exclude.replaceAll(/(\*\.)/g, '**/*.') - pathFilter.exclude = excludeWithGlobalExpression.split(',').map(i => i.trim()) + pathFilter.exclude = setGlobalExpression(state.exclude) } const filteredFiles = files.filter(filePathFilter(pathFilter)).map(file => { const r: SearchResult = { From 0cadea9798b4b582b3e67944681c462d25b82eed Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 10 Mar 2022 17:57:54 +0530 Subject: [PATCH 7/8] removed click --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index a71cffd13b..5913e4bf63 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -121,13 +121,12 @@ module.exports = { }, 'Run tests using Mocha script and check result logging in the terminal #group4': function (browser: NightwatchBrowser) { browser - .click('*[data-id="treeViewDivtreeViewItem"]') .addFile('scripts/storage.test.js', { content: storageMochaTests }) .pause(1000) .openFile('contracts/1_Storage.sol') .clickLaunchIcon('solidity') .click('*[data-id="compilerContainerCompileBtn"]') - .pause(2000) // compile Storage + .pause(1000) // compile Storage .executeScript('remix.execute(\'scripts/storage.test.js\')') .pause(1000) .waitForElementContainsText('*[data-id="terminalJournal"]', 'Running tests....') From 1a3a24ddbcd2bbddcc43f81dcbb50c9a31c26a2c Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 10 Mar 2022 19:22:51 +0530 Subject: [PATCH 8/8] e2e for contract wiht lib --- apps/remix-ide-e2e/src/tests/terminal.test.ts | 112 +++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index 5913e4bf63..0f90f84199 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -139,7 +139,27 @@ module.exports = { .waitForElementContainsText('*[data-id="terminalJournal"]', 'Message: incorrect number: expected 56 to equal 55') .waitForElementContainsText('*[data-id="terminalJournal"]', '2 passing, 1 failing') }, - + 'Run tests using Mocha for a contract with library deployment and check result logging in the terminal #group4': function (browser: NightwatchBrowser) { + browser + .addFile('scripts/storageWithLib.test.js', { content: storageWithLibMochaTests }) + .pause(1000) + .click('[data-id="treeViewDivtreeViewItemcontracts"]') + .addFile('contracts/StorageWithLib.sol', { content: storageWithLibContract }) + .openFile('contracts/StorageWithLib.sol') + .clickLaunchIcon('solidity') + .click('*[data-id="compilerContainerCompileBtn"]') + .pause(1000) // compile StorageWithLib + .executeScript('remix.execute(\'scripts/storageWithLib.test.js\')') + .pause(1000) + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Running tests....') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Storage with lib') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'deploying lib:') + .waitForElementContainsText('*[data-id="terminalJournal"]', '✘ test library integration by calling a lib method') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Expected: 34') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Actual: 14') + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Message: expected \'14\' to equal \'34\'') + .waitForElementContainsText('*[data-id="terminalJournal"]', '0 passing, 1 failing') + }, 'Should print hardhat logs #group4': function (browser: NightwatchBrowser) { browser .click('*[data-id="terminalClearConsole"]') // clear the terminal @@ -284,7 +304,7 @@ const deployWithEthersJs = ` const storageMochaTests = ` const { expect } = require("chai"); -describe("Storage", function () { +describe("Storage with lib", function () { it("test initial value", async function () { // Make sure contract is compiled and artifacts are generated const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'contracts/artifacts/Storage.json')) @@ -319,6 +339,94 @@ describe("Storage", function () { }); });` +const storageWithLibContract = ` +// SPDX-License-Identifier: GPL-3.0 + +pragma solidity >=0.7.0 <0.9.0; + +library Lib { + function test () public view returns (uint) { + return 14; + } +} +/** + * @title Storage + * @dev Store & retrieve value inr a variable + */ +contract StorageWithLib { + + uint256 number; + + /** + * @dev Store valrue in variable + * @param num value to store + */ + function store(uint256 num) public { + number = num; + } + + /** + * @dev Return value + * @return value of 'number' + */ + function retrieve() public view returns (uint256){ + return number; + } + + function getFromLib() public view returns (uint) { + return Lib.test(); + } +} +` + +const storageWithLibMochaTests = ` +const { expect } = require("chai"); +const { ethers } = require("hardhat"); + +describe("Storage", function () { + it("test library integration by calling a lib method", async function () { + const metadataLib = JSON.parse(await remix.call('fileManager', 'readFile', 'contracts/artifacts/Lib.json')) + console.log('deploying lib:') + const artifactLib = { + contractName: 'Lib', + sourceName: 'contracts/StorageWithLib.sol', + abi: metadataLib.abi, + bytecode: '0x' + metadataLib.data.bytecode.object, + deployedBytecode: '0x' + metadataLib.data.deployedBytecode.object, + linkReferences: metadataLib.data.bytecode.linkReferences, + deployedLinkReferences: metadataLib.data.deployedBytecode.linkReferences, + } + + const optionsLib = {} + const factoryLib = await ethers.getContractFactoryFromArtifact(artifactLib, optionsLib) + const lib = await factoryLib.deploy(); + await lib.deployed() + + const metadata = JSON.parse(await remix.call('fileManager', 'readFile', 'contracts/artifacts/StorageWithLib.json')) + const artifact = { + contractName: 'StorageWithLib', + sourceName: 'contracts/StorageWithLib.sol', + abi: metadata.abi, + bytecode: '0x' + metadata.data.bytecode.object, + deployedBytecode: '0x' + metadata.data.deployedBytecode.object, + linkReferences: metadata.data.bytecode.linkReferences, + deployedLinkReferences: metadata.data.deployedBytecode.linkReferences, + } + const options = { + libraries: { + 'Lib': lib.address + } + } + + const factory = await ethers.getContractFactoryFromArtifact(artifact, options) + const storage = await factory.deploy(); + await storage.deployed() + const storeValue = await storage.store(333); + await storeValue.wait(); + expect((await storage.getFromLib()).toString()).to.equal('34'); + }); +});` + const hardhatLog = ` // SPDX-License-Identifier: GPL-3.0