diff --git a/src/solidity/types/Struct.js b/src/solidity/types/Struct.js index 06b2df20a1..00cf263590 100644 --- a/src/solidity/types/Struct.js +++ b/src/solidity/types/Struct.js @@ -8,7 +8,15 @@ function Struct (memberDetails) { } Struct.prototype.decodeFromStorage = function (location, storageContent) { - return '' + var ret = {} + this.members.map(function (item, i) { + var globalLocation = { + offset: location.offset + item.location.offset, + slot: location.slot + item.location.slot + } + ret[item.name] = item.type.decodeFromStorage(globalLocation, storageContent) + }) + return ret } module.exports = Struct diff --git a/test/solidity/contracts/structArrayStorage.js b/test/solidity/contracts/structArrayStorage.js new file mode 100644 index 0000000000..f3a4d2b03a --- /dev/null +++ b/test/solidity/contracts/structArrayStorage.js @@ -0,0 +1,29 @@ +'use strict' + +module.exports = { + contract: `contract structArrayStorage { + struct intStruct { + int8 i8; + int16 i16; + uint32 ui32; + int i256; + uint16 ui16; + int32 i32; + } + intStruct intStructDec; + function structArrayStorage () { + intStructDec.i8 = 32; + intStructDec.i16 = -54; + intStructDec.ui32 = 128; + intStructDec.i256 = -1243565465756; + intStructDec.ui16 = 34556; + intStructDec.i32 = -345446546; + } +} +`, + storage: { + '0x0000000000000000000000000000000000000000000000000000000000000000': '0x0000000000000000000000000000000000000000000000000000000080ffca20', + '0x0000000000000000000000000000000000000000000000000000000000000001': '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffede75b8df64', + '0x0000000000000000000000000000000000000000000000000000000000000002': '0x0000000000000000000000000000000000000000000000000000eb68e76e86fc' + } +} diff --git a/test/solidity/storageDecoder.js b/test/solidity/storageDecoder.js index d3bc9ef30a..58eecaa5c6 100644 --- a/test/solidity/storageDecoder.js +++ b/test/solidity/storageDecoder.js @@ -7,6 +7,7 @@ tape('solidity', function (t) { t.test('storage decoder', function (st) { testIntStorage(st) testByteStorage(st) + testStructArrayStorage(st) st.end() }) }) @@ -197,3 +198,15 @@ function shrinkStorage (storage) { } return shrinkedStorage } + +function testStructArrayStorage (st) { + var structArrayStorage = require('./contracts/structArrayStorage') + var output = compiler.compile(structArrayStorage.contract, 0) + var decoded = stateDecoder.solidityState(structArrayStorage.storage, output.sources, 'structArrayStorage') + st.equal(decoded['intStructDec']['i8'], '32') + st.equal(decoded['intStructDec']['i16'], '-54') + st.equal(decoded['intStructDec']['ui32'], '128') + st.equal(decoded['intStructDec']['i256'], '-1243565465756') + st.equal(decoded['intStructDec']['ui16'], '34556') + st.equal(decoded['intStructDec']['i32'], '-345446546') +}