diff --git a/test/solidity/contracts/miscLocal.js b/test/solidity/contracts/miscLocal.js index a53fd226a3..750b8e63e6 100644 --- a/test/solidity/contracts/miscLocal.js +++ b/test/solidity/contracts/miscLocal.js @@ -29,4 +29,11 @@ contract miscLocal { bytes32 __bytes32 = hex"9999ABD41799ABD417"; } } + + contract miscLocal2 { + function miscLocal2 () { + bytes memory dynbytes = "dynamicbytes"; + string memory smallstring = "test_test_test"; + } + } `} diff --git a/test/solidity/localDecoder.js b/test/solidity/localDecoder.js index 6950b08aa9..24a5aa1ce7 100644 --- a/test/solidity/localDecoder.js +++ b/test/solidity/localDecoder.js @@ -9,6 +9,7 @@ var Web3Providers = require('../../src/web3Provider/web3Providers') var util = require('../../src/helpers/global') var intLocalTest = require('./localsTests/int') var miscLocalTest = require('./localsTests/misc') +var misc2LocalTest = require('./localsTests/misc2') tape('solidity', function (t) { t.test('local decoder', function (st) { @@ -47,6 +48,9 @@ function test (st, vm, privateKey) { var output = compiler.compile(intLocal.contract, 0) intLocalTest(st, vm, privateKey, output.contracts['intLocal'].bytecode, output, function () { output = compiler.compile(miscLocal.contract, 0) - miscLocalTest(st, vm, privateKey, output.contracts['miscLocal'].bytecode, output, function () {}) + miscLocalTest(st, vm, privateKey, output.contracts['miscLocal'].bytecode, output, function () { + output = compiler.compile(miscLocal.contract, 0) + misc2LocalTest(st, vm, privateKey, output.contracts['miscLocal2'].bytecode, output, function () {}) + }) }) } diff --git a/test/solidity/localsTests/misc2.js b/test/solidity/localsTests/misc2.js new file mode 100644 index 0000000000..aa2d7f9756 --- /dev/null +++ b/test/solidity/localsTests/misc2.js @@ -0,0 +1,60 @@ +'use strict' +var TraceManager = require('../../../src/trace/traceManager') +var CodeManager = require('../../../src/code/codeManager') +var vmSendTx = require('./vmCall') +var traceHelper = require('../../../src/helpers/traceHelper') +var util = require('../../../src/helpers/global') +var SolidityProxy = require('../../../src/solidity/solidityProxy') +var InternalCallTree = require('../../../src/util/internalCallTree') +var EventManager = require('../../../src/lib/eventManager') +var helper = require('./helper') + +module.exports = function (st, vm, privateKey, contractBytecode, compilationResult, cb) { + vmSendTx(vm, {nonce: 0, privateKey: privateKey}, null, 0, contractBytecode, function (error, txHash) { + if (error) { + st.fail(error) + } else { + util.web3.getTransaction(txHash, function (error, tx) { + if (error) { + st.fail(error) + } else { + tx.to = traceHelper.contractCreationToken('0') + var traceManager = new TraceManager() + var codeManager = new CodeManager(traceManager) + codeManager.clear() + var solidityProxy = new SolidityProxy(traceManager, codeManager) + solidityProxy.reset(compilationResult) + var debuggerEvent = new EventManager() + var callTree = new InternalCallTree(debuggerEvent, traceManager, solidityProxy, codeManager, { includeLocalsVariables: true }) + callTree.event.register('callTreeReady', (scopes, scopeStarts) => { + helper.decodeLocals(st, 82, traceManager, callTree, function (locals) { + try { + st.equals(locals['dynbytes'].value, '0x64796e616d69636279746573') + st.equals(locals['smallstring'].value, 'test_test_test') + st.equals(Object.keys(locals).length, 2) + } catch (e) { + st.fail(e.message) + } + }) + + helper.decodeLocals(st, 7, traceManager, callTree, function (locals) { + try { + st.equals(Object.keys(locals).length, 2) + } catch (e) { + st.fail(e.message) + } + cb() + }) + }) + traceManager.resolveTrace(tx, (error, result) => { + if (error) { + st.fail(error) + } else { + debuggerEvent.trigger('newTraceLoaded', [traceManager.trace]) + } + }) + } + }) + } + }) +}