decode struct + fix uint decoding

pull/7/head
yann300 8 years ago
parent 0997621fc6
commit 6e43844de2
  1. 10
      src/solidity/types/Struct.js
  2. 29
      test/solidity/contracts/structArrayStorage.js
  3. 13
      test/solidity/storageDecoder.js

@ -8,7 +8,15 @@ function Struct (memberDetails) {
} }
Struct.prototype.decodeFromStorage = function (location, storageContent) { Struct.prototype.decodeFromStorage = function (location, storageContent) {
return '<not implemented yet>' 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 module.exports = Struct

@ -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'
}
}

@ -7,6 +7,7 @@ tape('solidity', function (t) {
t.test('storage decoder', function (st) { t.test('storage decoder', function (st) {
testIntStorage(st) testIntStorage(st)
testByteStorage(st) testByteStorage(st)
testStructArrayStorage(st)
st.end() st.end()
}) })
}) })
@ -197,3 +198,15 @@ function shrinkStorage (storage) {
} }
return shrinkedStorage 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')
}

Loading…
Cancel
Save