From 72ab547de5bc63bec764b7f6371588d291869d16 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 12 Dec 2016 16:40:06 +0100 Subject: [PATCH] fix and add tests --- test/solidity/contracts/addressLocal.js | 10 ----- test/solidity/contracts/miscLocal.js | 32 ++++++++++++++++ test/solidity/localDecoder.js | 9 ++--- .../localsTests/{address.js => misc.js} | 38 +++++++++++++++++-- 4 files changed, 70 insertions(+), 19 deletions(-) delete mode 100644 test/solidity/contracts/addressLocal.js create mode 100644 test/solidity/contracts/miscLocal.js rename test/solidity/localsTests/{address.js => misc.js} (51%) diff --git a/test/solidity/contracts/addressLocal.js b/test/solidity/contracts/addressLocal.js deleted file mode 100644 index e67de7ee8c..0000000000 --- a/test/solidity/contracts/addressLocal.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -module.exports = { - contract: ` -contract addressLocal { - function addressLocal () { - address sender = msg.sender; - } - } -`} diff --git a/test/solidity/contracts/miscLocal.js b/test/solidity/contracts/miscLocal.js new file mode 100644 index 0000000000..a53fd226a3 --- /dev/null +++ b/test/solidity/contracts/miscLocal.js @@ -0,0 +1,32 @@ +'use strict' + +module.exports = { + contract: ` +contract miscLocal { + enum enumDef { + one, + two, + three, + four + } + function miscLocal () { + bool boolFalse = false; + bool boolTrue = true; + enumDef testEnum; + testEnum = enumDef.three; + address sender = msg.sender; + byte _bytes1 = hex"99"; + bytes1 __bytes1 = hex"99"; + bytes2 __bytes2 = hex"99AB"; + bytes4 __bytes4 = hex"99FA"; + bytes6 __bytes6 = hex"99"; + bytes7 __bytes7 = hex"993567"; + bytes8 __bytes8 = hex"99ABD417"; + bytes9 __bytes9 = hex"99156744AF"; + bytes13 __bytes13 = hex"991234234253"; + bytes16 __bytes16 = hex"99AFAD234324"; + bytes24 __bytes24 = hex"99AFAD234324"; + bytes32 __bytes32 = hex"9999ABD41799ABD417"; + } + } +`} diff --git a/test/solidity/localDecoder.js b/test/solidity/localDecoder.js index 77441820b6..6950b08aa9 100644 --- a/test/solidity/localDecoder.js +++ b/test/solidity/localDecoder.js @@ -2,14 +2,13 @@ var tape = require('tape') var compiler = require('solc') var intLocal = require('./contracts/intLocal') -var addressLocal = require('./contracts/addressLocal') +var miscLocal = require('./contracts/miscLocal') var VM = require('ethereumjs-vm') var utileth = require('ethereumjs-util') var Web3Providers = require('../../src/web3Provider/web3Providers') var util = require('../../src/helpers/global') var intLocalTest = require('./localsTests/int') -var addressLocalTest = require('./localsTests/address') -// var sync = require('sync') +var miscLocalTest = require('./localsTests/misc') tape('solidity', function (t) { t.test('local decoder', function (st) { @@ -47,7 +46,7 @@ function initVM (st, address) { 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(addressLocal.contract, 0) - addressLocalTest(st, vm, privateKey, output.contracts['addressLocal'].bytecode, output, function () {}) + output = compiler.compile(miscLocal.contract, 0) + miscLocalTest(st, vm, privateKey, output.contracts['miscLocal'].bytecode, output, function () {}) }) } diff --git a/test/solidity/localsTests/address.js b/test/solidity/localsTests/misc.js similarity index 51% rename from test/solidity/localsTests/address.js rename to test/solidity/localsTests/misc.js index 91a54365a2..20f042e4bb 100644 --- a/test/solidity/localsTests/address.js +++ b/test/solidity/localsTests/misc.js @@ -27,19 +27,49 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu var debuggerEvent = new EventManager() var callTree = new InternalCallTree(debuggerEvent, traceManager, solidityProxy, codeManager, { includeLocalsVariables: true }) callTree.event.register('callTreeReady', (scopes, scopeStarts) => { - helper.decodeLocals(st, 10, traceManager, callTree, function (locals) { + helper.decodeLocals(st, 70, traceManager, callTree, function (locals) { try { + st.equals(locals['boolFalse'], false) + st.equals(locals['boolTrue'], true) + st.equals(locals['testEnum'], 'three') st.equals(locals['sender'], '0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db') - st.equals(Object.keys(locals).length, 1) + st.equals(locals['_bytes1'], '0x99') + st.equals(locals['__bytes1'], '0x99') + st.equals(locals['__bytes2'], '0x99AB') + st.equals(locals['__bytes4'], '0x99FA0000') + st.equals(locals['__bytes6'], '0x990000000000') + st.equals(locals['__bytes7'], '0x99356700000000') + st.equals(locals['__bytes8'], '0x99ABD41700000000') + st.equals(locals['__bytes9'], '0x99156744AF00000000') + st.equals(locals['__bytes13'], '0x99123423425300000000000000') + st.equals(locals['__bytes16'], '0x99AFAD23432400000000000000000000') + st.equals(locals['__bytes24'], '0x99AFAD234324000000000000000000000000000000000000') + st.equals(locals['__bytes32'], '0x9999ABD41799ABD4170000000000000000000000000000000000000000000000') + st.equals(Object.keys(locals).length, 16) } catch (e) { st.fail(e.message) } }) - helper.decodeLocals(st, 4, traceManager, callTree, function (locals) { + helper.decodeLocals(st, 7, traceManager, callTree, function (locals) { try { + st.equals(locals['boolFalse'], false) + st.equals(locals['boolTrue'], false) + st.equals(locals['testEnum'], 'one') st.equals(locals['sender'], '0x0000000000000000000000000000000000000000') - st.equals(Object.keys(locals).length, 1) + st.equals(locals['_bytes1'], '0x') + st.equals(locals['__bytes1'], '0x') + st.equals(locals['__bytes2'], '0x') + st.equals(locals['__bytes4'], '0x') + st.equals(locals['__bytes6'], '0x') + st.equals(locals['__bytes7'], '0x') + st.equals(locals['__bytes8'], '0x') + st.equals(locals['__bytes9'], '0x') + st.equals(locals['__bytes13'], '0x') + st.equals(locals['__bytes16'], '0x') + st.equals(locals['__bytes24'], '0x') + st.equals(locals['__bytes32'], '0x') + st.equals(Object.keys(locals).length, 16) } catch (e) { st.fail(e.message) }