Merge branch 'master' of https://github.com/ethereum/remix-project into rendercomponent
commit
6f0ec08b24
@ -0,0 +1,39 @@ |
||||
'use strict' |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import init from '../helpers/init' |
||||
|
||||
module.exports = { |
||||
before: function (browser: NightwatchBrowser, done: VoidFunction) { |
||||
init(browser, done, 'http://127.0.0.1:8080?e2e_testmigration=true', false) |
||||
}, |
||||
'Should have README file with TEST README as content': function (browser: NightwatchBrowser) { |
||||
browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]', 5000) |
||||
.waitForElementVisible('div[data-id="filePanelFileExplorerTree"]') |
||||
.openFile('TEST_README.txt') |
||||
.getEditorValue((content) => { |
||||
browser.assert.equal(content, 'TEST README') |
||||
}) |
||||
}, |
||||
'Should have a workspace_test': function (browser: NightwatchBrowser) { |
||||
browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]', 5000) |
||||
.click('*[data-id="workspacesSelect"] option[value="workspace_test"]') |
||||
.waitForElementVisible('*[data-id="treeViewLitreeViewItemtest_contracts"]') |
||||
}, |
||||
'Should have a sol file with test data': function (browser: NightwatchBrowser) { |
||||
browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]', 5000) |
||||
.click('*[data-id="treeViewLitreeViewItemtest_contracts"]') |
||||
.openFile('test_contracts/1_Storage.sol') |
||||
.getEditorValue((content) => { |
||||
browser.assert.equal(content, 'testing') |
||||
}) |
||||
}, |
||||
'Should have a artifacts file with JSON test data': function (browser: NightwatchBrowser) { |
||||
browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]', 5000) |
||||
.click('*[data-id="treeViewLitreeViewItemtest_contracts/artifacts"]') |
||||
.openFile('test_contracts/artifacts/Storage_metadata.json') |
||||
.getEditorValue((content) => { |
||||
const metadata = JSON.parse(content) |
||||
browser.assert.equal(metadata.test, 'data') |
||||
}) |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
import { Plugin } from '@remixproject/engine'; |
||||
|
||||
const profile = { |
||||
name: 'storage', |
||||
displayName: 'Storage', |
||||
description: 'Storage', |
||||
methods: ['getStorage'] |
||||
}; |
||||
|
||||
export class StoragePlugin extends Plugin { |
||||
constructor() { |
||||
super(profile); |
||||
} |
||||
|
||||
async getStorage() { |
||||
if ('storage' in navigator && 'estimate' in navigator.storage) { |
||||
return navigator.storage.estimate() |
||||
} else { |
||||
throw new Error("Can't get storage quota"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,107 @@ |
||||
/* eslint-disable prefer-promise-reject-errors */ |
||||
function urlParams () { |
||||
var qs = window.location.hash.substr(1) |
||||
|
||||
if (window.location.search.length > 0) { |
||||
// use legacy query params instead of hash
|
||||
window.location.hash = window.location.search.substr(1) |
||||
window.location.search = '' |
||||
} |
||||
|
||||
var params = {} |
||||
var parts = qs.split('&') |
||||
for (var x in parts) { |
||||
var keyValue = parts[x].split('=') |
||||
if (keyValue[0] !== '') { |
||||
params[keyValue[0]] = keyValue[1] |
||||
} |
||||
} |
||||
return params |
||||
} |
||||
const defaultVersion = '0.8.0' |
||||
const versionToLoad = urlParams().appVersion ? urlParams().appVersion : defaultVersion |
||||
|
||||
const assets = { |
||||
'0.8.0': ['https://use.fontawesome.com/releases/v5.8.1/css/all.css', 'assets/css/pygment_trac.css'], |
||||
'0.7.7': ['assets/css/font-awesome.min.css', 'assets/css/pygment_trac.css'] |
||||
} |
||||
const versions = { |
||||
'0.7.7': 'assets/js/0.7.7/app.js', // commit 7b5c7ae3de935e0ccc32eadfd83bf7349478491e
|
||||
'0.8.0': 'main.js' |
||||
} |
||||
for (const k in assets[versionToLoad]) { |
||||
const app = document.createElement('link') |
||||
app.setAttribute('rel', 'stylesheet') |
||||
app.setAttribute('href', assets[versionToLoad][k]) |
||||
if (assets[versionToLoad][k] === 'https://use.fontawesome.com/releases/v5.8.1/css/all.css') { |
||||
app.setAttribute('integrity', 'sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf') |
||||
app.setAttribute('crossorigin', 'anonymous') |
||||
} |
||||
document.head.appendChild(app) |
||||
} |
||||
|
||||
window.onload = () => { |
||||
// eslint-disable-next-line no-undef
|
||||
class RemixFileSystem extends LightningFS { |
||||
constructor (...t) { |
||||
super(...t) |
||||
this.addSlash = (file) => { |
||||
if (!file.startsWith('/')) file = '/' + file |
||||
return file |
||||
} |
||||
this.base = this.promises |
||||
this.promises = { |
||||
...this.promises, |
||||
|
||||
exists: async (path) => { |
||||
return new Promise((resolve, reject) => { |
||||
this.base.stat(this.addSlash(path)).then(() => resolve(true)).catch(() => resolve(false)) |
||||
}) |
||||
}, |
||||
rmdir: async (path) => { |
||||
return this.base.rmdir(this.addSlash(path)) |
||||
}, |
||||
readdir: async (path) => { |
||||
return this.base.readdir(this.addSlash(path)) |
||||
}, |
||||
unlink: async (path) => { |
||||
return this.base.unlink(this.addSlash(path)) |
||||
}, |
||||
mkdir: async (path) => { |
||||
return this.base.mkdir(this.addSlash(path)) |
||||
}, |
||||
readFile: async (path, options) => { |
||||
return this.base.readFile(this.addSlash(path), options) |
||||
}, |
||||
rename: async (from, to) => { |
||||
return this.base.rename(this.addSlash(from), this.addSlash(to)) |
||||
}, |
||||
writeFile: async (path, content, options) => { |
||||
return this.base.writeFile(this.addSlash(path), content, options) |
||||
}, |
||||
stat: async (path) => { |
||||
return this.base.stat(this.addSlash(path)) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
function loadApp () { |
||||
const app = document.createElement('script') |
||||
app.setAttribute('src', versions[versionToLoad]) |
||||
document.body.appendChild(app) |
||||
} |
||||
|
||||
window.remixFileSystemCallback = new RemixFileSystem() |
||||
window.remixFileSystemCallback.init('RemixFileSystem').then(() => { |
||||
window.remixFileSystem = window.remixFileSystemCallback.promises |
||||
// check if .workspaces is present in indexeddb
|
||||
window.remixFileSystem.stat('.workspaces').then((dir) => { |
||||
if (dir.isDirectory()) loadApp() |
||||
}).catch(() => { |
||||
// no indexeddb .workspaces -> run migration
|
||||
// eslint-disable-next-line no-undef
|
||||
migrateFilesFromLocalStorage(loadApp) |
||||
}) |
||||
}) |
||||
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,139 @@ |
||||
// eslint-disable-next-line no-unused-vars
|
||||
async function migrateFilesFromLocalStorage (cb) { |
||||
let testmigration = false // migration loads test data into localstorage with browserfs
|
||||
// indexeddb will be empty by this point, so there is no danger but do a check for the origin to load test data so it runs only locally
|
||||
testmigration = window.location.hash.includes('e2e_testmigration=true') && window.location.host === '127.0.0.1:8080' && window.location.protocol === 'http:' |
||||
// eslint-disable-next-line no-undef
|
||||
BrowserFS.install(window) |
||||
// eslint-disable-next-line no-undef
|
||||
BrowserFS.configure({ |
||||
fs: 'LocalStorage' |
||||
}, async function (e) { |
||||
if (e) console.log(e) |
||||
|
||||
const browserFS = window.require('fs') |
||||
|
||||
/** |
||||
* copy the folder recursively (internal use) |
||||
* @param {string} path is the folder to be copied over |
||||
* @param {Function} visitFile is a function called for each visited files |
||||
* @param {Function} visitFolder is a function called for each visited folders |
||||
*/ |
||||
async function _copyFolderToJsonInternal (path, visitFile, visitFolder, fs) { |
||||
visitFile = visitFile || (() => { }) |
||||
visitFolder = visitFolder || (() => { }) |
||||
return new Promise((resolve, reject) => { |
||||
const json = {} |
||||
if (fs.existsSync(path)) { |
||||
try { |
||||
const items = fs.readdirSync(path) |
||||
visitFolder({ path }) |
||||
if (items.length !== 0) { |
||||
items.forEach(async (item, index) => { |
||||
const file = {} |
||||
const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}` |
||||
if (fs.statSync(curPath).isDirectory()) { |
||||
file.children = await _copyFolderToJsonInternal(curPath, visitFile, visitFolder, fs) |
||||
} else { |
||||
file.content = fs.readFileSync(curPath, 'utf8') |
||||
visitFile({ path: curPath, content: file.content }) |
||||
} |
||||
json[curPath] = file |
||||
}) |
||||
} |
||||
} catch (e) { |
||||
console.log(e) |
||||
return reject(e) |
||||
} |
||||
} |
||||
return resolve(json) |
||||
}) |
||||
} |
||||
|
||||
/** |
||||
* copy the folder recursively |
||||
* @param {string} path is the folder to be copied over |
||||
* @param {Function} visitFile is a function called for each visited files |
||||
* @param {Function} visitFolder is a function called for each visited folders |
||||
*/ |
||||
async function copyFolderToJson (path, visitFile, visitFolder, fs) { |
||||
visitFile = visitFile || (() => { }) |
||||
visitFolder = visitFolder || (() => { }) |
||||
return _copyFolderToJsonInternal(path, visitFile, visitFolder, fs) |
||||
} |
||||
|
||||
const populateWorkspace = async (json, fs) => { |
||||
for (const item in json) { |
||||
const isFolder = json[item].content === undefined |
||||
if (isFolder) { |
||||
await createDir(item, fs) |
||||
await populateWorkspace(json[item].children, fs) |
||||
} else { |
||||
try { |
||||
await fs.writeFile(item, json[item].content, 'utf8') |
||||
} catch (error) { |
||||
console.log(error) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
const createDir = async (path, fs) => { |
||||
const paths = path.split('/') |
||||
if (paths.length && paths[0] === '') paths.shift() |
||||
let currentCheck = '' |
||||
for (const value of paths) { |
||||
currentCheck = currentCheck + (currentCheck ? '/' : '') + value |
||||
if (!await fs.exists(currentCheck)) { |
||||
try { |
||||
await fs.mkdir(currentCheck) |
||||
} catch (error) { |
||||
console.log(error) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
//
|
||||
if (testmigration) await populateWorkspace(testData, browserFS) |
||||
const files = await copyFolderToJson('/', null, null, browserFS) |
||||
await populateWorkspace(files, window.remixFileSystem) |
||||
// eslint-disable-next-line no-undef
|
||||
if (cb) cb() |
||||
}) |
||||
} |
||||
|
||||
/* eslint-disable no-template-curly-in-string */ |
||||
const testData = { |
||||
'.workspaces': { |
||||
children: { |
||||
'.workspaces/default_workspace': { |
||||
children: { |
||||
'.workspaces/default_workspace/README.txt': { |
||||
content: 'TEST README' |
||||
} |
||||
} |
||||
}, |
||||
'.workspaces/workspace_test': { |
||||
children: { |
||||
'.workspaces/workspace_test/TEST_README.txt': { |
||||
content: 'TEST README' |
||||
}, |
||||
'.workspaces/workspace_test/test_contracts': { |
||||
children: { |
||||
'.workspaces/workspace_test/test_contracts/1_Storage.sol': { |
||||
content: 'testing' |
||||
}, |
||||
'.workspaces/workspace_test/test_contracts/artifacts': { |
||||
children: { |
||||
'.workspaces/workspace_test/test_contracts/artifacts/Storage_metadata.json': { |
||||
content: '{ "test": "data" }' |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue