handle url param

pull/1382/head
yann300 3 years ago
parent 71633c513b
commit 8890924687
  1. 16
      apps/remix-ide-e2e/src/tests/url.spec.ts
  2. 21
      apps/remix-ide/src/app/panels/file-panel.js

@ -17,7 +17,7 @@ module.exports = {
return sources
},
'Should load the code from URL params': function (browser: NightwatchBrowser) {
'Should load the code from URL params (code param)': function (browser: NightwatchBrowser) {
browser
.pause(5000)
.url('http://127.0.0.1:8080/#optimize=true&runs=300&evmVersion=istanbul&version=soljson-v0.7.4+commit.3f05b770.js&code=cHJhZ21hIHNvbGlkaXR5ID49MC42LjAgPDAuNy4wOwoKaW1wb3J0ICJodHRwczovL2dpdGh1Yi5jb20vT3BlblplcHBlbGluL29wZW56ZXBwZWxpbi1jb250cmFjdHMvYmxvYi9tYXN0ZXIvY29udHJhY3RzL2FjY2Vzcy9Pd25hYmxlLnNvbCI7Cgpjb250cmFjdCBHZXRQYWlkIGlzIE93bmFibGUgewogIGZ1bmN0aW9uIHdpdGhkcmF3KCkgZXh0ZXJuYWwgb25seU93bmVyIHsKICB9Cn0')
@ -31,6 +31,20 @@ module.exports = {
})
},
'Should load the code from URL params (url param)': function (browser: NightwatchBrowser) {
browser
.pause(5000)
.url('http://127.0.0.1:8080/#optimize=true&runs=300&evmVersion=istanbul&version=soljson-v0.7.4+commit.3f05b770.js&url=https://github.com/ethereum/remix-project/blob/master/apps/remix-ide/contracts/app/solidity/mode.sol')
.refresh() // we do one reload for making sure we already have the default workspace
.pause(5000)
.currentWorkspaceIs('code-sample')
.getEditorValue((content) => {
browser.assert.ok(content.indexOf(
'proposals.length = _numProposals;') !== -1,
'url has not been loaded')
})
},
'Should load using URL compiler params': function (browser: NightwatchBrowser) {
browser
.pause(5000)

@ -165,16 +165,25 @@ module.exports = class Filepanel extends ViewPlugin {
}
if (loadedFromGist) return
if (params.code) {
if (params.code || params.url) {
try {
await this.processCreateWorkspace('code-sample')
this._deps.fileProviders.workspace.setWorkspace('code-sample')
var hash = bufferToHex(keccakFromString(params.code))
const fileName = 'contract-' + hash.replace('0x', '').substring(0, 10) + '.sol'
const path = fileName
await this._deps.fileProviders.workspace.set(path, atob(params.code))
let path = ''
let content = ''
if (params.code) {
var hash = bufferToHex(keccakFromString(params.code))
path = 'contract-' + hash.replace('0x', '').substring(0, 10) + '.sol'
content = atob(params.code)
}
if (params.url) {
const data = await this.call('contentImport', 'resolve', params.url)
path = data.cleanUrl
content = data.content
}
await this._deps.fileProviders.workspace.set(path, content)
this.initialWorkspace = 'code-sample'
await this._deps.fileManager.openFile(fileName)
await this._deps.fileManager.openFile(path)
} catch (e) {
console.error(e)
}

Loading…
Cancel
Save