Merge pull request #913 from ethereum/fixtxsearch

Fix Terminal Search Input
pull/1/head
yann300 7 years ago committed by GitHub
commit febce5aea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      nightwatch.js
  2. 1
      src/app/execution/txListener.js
  3. 13
      src/app/execution/txLogger.js
  4. 65
      src/app/panels/terminal.js
  5. 31
      src/lib/helper.js
  6. 23
      test-browser/helpers/contracts.js
  7. 5
      test-browser/tests/compiling.js

@ -42,7 +42,10 @@ module.exports = {
'javascriptEnabled': true, 'javascriptEnabled': true,
'acceptSslCerts': true, 'acceptSslCerts': true,
'build': 'build-' + TRAVIS_JOB_NUMBER, 'build': 'build-' + TRAVIS_JOB_NUMBER,
'tunnel-identifier': 'browsersolidity_tests_' + TRAVIS_JOB_NUMBER 'tunnel-identifier': 'browsersolidity_tests_' + TRAVIS_JOB_NUMBER,
'chromeOptions': {
'args': ['window-size=2560,1440', 'start-fullscreen']
}
} }
}, },

@ -47,7 +47,6 @@ class TxListener {
input: data, input: data,
hash: txResult.transactionHash ? txResult.transactionHash : 'call' + (from || '') + to + data, hash: txResult.transactionHash ? txResult.transactionHash : 'call' + (from || '') + to + data,
isCall: true, isCall: true,
output: txResult.result,
returnValue: executionContext.isVM() ? txResult.result.vm.return : ethJSUtil.toBuffer(txResult.result), returnValue: executionContext.isVM() ? txResult.result.vm.return : ethJSUtil.toBuffer(txResult.result),
envMode: executionContext.getProvider() envMode: executionContext.getProvider()
} }

