Merge pull request #159 from ethereum/decodeLocals
Add DecodeFromMemory to Solidity Typespull/7/head
commit
7dd80d338c
@ -1,15 +1,19 @@ |
||||
'use strict' |
||||
var util = require('./util') |
||||
var ValueType = require('./ValueType') |
||||
|
||||
function Address () { |
||||
this.storageSlots = 1 |
||||
this.storageBytes = 20 |
||||
this.typeName = 'address' |
||||
} |
||||
class Address extends ValueType { |
||||
constructor () { |
||||
super(1, 20, 'address') |
||||
} |
||||
|
||||
Address.prototype.decodeFromStorage = function (location, storageContent) { |
||||
var value = util.extractHexValue(location, storageContent, this.storageBytes) |
||||
return '0x' + value.toUpperCase() |
||||
decodeValue (value) { |
||||
if (!value) { |
||||
return '0x0000000000000000000000000000000000000000' |
||||
} else { |
||||
return '0x' + util.extractHexByteSlice(value, this.storageBytes, 0).toUpperCase() |
||||
} |
||||
} |
||||
} |
||||
|
||||
module.exports = Address |
||||
|
@ -1,15 +1,20 @@ |
||||
'use strict' |
||||
var ValueType = require('./ValueType') |
||||
var util = require('./util') |
||||
|
||||
function Bool () { |
||||
this.storageSlots = 1 |
||||
this.storageBytes = 1 |
||||
this.typeName = 'bool' |
||||
} |
||||
class Bool extends ValueType { |
||||
constructor () { |
||||
super(1, 1, 'bool') |
||||
} |
||||
|
||||
Bool.prototype.decodeFromStorage = function (location, storageContent) { |
||||
var value = util.extractHexValue(location, storageContent, this.storageBytes) |
||||
return value !== '00' |
||||
decodeValue (value) { |
||||
if (!value) { |
||||
return false |
||||
} else { |
||||
value = util.extractHexByteSlice(value, this.storageBytes, 0) |
||||
return value !== '00' |
||||
} |
||||
} |
||||
} |
||||
|
||||
module.exports = Bool |
||||
|
@ -1,15 +1,14 @@ |
||||
'use strict' |
||||
var util = require('./util') |
||||
var ValueType = require('./ValueType') |
||||
|
||||
function FixedByteArray (storageBytes) { |
||||
this.storageSlots = 1 |
||||
this.storageBytes = storageBytes |
||||
this.typeName = 'bytesX' |
||||
} |
||||
class FixedByteArray extends ValueType { |
||||
constructor (storageBytes) { |
||||
super(1, storageBytes, 'bytesX') |
||||
} |
||||
|
||||
FixedByteArray.prototype.decodeFromStorage = function (location, storageContent) { |
||||
var value = util.extractHexValue(location, storageContent, this.storageBytes) |
||||
return '0x' + value.toUpperCase() |
||||
decodeValue (value) { |
||||
return '0x' + value.substr(0, 2 * this.storageBytes).toUpperCase() |
||||
} |
||||
} |
||||
|
||||
module.exports = FixedByteArray |
||||
|
@ -1,14 +1,16 @@ |
||||
'use strict' |
||||
var util = require('./util') |
||||
var ValueType = require('./ValueType') |
||||
|
||||
function Int (storageBytes) { |
||||
this.storageSlots = 1 |
||||
this.storageBytes = storageBytes |
||||
this.typeName = 'int' |
||||
} |
||||
class Int extends ValueType { |
||||
constructor (storageBytes) { |
||||
super(1, storageBytes, 'int') |
||||
} |
||||
|
||||
Int.prototype.decodeFromStorage = function (location, storageContent) { |
||||
return util.decodeInt(location, storageContent, this.storageBytes, true) |
||||
decodeValue (value) { |
||||
value = util.extractHexByteSlice(value, this.storageBytes, 0) |
||||
return util.decodeIntFromHex(value, this.storageBytes, true) |
||||
} |
||||
} |
||||
|
||||
module.exports = Int |
||||
|
@ -1,13 +1,22 @@ |
||||
'use strict' |
||||
var RefType = require('./RefType') |
||||
|
||||
function Mapping () { |
||||
this.storageSlots = 1 |
||||
this.storageBytes = 32 |
||||
this.typeName = 'mapping' |
||||
} |
||||
class Mapping extends RefType { |
||||
constructor () { |
||||
super(1, 32, 'mapping') |
||||
} |
||||
|
||||
decodeValue (value) { |
||||
return '<not implemented>' |
||||
} |
||||
|
||||
decodeFromStorage (location, storageContent) { |
||||
return '<not implemented>' |
||||
} |
||||
|
||||
Mapping.prototype.decodeFromStorage = function (location, storageContent) { |
||||
return '<not implemented>' |
||||
decodeFromMemoryInternal (offset, memory) { |
||||
return '<not implemented>' |
||||
} |
||||
} |
||||
|
||||
module.exports = Mapping |
||||
|
@ -0,0 +1,71 @@ |
||||
'use strict' |
||||
|
||||
class RefType { |
||||
constructor (storageSlots, storageBytes, typeName, location) { |
||||
this.location = location |
||||
this.storageSlots = storageSlots |
||||
this.storageBytes = storageBytes |
||||
this.typeName = typeName |
||||
this.basicType = 'RefType' |
||||
} |
||||
|
||||
/** |
||||
* decode the type from the stack |
||||
* |
||||
* @param {Int} stackDepth - position of the type in the stack |
||||
* @param {Array} stack - stack |
||||
* @param {String} - memory |
||||
* @param {Object} - storage |
||||
* @return {Object} decoded value |
||||
*/ |
||||
decodeFromStack (stackDepth, stack, memory, storage) { |
||||
if (stack.length - 1 < stackDepth) { |
||||
return { error: '<decoding failed - stack underflow ' + stackDepth + '>' } |
||||
} |
||||
if (!storage) { |
||||
storage = {} // TODO this is a fallback, should manage properly locals store in storage
|
||||
} |
||||
var offset = stack[stack.length - 1 - stackDepth] |
||||
offset = parseInt(offset, 16) |
||||
if (this.isInStorage()) { |
||||
return this.decodeFromStorage({ offset: 0, slot: offset }, storage) |
||||
} else if (this.isInMemory()) { |
||||
return this.decodeFromMemoryInternal(offset, memory) |
||||
} else { |
||||
return { error: '<decoding failed - no decoder for ' + this.location + '>' } |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* decode the type from the memory |
||||
* |
||||
* @param {Int} offset - position of the ref of the type in memory |
||||
* @param {String} memory - memory |
||||
* @return {Object} decoded value |
||||
*/ |
||||
decodeFromMemory (offset, memory) { |
||||
offset = memory.substr(2 * offset, 64) |
||||
offset = parseInt(offset, 16) |
||||
return this.decodeFromMemoryInternal(offset, memory) |
||||
} |
||||
|
||||
/** |
||||
* current type defined in storage |
||||
* |
||||
* @return {Bool} - return true if the type is defined in the storage |
||||
*/ |
||||
isInStorage () { |
||||
return this.location.indexOf('storage') === 0 |
||||
} |
||||
|
||||
/** |
||||
* current type defined in memory |
||||
* |
||||
* @return {Bool} - return true if the type is defined in the memory |
||||
*/ |
||||
isInMemory () { |
||||
return this.location.indexOf('memory') === 0 |
||||
} |
||||
} |
||||
|
||||
module.exports = RefType |
@ -1,23 +1,35 @@ |
||||
'use strict' |
||||
var util = require('./util') |
||||
var RefType = require('./RefType') |
||||
|
||||
function Struct (memberDetails) { |
||||
this.storageSlots = memberDetails.storageSlots |
||||
this.storageBytes = 32 |
||||
this.members = memberDetails.members |
||||
this.typeName = 'struct' |
||||
} |
||||
class Struct extends RefType { |
||||
constructor (memberDetails, location) { |
||||
super(memberDetails.storageSlots, 32, 'struct', location) |
||||
this.members = memberDetails.members |
||||
} |
||||
|
||||
decodeFromStorage (location, storageContent) { |
||||
var ret = {} |
||||
this.members.map(function (item, i) { |
||||
var globalLocation = { |
||||
offset: location.offset + item.storagelocation.offset, |
||||
slot: util.add(location.slot, item.storagelocation.slot) |
||||
} |
||||
ret[item.name] = item.type.decodeFromStorage(globalLocation, storageContent) |
||||
}) |
||||
return ret |
||||
} |
||||
|
||||
Struct.prototype.decodeFromStorage = function (location, storageContent) { |
||||
var ret = {} |
||||
this.members.map(function (item, i) { |
||||
var globalLocation = { |
||||
offset: location.offset + item.location.offset, |
||||
slot: util.add(location.slot, item.location.slot) |
||||
} |
||||
ret[item.name] = item.type.decodeFromStorage(globalLocation, storageContent) |
||||
}) |
||||
return ret |
||||
decodeFromMemoryInternal (offset, memory) { |
||||
var ret = {} |
||||
this.members.map((item, i) => { |
||||
var contentOffset = offset |
||||
var member = item.type.decodeFromMemory(contentOffset, memory) |
||||
ret[item.name] = member |
||||
offset += 32 |
||||
}) |
||||
return ret |
||||
} |
||||
} |
||||
|
||||
module.exports = Struct |
||||
|
@ -1,14 +1,16 @@ |
||||
'use strict' |
||||
var util = require('./util') |
||||
var ValueType = require('./ValueType') |
||||
|
||||
function Uint (storageBytes) { |
||||
this.storageSlots = 1 |
||||
this.storageBytes = storageBytes |
||||
this.typeName = 'uint' |
||||
} |
||||
class Uint extends ValueType { |
||||
constructor (storageBytes) { |
||||
super(1, storageBytes, 'uint') |
||||
} |
||||
|
||||
Uint.prototype.decodeFromStorage = function (location, storageContent) { |
||||
return util.decodeInt(location, storageContent, this.storageBytes, false) |
||||
decodeValue (value) { |
||||
value = util.extractHexByteSlice(value, this.storageBytes, 0) |
||||
return util.decodeIntFromHex(value, this.storageBytes, false) |
||||
} |
||||
} |
||||
|
||||
module.exports = Uint |
||||
|
@ -0,0 +1,53 @@ |
||||
'use strict' |
||||
var util = require('./util') |
||||
|
||||
class ValueType { |
||||
constructor (storageSlots, storageBytes, typeName) { |
||||
this.storageSlots = storageSlots |
||||
this.storageBytes = storageBytes |
||||
this.typeName = typeName |
||||
this.basicType = 'ValueType' |
||||
} |
||||
|
||||
/** |
||||
* decode the type with the @arg location from the storage |
||||
* |
||||
* @param {Object} location - containing offset and slot |
||||
* @param {Object} storageContent - storageContent (storage) |
||||
* @return {Object} - decoded value |
||||
*/ |
||||
decodeFromStorage (location, storageContent) { |
||||
var value = util.extractHexValue(location, storageContent, this.storageBytes) |
||||
return this.decodeValue(value) |
||||
} |
||||
|
||||
/** |
||||
* decode the type from the stack |
||||
* |
||||
* @param {Int} stackDepth - position of the type in the stack |
||||
* @param {Array} stack - stack |
||||
* @param {String} - memory |
||||
* @return {Object} - decoded value |
||||
*/ |
||||
decodeFromStack (stackDepth, stack, memory) { |
||||
if (stackDepth >= stack.length) { |
||||
return this.decodeValue('') |
||||
} else { |
||||
return this.decodeValue(stack[stack.length - 1 - stackDepth].replace('0x', '')) |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* decode the type with the @arg offset location from the memory |
||||
* |
||||
* @param {Int} stackDepth - position of the type in the stack |
||||
* @return {String} - memory |
||||
* @return {Object} - decoded value |
||||
*/ |
||||
decodeFromMemory (offset, memory) { |
||||
var value = memory.substr(2 * offset, 64) |
||||
return this.decodeValue(util.extractHexByteSlice(value, this.storageBytes, 0)) |
||||
} |
||||
} |
||||
|
||||
module.exports = ValueType |
@ -0,0 +1,39 @@ |
||||
'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"; |
||||
} |
||||
} |
||||
|
||||
contract miscLocal2 { |
||||
function miscLocal2 () { |
||||
bytes memory dynbytes = "dynamicbytes"; |
||||
string memory smallstring = "test_test_test"; |
||||
} |
||||
} |
||||
`}
|
@ -0,0 +1,84 @@ |
||||
'use strict' |
||||
|
||||
module.exports = { |
||||
contract: ` |
||||
contract structArrayLocal { |
||||
struct teststruct { |
||||
string a; |
||||
int b; |
||||
string c; |
||||
int d; |
||||
bool e; |
||||
} |
||||
|
||||
enum enumdef |
||||
{ |
||||
one, |
||||
two, |
||||
three |
||||
}
|
||||
|
||||
struct teststructArray { |
||||
string[] a; |
||||
int8[3] b; |
||||
enumdef c; |
||||
}
|
||||
|
||||
function structArrayLocal () { |
||||
bytes memory bytesSimple = "test_super"; |
||||
teststruct memory e; |
||||
e.a = "test"; |
||||
e.b = 5; |
||||
string memory f = "test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_"; |
||||
e.c = "test_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_test"; |
||||
e.d = 3; |
||||
e.e = true; |
||||
|
||||
int[5] memory simpleArray; |
||||
simpleArray[0] = 45; |
||||
simpleArray[1] = 324324; |
||||
simpleArray[2] = -333; |
||||
simpleArray[3] = 5656; |
||||
simpleArray[4] = -1111; |
||||
|
||||
string[3] memory stringArray; |
||||
stringArray[0] = "long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_"; |
||||
stringArray[1] = "two"; |
||||
stringArray[2] = "three"; |
||||
|
||||
int[][3] memory dynArray; |
||||
dynArray[0] = new int[](1); |
||||
dynArray[1] = new int[](2); |
||||
dynArray[2] = new int[](3); |
||||
dynArray[0][0] = 3423423532; |
||||
dynArray[1][0] = -342343323532; |
||||
dynArray[1][1] = 23432; |
||||
dynArray[2][0] = -432432; |
||||
dynArray[2][1] = 3423423532; |
||||
dynArray[2][2] = -432432; |
||||
|
||||
teststruct[3] memory structArray; |
||||
structArray[0] = e; |
||||
|
||||
structArray[1].a = "item1 a"; |
||||
structArray[1].b = 20; |
||||
structArray[1].c = "item1 c"; |
||||
structArray[1].d = -45; |
||||
structArray[1].e = false; |
||||
|
||||
structArray[2].a = "item2 a"; |
||||
structArray[2].b = 200; |
||||
structArray[2].c = "item2 c"; |
||||
structArray[2].d = -450; |
||||
structArray[2].e = true; |
||||
|
||||
teststructArray memory arrayStruct; |
||||
arrayStruct.a = new string[](1); |
||||
arrayStruct.a[0] = "string"; |
||||
arrayStruct.b[0] = 34; |
||||
arrayStruct.b[1] = -23; |
||||
arrayStruct.b[2] = -3; |
||||
arrayStruct.c = enumdef.three; |
||||
} |
||||
} |
||||
`}
|
@ -0,0 +1,28 @@ |
||||
'use strict' |
||||
var localDecoder = require('../../../babelify-src/solidity/localDecoder') |
||||
|
||||
/* |
||||
Decode local variable |
||||
*/ |
||||
function decodeLocal (st, index, traceManager, callTree, verifier) { |
||||
try { |
||||
traceManager.waterfall([ |
||||
traceManager.getStackAt, |
||||
traceManager.getMemoryAt], |
||||
index, |
||||
function (error, result) { |
||||
if (!error) { |
||||
var locals = localDecoder.solidityLocals(index, callTree, result[0].value, result[1].value) |
||||
verifier(locals) |
||||
} else { |
||||
st.fail(error) |
||||
} |
||||
}) |
||||
} catch (e) { |
||||
st.fail(e.message) |
||||
} |
||||
} |
||||
|
||||
module.exports = { |
||||
decodeLocals: decodeLocal |
||||
} |
@ -0,0 +1,105 @@ |
||||
'use strict' |
||||
var TraceManager = require('../../../babelify-src/trace/traceManager') |
||||
var CodeManager = require('../../../babelify-src/code/codeManager') |
||||
var vmSendTx = require('./vmCall') |
||||
var traceHelper = require('../../../babelify-src/helpers/traceHelper') |
||||
var util = require('../../../babelify-src/helpers/global') |
||||
var SolidityProxy = require('../../../babelify-src/solidity/solidityProxy') |
||||
var InternalCallTree = require('../../../babelify-src/util/internalCallTree') |
||||
var EventManager = require('../../../babelify-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, { includeLocalVariables: true }) |
||||
callTree.event.register('callTreeBuildFailed', (error) => { |
||||
st.fail(error) |
||||
}) |
||||
callTree.event.register('callTreeReady', (scopes, scopeStarts) => { |
||||
try { |
||||
st.equals(scopeStarts[0], '') |
||||
st.equals(scopeStarts[97], '1') |
||||
st.equals(scopeStarts[112], '1.1') |
||||
st.equals(scopeStarts[135], '2') |
||||
st.equals(scopeStarts[154], '3') |
||||
st.equals(scopeStarts[169], '3.1') |
||||
st.equals(scopes[''].locals['ui8'].type.typeName, 'uint') |
||||
st.equals(scopes[''].locals['ui16'].type.typeName, 'uint') |
||||
st.equals(scopes[''].locals['ui32'].type.typeName, 'uint') |
||||
st.equals(scopes[''].locals['ui64'].type.typeName, 'uint') |
||||
st.equals(scopes[''].locals['ui128'].type.typeName, 'uint') |
||||
st.equals(scopes[''].locals['ui256'].type.typeName, 'uint') |
||||
st.equals(scopes[''].locals['ui'].type.typeName, 'uint') |
||||
st.equals(scopes[''].locals['i8'].type.typeName, 'int') |
||||
st.equals(scopes[''].locals['i16'].type.typeName, 'int') |
||||
st.equals(scopes[''].locals['i32'].type.typeName, 'int') |
||||
st.equals(scopes[''].locals['i64'].type.typeName, 'int') |
||||
st.equals(scopes[''].locals['i128'].type.typeName, 'int') |
||||
st.equals(scopes[''].locals['i256'].type.typeName, 'int') |
||||
st.equals(scopes[''].locals['i'].type.typeName, 'int') |
||||
st.equals(scopes[''].locals['ishrink'].type.typeName, 'int') |
||||
st.equals(scopes['1'].locals['ui8'].type.typeName, 'uint') |
||||
st.equals(scopes['1.1'].locals['ui81'].type.typeName, 'uint') |
||||
st.equals(scopes['2'].locals['ui81'].type.typeName, 'uint') |
||||
st.equals(scopes['3'].locals['ui8'].type.typeName, 'uint') |
||||
st.equals(scopes['3.1'].locals['ui81'].type.typeName, 'uint') |
||||
} catch (e) { |
||||
st.fail(e.message) |
||||
} |
||||
|
||||
helper.decodeLocals(st, 125, traceManager, callTree, function (locals) { |
||||
st.equals(Object.keys(locals).length, 16) |
||||
st.equals(locals['ui8'], '130') |
||||
st.equals(locals['ui16'], '456') |
||||
st.equals(locals['ui32'], '4356') |
||||
st.equals(locals['ui64'], '3543543543') |
||||
st.equals(locals['ui128'], '234567') |
||||
st.equals(locals['ui256'], '115792089237316195423570985008687907853269984665640564039457584007880697216513') |
||||
st.equals(locals['ui'], '123545666') |
||||
st.equals(locals['i8'], '-45') |
||||
st.equals(locals['i16'], '-1234') |
||||
st.equals(locals['i32'], '3455') |
||||
st.equals(locals['i64'], '-35566') |
||||
st.equals(locals['i128'], '-444444') |
||||
st.equals(locals['i256'], '3434343') |
||||
st.equals(locals['i'], '-32432423423') |
||||
st.equals(locals['ishrink'], '2') |
||||
}) |
||||
|
||||
helper.decodeLocals(st, 177, traceManager, callTree, function (locals) { |
||||
try { |
||||
st.equals(locals['ui8'], '123') |
||||
st.equals(Object.keys(locals).length, 1) |
||||
} catch (e) { |
||||
st.fail(e.message) |
||||
} |
||||
cb() |
||||
}) |
||||
}) |
||||
traceManager.resolveTrace(tx, (error, result) => { |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace]) |
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
} |
||||
|
@ -0,0 +1,93 @@ |
||||
'use strict' |
||||
var TraceManager = require('../../../babelify-src/trace/traceManager') |
||||
var CodeManager = require('../../../babelify-src/code/codeManager') |
||||
var vmSendTx = require('./vmCall') |
||||
var traceHelper = require('../../../babelify-src/helpers/traceHelper') |
||||
var util = require('../../../babelify-src/helpers/global') |
||||
var SolidityProxy = require('../../../babelify-src/solidity/solidityProxy') |
||||
var InternalCallTree = require('../../../babelify-src/util/internalCallTree') |
||||
var EventManager = require('../../../babelify-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, { includeLocalVariables: true }) |
||||
callTree.event.register('callTreeBuildFailed', (error) => { |
||||
st.fail(error) |
||||
}) |
||||
callTree.event.register('callTreeReady', (scopes, scopeStarts) => { |
||||
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(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, 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(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) |
||||
} |
||||
cb() |
||||
}) |
||||
}) |
||||
traceManager.resolveTrace(tx, (error, result) => { |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace]) |
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
} |
@ -0,0 +1,63 @@ |
||||
'use strict' |
||||
var TraceManager = require('../../../babelify-src/trace/traceManager') |
||||
var CodeManager = require('../../../babelify-src/code/codeManager') |
||||
var vmSendTx = require('./vmCall') |
||||
var traceHelper = require('../../../babelify-src/helpers/traceHelper') |
||||
var util = require('../../../babelify-src/helpers/global') |
||||
var SolidityProxy = require('../../../babelify-src/solidity/solidityProxy') |
||||
var InternalCallTree = require('../../../babelify-src/util/internalCallTree') |
||||
var EventManager = require('../../../babelify-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, { includeLocalVariables: true }) |
||||
callTree.event.register('callTreeBuildFailed', (error) => { |
||||
st.fail(error) |
||||
}) |
||||
callTree.event.register('callTreeReady', (scopes, scopeStarts) => { |
||||
helper.decodeLocals(st, 72, 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]) |
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
} |
@ -0,0 +1,121 @@ |
||||
'use strict' |
||||
var TraceManager = require('../../../babelify-src/trace/traceManager') |
||||
var CodeManager = require('../../../babelify-src/code/codeManager') |
||||
var vmSendTx = require('./vmCall') |
||||
var traceHelper = require('../../../babelify-src/helpers/traceHelper') |
||||
var util = require('../../../babelify-src/helpers/global') |
||||
var SolidityProxy = require('../../../babelify-src/solidity/solidityProxy') |
||||
var InternalCallTree = require('../../../babelify-src/util/internalCallTree') |
||||
var EventManager = require('../../../babelify-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, { includeLocalVariables: true }) |
||||
callTree.event.register('callTreeBuildFailed', (error) => { |
||||
st.fail(error) |
||||
}) |
||||
callTree.event.register('callTreeReady', (scopes, scopeStarts) => { |
||||
helper.decodeLocals(st, 1814, traceManager, callTree, function (locals) { |
||||
try { |
||||
st.equals(locals['bytesSimple'].length, '0x14') |
||||
st.equals(locals['bytesSimple'].value, '0x746573745f7375706572') |
||||
st.equals(locals['e']['a'].value, 'test') |
||||
st.equals(locals['e']['a'].length, '0x8') |
||||
st.equals(locals['e']['a'].raw, '0x74657374') |
||||
st.equals(locals['e']['b'], '5') |
||||
st.equals(locals['e']['c'].length, '0x220') |
||||
st.equals(locals['e']['c'].raw, '0x746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374') |
||||
st.equals(locals['e']['c'].value, 'test_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_test') |
||||
st.equals(locals['e']['d'], '3') |
||||
st.equals(locals['f'].length, '0x1b8') |
||||
st.equals(locals['f'].raw, '0x746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f') |
||||
st.equals(locals['f'].value, 'test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_test_long_') |
||||
st.equals(locals['e']['e'], true) |
||||
|
||||
st.equals(locals['simpleArray'][0], '45') |
||||
st.equals(locals['simpleArray'][1], '324324') |
||||
st.equals(locals['simpleArray'][2], '-333') |
||||
st.equals(locals['simpleArray'][3], '5656') |
||||
st.equals(locals['simpleArray'][4], '-1111') |
||||
|
||||
st.equals(locals['stringArray'][0].value, 'long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_long_one_') |
||||
st.equals(locals['stringArray'][1].value, 'two') |
||||
st.equals(locals['stringArray'][2].value, 'three') |
||||
|
||||
st.equals(locals['dynArray'][0][0], '3423423532') |
||||
st.equals(locals['dynArray'][1][0], '-342343323532') |
||||
st.equals(locals['dynArray'][1][1], '23432') |
||||
st.equals(locals['dynArray'][2][0], '-432432') |
||||
st.equals(locals['dynArray'][2][1], '3423423532') |
||||
st.equals(locals['dynArray'][2][2], '-432432') |
||||
|
||||
st.equals(locals['structArray'][0]['a'].value, 'test') |
||||
st.equals(locals['structArray'][0]['a'].length, '0x8') |
||||
st.equals(locals['structArray'][0]['a'].raw, '0x74657374') |
||||
st.equals(locals['structArray'][0]['b'], '5') |
||||
st.equals(locals['structArray'][0]['c'].length, '0x220') |
||||
st.equals(locals['structArray'][0]['c'].raw, '0x746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374746573745f6c6f6e675f746573745f6c6f6e675f746573745f6c6f6e675f74657374') |
||||
st.equals(locals['structArray'][0]['c'].value, 'test_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_testtest_long_test_long_test_long_test') |
||||
st.equals(locals['structArray'][0]['d'], '3') |
||||
st.equals(locals['structArray'][0]['e'], true) |
||||
|
||||
st.equals(locals['structArray'][1]['a'].value, 'item1 a') |
||||
st.equals(locals['structArray'][1]['b'], '20') |
||||
st.equals(locals['structArray'][1]['c'].value, 'item1 c') |
||||
st.equals(locals['structArray'][1]['d'], '-45') |
||||
st.equals(locals['structArray'][1]['e'], false) |
||||
|
||||
st.equals(locals['structArray'][2]['a'].value, 'item2 a') |
||||
st.equals(locals['structArray'][2]['b'], '200') |
||||
st.equals(locals['structArray'][2]['c'].value, 'item2 c') |
||||
st.equals(locals['structArray'][2]['d'], '-450') |
||||
st.equals(locals['structArray'][2]['e'], true) |
||||
|
||||
st.equals(locals['arrayStruct'].a[0].value, 'string') |
||||
st.equals(locals['arrayStruct'].b[0], '34') |
||||
st.equals(locals['arrayStruct'].b[1], '-23') |
||||
st.equals(locals['arrayStruct'].b[2], '-3') |
||||
st.equals(locals['arrayStruct'].c, 'three') |
||||
|
||||
st.equals(Object.keys(locals).length, 8) |
||||
} catch (e) { |
||||
st.fail(e.message) |
||||
} |
||||
}) |
||||
|
||||
helper.decodeLocals(st, 7, traceManager, callTree, function (locals) { |
||||
try { |
||||
st.equals(Object.keys(locals).length, 8) |
||||
} catch (e) { |
||||
st.fail(e.message) |
||||
} |
||||
cb() |
||||
}) |
||||
}) |
||||
traceManager.resolveTrace(tx, (error, result) => { |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace]) |
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
} |
@ -0,0 +1,30 @@ |
||||
'use strict' |
||||
var utileth = require('ethereumjs-util') |
||||
var Tx = require('ethereumjs-tx') |
||||
var Block = require('ethereumjs-block') |
||||
var BN = require('ethereumjs-util').BN |
||||
|
||||
function sendTx (vm, from, to, value, data, cb) { |
||||
var tx = new Tx({ |
||||
nonce: new BN(from.nonce++), |
||||
gasPrice: new BN(1), |
||||
gasLimit: new BN(3000000, 10), |
||||
to: to, |
||||
value: new BN(value, 10), |
||||
data: new Buffer(data, 'hex') |
||||
}) |
||||
tx.sign(from.privateKey) |
||||
var block = new Block({ |
||||
header: { |
||||
timestamp: new Date().getTime() / 1000 | 0, |
||||
number: 0 |
||||
}, |
||||
transactions: [], |
||||
uncleHeaders: [] |
||||
}) |
||||
vm.runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (error, result) { |
||||
cb(error, utileth.bufferToHex(tx.hash())) |
||||
}) |
||||
} |
||||
|
||||
module.exports = sendTx |
Loading…
Reference in new issue