From 1fe1fd2901d8c12ac15110befe5b2c92fecc2a15 Mon Sep 17 00:00:00 2001 From: David Disu Date: Fri, 3 Jun 2022 16:09:39 +0100 Subject: [PATCH] set details after contract has been parsed --- apps/remix-ide-e2e/src/tests/ballot.test.ts | 3 -- .../solidity-compiler/src/app/compiler-api.ts | 45 +++++++++++++------ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/ballot.test.ts b/apps/remix-ide-e2e/src/tests/ballot.test.ts index ba52a14ed6..3d5dbcdb54 100644 --- a/apps/remix-ide-e2e/src/tests/ballot.test.ts +++ b/apps/remix-ide-e2e/src/tests/ballot.test.ts @@ -121,14 +121,11 @@ module.exports = { .click('*[data-id="scFileConfiguration"]') .waitForElementVisible('*[data-id="scConfigChangeFilePath"]', 10000) .click('*[data-id="scConfigChangeFilePath"]') - .pause(10000) .waitForElementVisible('*[data-id="scConfigFilePathInput"]', 10000) - .click('*[data-id="scConfigFilePathInput]') .clearValue('*[data-id="scConfigFilePathInput"]') .setValue('*[data-id="scConfigFilePathInput"]', 'cf.json') .sendKeys('*[data-id$="scConfigFilePathInput"]', browser.Keys.ENTER) .openFile('Untitled.sol') - .pause(20000) .verifyContracts(['Ballot'], {wait: 2000, runs: '300'}) }, diff --git a/apps/solidity-compiler/src/app/compiler-api.ts b/apps/solidity-compiler/src/app/compiler-api.ts index 47817450a0..4f38068ff0 100644 --- a/apps/solidity-compiler/src/app/compiler-api.ts +++ b/apps/solidity-compiler/src/app/compiler-api.ts @@ -287,23 +287,20 @@ export const CompilerApiMixin = (Base) => class extends Base { type: 'warning' }) } else this.statusChanged({ key: 'succeed', title: 'compilation successful', type: 'success' }) - // Store the contracts - this.compilationDetails.contractsDetails = {} - this.compiler.visitContracts((contract) => { - this.compilationDetails.contractsDetails[contract.name] = parseContracts( - contract.name, - contract.object, - this.compiler.getSource(contract.file) - ) - }) } else { const count = (data.errors ? data.errors.filter(error => error.severity === 'error').length : 0 + (data.error ? 1 : 0)) this.statusChanged({ key: count, title: `compilation failed with ${count} error${count > 1 ? 's' : ''}`, type: 'error' }) } - // Update contract Selection - this.compilationDetails.contractMap = {} - if (success) this.compiler.visitContracts((contract) => { this.compilationDetails.contractMap[contract.name] = contract }) - this.compilationDetails.target = source.target + // Store the contracts and Update contract Selection + if (success) { + this.compilationDetails = await this.visitsContractApi(source) + } else { + this.compilationDetails = { + contractMap: {}, + contractsDetails: {}, + target: source.target + } + } if (this.onCompilationFinished) this.onCompilationFinished(this.compilationDetails) // set annotations if (data.errors) { @@ -347,4 +344,26 @@ export const CompilerApiMixin = (Base) => class extends Base { } window.document.addEventListener('keydown', this.data.eventHandlers.onKeyDown) } + + async visitsContractApi (source): Promise<{ contractMap: { file: string } | Record, contractsDetails: Record, target?: string }> { + return new Promise((resolve) => { + this.compiler.visitContracts((contract) => { + const contractDetails = parseContracts( + contract.name, + contract.object, + this.compiler.getSource(contract.file) + ) + const contractMap = contract + + return resolve({ + contractMap: { + [contract.name]: contractMap + }, contractsDetails: { + [contract.name]: contractDetails + }, + target: source.target + }) + }) + }) + } }