@ -65,6 +65,14 @@ class TxLogger {
constructor (opts = {}) { constructor (opts = {}) {
this.event = new EventManager() this.event = new EventManager()
this.opts = opts this.opts = opts
this.seen = {}
function filterTx (value, query) {
if (value.length) {
return helper.find(value, query)
}
return false
}
this.logKnownTX = opts.api.editorpanel.registerCommand('knownTransaction', (args, cmds, append) => { this.logKnownTX = opts.api.editorpanel.registerCommand('knownTransaction', (args, cmds, append) => {
var data = args[0] var data = args[0]
var el var el
@ -73,14 +81,15 @@ class TxLogger {
} else { } else {
el = renderKnownTransaction(this, data) el = renderKnownTransaction(this, data)
} }
this.seen[data.tx.hash] = el
append(el) append(el)
}, { activate: true }) }, { activate: true, filterFn: filterTx })
this.logUnknownTX = opts.api.editorpanel.registerCommand('unknownTransaction', (args, cmds, append) => { this.logUnknownTX = opts.api.editorpanel.registerCommand('unknownTransaction', (args, cmds, append) => {
var data = args[0] var data = args[0]
var el = renderUnknownTransaction(this, data) var el = renderUnknownTransaction(this, data)
append(el) append(el)
}, { activate: false }) }, { activate: false, filterFn: filterTx })
this.logEmptyBlock = opts.api.editorpanel.registerCommand('emptyBlock', (args, cmds, append) => { this.logEmptyBlock = opts.api.editorpanel.registerCommand('emptyBlock', (args, cmds, append) => {
var data = args[0] var data = args[0]

@ -122,7 +122,7 @@ var css = csjs`
} }
.filter { .filter {
${styles.terminal.input_Search_MenuBar} ${styles.terminal.input_Search_MenuBar}
width : 150px; width : 200px;
padding-right : 0px; padding-right : 0px;
margin-right : 0px; margin-right : 0px;
border-top-left-radius : 0px; border-top-left-radius : 0px;
@ -179,7 +179,8 @@ class Terminal {
self.data = { self.data = {
lineLength: opts.lineLength || 80, lineLength: opts.lineLength || 80,
session: [], session: [],
activeFilters: { commands: {}, input: '' } activeFilters: { commands: {}, input: '' },
filterFns: {}
} }
self._view = { el: null, bar: null, input: null, term: null, journal: null, cli: null } self._view = { el: null, bar: null, input: null, term: null, journal: null, cli: null }
self._components = {} self._components = {}
@ -224,6 +225,13 @@ class Terminal {
else scopedCommands.log(output) else scopedCommands.log(output)
}) })
}, { activate: true }) }, { activate: true })
function basicFilter (value, query) { try { return value.indexOf(query) !== -1 } catch (e) { return false } }
self.registerFilter('log', basicFilter)
self.registerFilter('info', basicFilter)
self.registerFilter('error', basicFilter)
self.registerFilter('script', basicFilter)
self._jsSandboxContext = {} self._jsSandboxContext = {}
self._jsSandbox = vm.createContext(self._jsSandboxContext) self._jsSandbox = vm.createContext(self._jsSandboxContext)
if (opts.shell) self._shell = opts.shell if (opts.shell) self._shell = opts.shell
@ -399,9 +407,14 @@ class Terminal {
self.event.trigger('resize', []) self.event.trigger('resize', [])
} }
} }
var filtertimeout = null
function filter (event) { function filter (event) {
var input = event.currentTarget if (filtertimeout) {
self.updateJournal({ type: 'search', value: input.value }) clearTimeout(filtertimeout)
}
filtertimeout = setTimeout(() => {
self.updateJournal({ type: 'search', value: document.querySelector('.' + event.target.className).value })
}, 500)
} }
function clear (event) { function clear (event) {
refocus() refocus()
@ -537,8 +550,8 @@ class Terminal {
var items = self._JOURNAL var items = self._JOURNAL
for (var gidx = 0, len = items.length; gidx < len; gidx++) { for (var gidx = 0, len = items.length; gidx < len; gidx++) {
var item = items[gidx] var item = items[gidx]
if (item) { if (item && self.data.filterFns[item.cmd]) {
var show = query.length ? match(item.args, query) : true var show = query.length ? self.data.filterFns[item.cmd](item.args, query) : true
item.hide = !show item.hide = !show
} }
} }
@ -553,14 +566,6 @@ class Terminal {
self._view.journal.appendChild(df) self._view.journal.appendChild(df)
}) })
} }
_shouldAdd (item) {
var self = this
if (self.data.activeFilters.commands[item.root.cmd]) {
var query = self.data.activeFilters.input
var args = item.args
return query.length ? match(args, query) : true
}
}
_appendItem (item) { _appendItem (item) {
var self = this var self = this
var { el, gidx } = item var { el, gidx } = item
@ -608,6 +613,9 @@ class Terminal {
}) })
return scopedCommands return scopedCommands
} }
registerFilter (commandName, filterFn) {
this.data.filterFns[commandName] = filterFn
}
registerCommand (name, command, opts) { registerCommand (name, command, opts) {
var self = this var self = this
name = String(name) name = String(name)
@ -636,7 +644,7 @@ class Terminal {
item.idx = self._INDEX.commands[cmd].push(item) - 1 item.idx = self._INDEX.commands[cmd].push(item) - 1
item.step = steps.push(item) - 1 item.step = steps.push(item) - 1
item.args = params item.args = params
if (self._shouldAdd(item)) self._appendItem(item) self._appendItem(item)
} }
var scopedCommands = self._scopeCommands(append) var scopedCommands = self._scopeCommands(append)
command(args, scopedCommands, el => append(null, args, blockify(el))) command(args, scopedCommands, el => append(null, args, blockify(el)))
@ -648,6 +656,9 @@ class Terminal {
self.commands[name].toString = _ => { return help } self.commands[name].toString = _ => { return help }
self.commands[name].help = help self.commands[name].help = help
self.data.activeFilters.commands[name] = opts && opts.activate self.data.activeFilters.commands[name] = opts && opts.activate
if (opts.filterFn) {
self.registerFilter(name, opts.filterFn)
}
return self.commands[name] return self.commands[name]
} }
_shell (script, scopedCommands, done) { // default shell _shell (script, scopedCommands, done) { // default shell
@ -675,30 +686,6 @@ function domTerminalFeatures (self, scopedCommands) {
} }
} }
function findDeep (object, fn, found = { break: false, value: undefined }) {
if (typeof object !== 'object' || object === null) return
for (var i in object) {
if (found.break) break
var el = object[i]
if (el && el.innerText !== undefined && el.innerText !== null) el = el.innerText
if (!fn(el, i, object)) findDeep(el, fn, found)
else if (found.break = true) return found.value = el // eslint-disable-line
}
return found.value
}
function match (args, query) {
query = query.trim()
var isMatch = !!findDeep(args, function check (value, key) {
if (value === undefined || value === null) return false
if (typeof value === 'function') return false
if (typeof value === 'object') return false
var contains = String(value).indexOf(query.trim()) !== -1
return contains
})
return isMatch
}
function blockify (el) { return yo`<div class=${css.block}>${el}</div>` } function blockify (el) { return yo`<div class=${css.block}>${el}</div>` }
module.exports = Terminal module.exports = Terminal

@ -19,5 +19,36 @@ module.exports = {
}, },
checkSpecialChars (name) { checkSpecialChars (name) {
return name.match(/[/:*?"<>\\'|]/) != null return name.match(/[/:*?"<>\\'|]/) != null
},
find: find
}
function findDeep (object, fn, found = { break: false, value: undefined }) {
if (typeof object !== 'object' || object === null) return
for (var i in object) {
if (found.break) break
var el = object[i]
if (el && el.innerText !== undefined && el.innerText !== null) el = el.innerText
if (fn(el, i, object)) {
found.value = el
found.break = true
break
} else {
findDeep(el, fn, found)
}
} }
return found.value
}
function find (args, query) {
query = query.trim()
var isMatch = !!findDeep(args, function check (value, key) {
if (value === undefined || value === null) return false
if (typeof value === 'function') return false
if (typeof value === 'object') return false
var contains = String(value).indexOf(query.trim()) !== -1
return contains
})
return isMatch
} }

@ -9,7 +9,8 @@ module.exports = {
verifyContract: verifyContract, verifyContract: verifyContract,
testFunction, testFunction,
checkDebug, checkDebug,
goToVMtraceStep goToVMtraceStep,
useFilter
} }
function getCompiledContracts (browser, compiled, callback) { function getCompiledContracts (browser, compiled, callback) {
@ -116,6 +117,26 @@ function addFile (browser, name, content, done) {
}) })
} }
function useFilter (browser, filter, test, done) {
if (browser.options.desiredCapabilities.browserName === 'chrome') { // nightwatch deos not handle well that part.... works locally
done()
return
}
var filterClass = '#editor-container div[class^="search"] input[class^="filter"]'
browser.setValue(filterClass, filter, function () {
browser.execute(function () {
return document.querySelector('#editor-container div[class^="journal"]').innerHTML === test
}, [], function (result) {
browser.clearValue(filterClass).setValue(filterClass, '', function () {
if (!result.value) {
browser.assert.fail('useFilter on ' + filter + ' ' + test, 'info about error', '')
}
done()
})
})
})
}
function switchFile (browser, name, done) { function switchFile (browser, name, done) {
browser browser
.useXpath() .useXpath()

@ -44,6 +44,11 @@ function testSimpleContract (browser, callback) {
"0": "uint256: 8" "0": "uint256: 8"
}`) }`)
.pause(500) .pause(500)
.perform((client, done) => {
contractHelper.useFilter(browser, '0x12332162e2e31397dc1e07ed0a1cf08f728e9b4487c6f9ed79d2f39410c92782', '', () => {
done()
})
})
.testFunction('g - transact (not payable)', .testFunction('g - transact (not payable)',
'0xb1532162e2e31397dc1e07ed0a1cf08f728e9b4487c6f9ed79d2f39410c92781', '0xb1532162e2e31397dc1e07ed0a1cf08f728e9b4487c6f9ed79d2f39410c92781',
'[vm] from:0xca3...a733c, to:TestContract.g() 0x692...77b3a, value:0 wei, data:0xe21...79b8e, 0 logs, hash:0xb15...92781', null, `{ '[vm] from:0xca3...a733c, to:TestContract.g() 0x692...77b3a, value:0 wei, data:0xe21...79b8e, 0 logs, hash:0xb15...92781', null, `{

Loading…
Cancel
Save