Merge pull request #518 from ethereum/fixSwithingToError

Fix switch to a github import from a solidity warning
pull/5370/head
yann300 4 years ago committed by GitHub
commit 8a8bd8d4cd
  1. 6
      apps/remix-ide-e2e/src/tests/generalSettings.test.ts
  2. 17
      apps/remix-ide-e2e/src/tests/solidityImport.test.ts
  3. 38
      apps/remix-ide/src/app/ui/renderer.js

@ -178,8 +178,8 @@ const remixIdeThemes = {
primary: '#2A9FD6', primary: '#2A9FD6',
secondary: '#555', secondary: '#555',
success: '#77B300', success: '#77B300',
info: '#9933CC', info: '#93C',
warning: '#FF8800', warning: '#F80',
danger: '#CC0000' danger: '#C00'
} }
} }

@ -58,6 +58,20 @@ module.exports = {
.addFile('Untitled7.sol', sources[6]['browser/Untitled7.sol']) .addFile('Untitled7.sol', sources[6]['browser/Untitled7.sol'])
.clickLaunchIcon('fileExplorers') .clickLaunchIcon('fileExplorers')
.verifyContracts(['test11', 'ERC20', 'SafeMath'], {wait: 10000}) .verifyContracts(['test11', 'ERC20', 'SafeMath'], {wait: 10000})
},
'Test switch to a github import from a solidity warning': function (browser: NightwatchBrowser) {
browser
.setSolidityCompilerVersion('soljson-v0.7.4+commit.3f05b770.js')
.addFile('Untitled8.sol', sources[7]['browser/Untitled8.sol'])
.clickLaunchIcon('fileExplorers')
.clickLaunchIcon('solidity')
.waitForElementPresent('[data-id="compiledErrors"] div:nth-child(3)')
.click('[data-id="compiledErrors"] div:nth-child(3)') // select the second warning which point to ERC20 code
.getEditorValue((content) => {
browser.assert.ok(content.indexOf(`contract ERC20 is Context, IERC20`) != -1,
'current displayed content should be from the ERC20 source code')
})
.end() .end()
}, },
tearDown: sauce tearDown: sauce
@ -85,5 +99,8 @@ const sources = [
}, },
{ {
'browser/Untitled7.sol': {content: 'import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/token/ERC20/ERC20.sol"; contract test11 {}'} 'browser/Untitled7.sol': {content: 'import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/token/ERC20/ERC20.sol"; contract test11 {}'}
},
{
'browser/Untitled8.sol': {content: 'import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/token/ERC20/ERC20.sol"; contract test12 {}'}
} }
] ]

@ -81,18 +81,24 @@ Renderer.prototype.error = function (message, container, opt) {
text = message.innerText text = message.innerText
} }
var errLocation = text.match(/^([^:]*):([0-9]*):(([0-9]*):)? /) // ^ e.g:
if ((!opt.errFile || !opt.errCol || !opt.errLine) && errLocation) { // browser/gm.sol: Warning: Source file does not specify required compiler version! Consider adding "pragma solidity ^0.6.12
errLocation = parseRegExError(errLocation) // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.2.0/contracts/introspection/IERC1820Registry.sol:3:1: ParserError: Source file requires different compiler version (current compiler is 0.7.4+commit.3f05b770.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version
opt.errFile = errLocation.errFile
opt.errLine = errLocation.errLine // extract line / column
opt.errCol = errLocation.errCol let position = text.match(/^(.*?):([0-9]*?):([0-9]*?)?/)
} opt.errLine = position ? parseInt(position[2]) - 1 : -1
opt.errCol = position ? parseInt(position[3]) : -1
// extract file
position = text.match(/^(https:.*?|http:.*?|.*?):/)
opt.errFile = position ? position[1] : ''
if (!opt.noAnnotations && errLocation) { if (!opt.noAnnotations && opt.errFile) {
this._error(errLocation.errFile, { this._error(opt.errFile, {
row: errLocation.errLine, row: opt.errLine,
column: errLocation.errCol, column: opt.errCol,
text: text, text: text,
type: opt.type type: opt.type
}) })
@ -107,7 +113,7 @@ Renderer.prototype.error = function (message, container, opt) {
$error.click((ev) => { $error.click((ev) => {
if (opt.click) { if (opt.click) {
opt.click(message) opt.click(message)
} else if (opt.errFile && opt.errLine && opt.errCol) { } else if (opt.errFile !== undefined && opt.errLine !== undefined && opt.errCol !== undefined) {
this._errorClick(opt.errFile, opt.errLine, opt.errCol) this._errorClick(opt.errFile, opt.errLine, opt.errCol)
} }
}) })
@ -119,12 +125,4 @@ Renderer.prototype.error = function (message, container, opt) {
}) })
} }
function parseRegExError (err) {
return {
errFile: err[1],
errLine: parseInt(err[2], 10) - 1,
errCol: err[4] ? parseInt(err[4], 10) : 0
}
}
module.exports = Renderer module.exports = Renderer

Loading…
Cancel
Save