Commit d5d15f7f authored by serapath's avatar serapath

REFACTOR terminal

parent db7d96a9
...@@ -162,7 +162,7 @@ class Terminal { ...@@ -162,7 +162,7 @@ class Terminal {
self.registerCommand('script', function execute (args, scopedCommands, append) { self.registerCommand('script', function execute (args, scopedCommands, append) {
var script = String(args[0]) var script = String(args[0])
scopedCommands.log(`> ${script}`) scopedCommands.log(`> ${script}`)
self._shell(script, function (error, output) { self._shell(script, scopedCommands, function (error, output) {
if (error) scopedCommands.error(error) if (error) scopedCommands.error(error)
else scopedCommands.log(output) else scopedCommands.log(output)
}) })
...@@ -564,10 +564,11 @@ class Terminal { ...@@ -564,10 +564,11 @@ class Terminal {
self.commands[name].help = help self.commands[name].help = help
return self.commands[name] return self.commands[name]
} }
_shell (script, done) { // default shell _shell (script, scopedCommands, done) { // default shell
var self = this var self = this
var context = domTerminalFeatures(self, scopedCommands)
try { try {
var context = vm.createContext(Object.assign(self._jsSandboxContext, domTerminalFeatures(self))) var context = vm.createContext(Object.assign(self._jsSandboxContext, context))
var result = vm.runInContext(script, context) var result = vm.runInContext(script, context)
self._jsSandboxContext = Object.assign({}, context) self._jsSandboxContext = Object.assign({}, context)
done(null, result) done(null, result)
...@@ -577,15 +578,15 @@ class Terminal { ...@@ -577,15 +578,15 @@ class Terminal {
} }
} }
function domTerminalFeatures (self) { function domTerminalFeatures (self, scopedCommands) {
return { var ctx = scopedCommands
web3: executionContext.getProvider() !== 'vm' ? new Web3(executionContext.web3().currentProvider) : null, ctx.web3 = executionContext.getProvider() !== 'vm' ? new Web3(executionContext.web3().currentProvider) : null,
console: { ctx.console = console = {
log: function () { self.commands.log.apply(null, arguments) }, log: function () { scopedCommands.log.apply(scopedCommands, arguments) },
info: function () { self.commands.info.apply(null, arguments) }, info: function () { scopedCommands.info.apply(scopedCommands, arguments) },
error: function () { self.commands.error.apply(null, arguments) } error: function () { scopedCommands.error.apply(scopedCommands, arguments) }
}
} }
return context
} }
function findDeep (object, fn, found = { break: false, value: undefined }) { function findDeep (object, fn, found = { break: false, value: undefined }) {
......
...@@ -32,8 +32,8 @@ function runTests (browser) { ...@@ -32,8 +32,8 @@ function runTests (browser) {
.click('#runTabView div[class^="create"]') .click('#runTabView div[class^="create"]')
.waitForElementPresent('.instance button[title="f - transact (not payable)"]') .waitForElementPresent('.instance button[title="f - transact (not payable)"]')
.click('.instance button[title="f - transact (not payable)"]') .click('.instance button[title="f - transact (not payable)"]')
.waitForElementPresent('#editor-container div[class^="terminal"] .knownTransaction span[id="tx0xa178c603400a184ce5fedbcfab392d9b77822f6ffa7facdec693aded214523bc"]') .waitForElementPresent('#editor-container div[class^="terminal"] span[id="tx0xa178c603400a184ce5fedbcfab392d9b77822f6ffa7facdec693aded214523bc"]')
.assert.containsText('#editor-container div[class^="terminal"] .knownTransaction span[id="tx0xa178c603400a184ce5fedbcfab392d9b77822f6ffa7facdec693aded214523bc"]', '(vm): from:0xca3...a733c, to:0x692...77b3a, browser/Untitled.sol:TestContract.f(), value:0 wei, data:0x261...21ff0, 0 logs, hash:0xa17...523bc,DetailsDebug') .assert.containsText('#editor-container div[class^="terminal"] span[id="tx0xa178c603400a184ce5fedbcfab392d9b77822f6ffa7facdec693aded214523bc"]', '(vm): from:0xca3...a733c, to:0x692...77b3a, browser/Untitled.sol:TestContract.f(), value:0 wei, data:0x261...21ff0, 0 logs, hash:0xa17...523bc,DetailsDebug')
.end() .end()
/* /*
@TODO: need to check now the return value of the function @TODO: need to check now the return value of the function
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment