Commit cd38d898 authored by ioedeveloper's avatar ioedeveloper

Set skip and limit for decode for memory internal

parent 7a1cbfef
...@@ -72,7 +72,7 @@ class ArrayType extends RefType { ...@@ -72,7 +72,7 @@ class ArrayType extends RefType {
return {value: ret, length: '0x' + size.toString(16), type: this.typeName} return {value: ret, length: '0x' + size.toString(16), type: this.typeName}
} }
decodeFromMemoryInternal (offset, memory) { decodeFromMemoryInternal (offset, memory, skip) {
const ret = [] const ret = []
let length = this.arraySize let length = this.arraySize
if (this.arraySize === 'dynamic') { if (this.arraySize === 'dynamic') {
...@@ -80,12 +80,28 @@ class ArrayType extends RefType { ...@@ -80,12 +80,28 @@ class ArrayType extends RefType {
length = parseInt(length, 16) length = parseInt(length, 16)
offset = offset + 32 offset = offset + 32
} }
for (var k = 0; k < length; k++) { if (isNaN(length)) {
return {
value: '<decoding failed - length is NaN>',
type: this.typeName
}
}
let limit = length
if (!skip) skip = 0
if (skip) offset = offset + (32 * skip)
if ((length - skip) > 500) limit = 500
for (var k = 0; k < limit; k++) {
var contentOffset = offset var contentOffset = offset
ret.push(this.underlyingType.decodeFromMemory(contentOffset, memory)) ret.push(this.underlyingType.decodeFromMemory(contentOffset, memory))
offset += 32 offset += 32
} }
return {value: ret, length: '0x' + length.toString(16), type: this.typeName} return {
value: ret,
length: '0x' + length.toString(16),
type: this.typeName,
cursor: skip + limit,
hasNext: length > (skip + limit)
}
} }
} }
......
...@@ -79,6 +79,10 @@ contract structArrayLocal { ...@@ -79,6 +79,10 @@ contract structArrayLocal {
arrayStruct.b[1] = -23; arrayStruct.b[1] = -23;
arrayStruct.b[2] = -3; arrayStruct.b[2] = -3;
arrayStruct.c = enumdef.three; arrayStruct.c = enumdef.three;
bytes32[] memory dynamic = new bytes32[](2);
dynamic[0] = 0x7465737400000000000000000000000000000000000000000000000000000000;
dynamic[1] = 0x7465737400000000000000000000000000000000000000000000000000000000;
} }
} }
`} `}
...@@ -30,7 +30,7 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu ...@@ -30,7 +30,7 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
st.fail(error) st.fail(error)
}) })
callTree.event.register('callTreeReady', (scopes, scopeStarts) => { callTree.event.register('callTreeReady', (scopes, scopeStarts) => {
helper.decodeLocals(st, 1622, traceManager, callTree, function (locals) { helper.decodeLocals(st, 1719, traceManager, callTree, function (locals) {
try { try {
st.equals(locals['bytesSimple'].length, '0x14') st.equals(locals['bytesSimple'].length, '0x14')
st.equals(locals['bytesSimple'].value, '0x746573745f7375706572') st.equals(locals['bytesSimple'].value, '0x746573745f7375706572')
...@@ -91,6 +91,8 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu ...@@ -91,6 +91,8 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
st.equals(locals['arrayStruct'].value.b.value[1].value, '-23') st.equals(locals['arrayStruct'].value.b.value[1].value, '-23')
st.equals(locals['arrayStruct'].value.b.value[2].value, '-3') st.equals(locals['arrayStruct'].value.b.value[2].value, '-3')
st.equals(locals['arrayStruct'].value.c.value, 'three') st.equals(locals['arrayStruct'].value.c.value, 'three')
st.equals(locals['dynamic'].value[0], '0x74657374')
st.equals(locals['dynamic'].value[1], '0x74657374')
st.equals(Object.keys(locals).length, 8) st.equals(Object.keys(locals).length, 8)
} catch (e) { } catch (e) {
......
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