fix and add tests

pull/7/head
yann300 8 years ago
parent e777c08597
commit dc07c26d3c
  1. 10
      test/solidity/contracts/addressLocal.js
  2. 32
      test/solidity/contracts/miscLocal.js
  3. 17
      test/solidity/localDecoder.js
  4. 38
      test/solidity/localsTests/misc.js

@ -1,10 +0,0 @@
'use strict'
module.exports = {
contract: `
contract addressLocal {
function addressLocal () {
address sender = msg.sender;
}
}
`}

@ -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";
}
}
`}

@ -2,13 +2,16 @@
var tape = require('tape')
var compiler = require('solc')
var intLocal = require('./contracts/intLocal')
var addressLocal = require('./contracts/addressLocal')
var miscLocal = require('./contracts/miscLocal')
var structArrayLocal = require('./contracts/structArrayLocal')
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 miscLocalTest = require('./localsTests/misc')
var misc2LocalTest = require('./localsTests/misc2')
var structArrayLocalTest = require('./localsTests/structArray')
tape('solidity', function (t) {
t.test('local decoder', function (st) {
@ -46,7 +49,13 @@ 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 () {
output = compiler.compile(miscLocal.contract, 0)
misc2LocalTest(st, vm, privateKey, output.contracts['miscLocal2'].bytecode, output, function () {
output = compiler.compile(structArrayLocal.contract, 0)
structArrayLocalTest(st, vm, privateKey, output.contracts['structArrayLocal'].bytecode, output, function () {})
})
})
})
}

@ -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)
}
Loading…
Cancel
Save