rename location storagelocation

pull/7/head
yann300 8 years ago
parent 70a880a89c
commit 311289a049
  1. 28
      src/solidity/decodeInfo.js
  2. 2
      src/solidity/stateDecoder.js
  3. 4
      src/solidity/types/Struct.js
  4. 58
      test/solidity/storageLocation.js

@ -286,7 +286,7 @@ function parseType (type, stateDefinitions, contractName) {
*/
function computeOffsets (types, stateDefinitions, contractName) {
var ret = []
var location = {
var storagelocation = {
offset: 0,
slot: 0
}
@ -297,31 +297,31 @@ function computeOffsets (types, stateDefinitions, contractName) {
console.log('unable to retrieve decode info of ' + variable.attributes.type)
return null
}
if (location.offset + type.storageBytes > 32) {
location.slot++
location.offset = 0
if (storagelocation.offset + type.storageBytes > 32) {
storagelocation.slot++
storagelocation.offset = 0
}
ret.push({
name: variable.attributes.name,
type: type,
location: {
offset: location.offset,
slot: location.slot
storagelocation: {
offset: storagelocation.offset,
slot: storagelocation.slot
}
})
if (type.storageSlots === 1 && location.offset + type.storageBytes <= 32) {
location.offset += type.storageBytes
if (type.storageSlots === 1 && storagelocation.offset + type.storageBytes <= 32) {
storagelocation.offset += type.storageBytes
} else {
location.slot += type.storageSlots
location.offset = 0
storagelocation.slot += type.storageSlots
storagelocation.offset = 0
}
}
if (location.offset > 0) {
location.slot++
if (storagelocation.offset > 0) {
storagelocation.slot++
}
return {
typesOffsets: ret,
endLocation: location
endLocation: storagelocation
}
}

@ -12,7 +12,7 @@ function decodeState (stateVars, storageContent) {
var ret = {}
for (var k in stateVars) {
var stateVar = stateVars[k]
ret[stateVar.name] = stateVar.type.decodeFromStorage(stateVar.location, storageContent)
ret[stateVar.name] = stateVar.type.decodeFromStorage(stateVar.storagelocation, storageContent)
}
return ret
}

@ -12,8 +12,8 @@ class Struct extends RefType {
var ret = {}
this.members.map(function (item, i) {
var globalLocation = {
offset: location.offset + item.location.offset,
slot: util.add(location.slot, item.location.slot)
offset: location.offset + item.storagelocation.offset,
slot: util.add(location.slot, item.storagelocation.slot)
}
ret[item.name] = item.type.decodeFromStorage(globalLocation, storageContent)
})

@ -8,43 +8,43 @@ tape('solidity', function (t) {
t.test('storage location', function (st) {
var output = compiler.compile(contracts, 0)
var stateDec = index.solidity.stateDecoder.extractStateVariables('contractUint', output.sources)
checkLocation(st, stateDec[0].location, 0, 0)
checkLocation(st, stateDec[1].location, 1, 0)
checkLocation(st, stateDec[2].location, 2, 0)
checkLocation(st, stateDec[3].location, 3, 0)
checkLocation(st, stateDec[0].storagelocation, 0, 0)
checkLocation(st, stateDec[1].storagelocation, 1, 0)
checkLocation(st, stateDec[2].storagelocation, 2, 0)
checkLocation(st, stateDec[3].storagelocation, 3, 0)
stateDec = index.solidity.stateDecoder.extractStateVariables('contractStructAndArray', output.sources)
checkLocation(st, stateDec[0].location, 0, 0)
checkLocation(st, stateDec[1].location, 2, 0)
checkLocation(st, stateDec[2].location, 8, 0)
checkLocation(st, stateDec[0].storagelocation, 0, 0)
checkLocation(st, stateDec[1].storagelocation, 2, 0)
checkLocation(st, stateDec[2].storagelocation, 8, 0)
stateDec = index.solidity.stateDecoder.extractStateVariables('contractArray', output.sources)
checkLocation(st, stateDec[0].location, 0, 0)
checkLocation(st, stateDec[1].location, 1, 0)
checkLocation(st, stateDec[2].location, 2, 0)
checkLocation(st, stateDec[0].storagelocation, 0, 0)
checkLocation(st, stateDec[1].storagelocation, 1, 0)
checkLocation(st, stateDec[2].storagelocation, 2, 0)
stateDec = index.solidity.stateDecoder.extractStateVariables('contractSmallVariable', output.sources)
checkLocation(st, stateDec[0].location, 0, 0)
checkLocation(st, stateDec[1].location, 0, 1)
checkLocation(st, stateDec[2].location, 0, 2)
checkLocation(st, stateDec[3].location, 0, 4)
checkLocation(st, stateDec[4].location, 1, 0)
checkLocation(st, stateDec[5].location, 2, 0)
checkLocation(st, stateDec[0].storagelocation, 0, 0)
checkLocation(st, stateDec[1].storagelocation, 0, 1)
checkLocation(st, stateDec[2].storagelocation, 0, 2)
checkLocation(st, stateDec[3].storagelocation, 0, 4)
checkLocation(st, stateDec[4].storagelocation, 1, 0)
checkLocation(st, stateDec[5].storagelocation, 2, 0)
stateDec = index.solidity.stateDecoder.extractStateVariables('testSimpleStorage', output.sources)
checkLocation(st, stateDec[0].location, 0, 0)
checkLocation(st, stateDec[1].location, 1, 0)
checkLocation(st, stateDec[2].location, 2, 0)
checkLocation(st, stateDec[3].location, 3, 0)
checkLocation(st, stateDec[4].location, 4, 0)
checkLocation(st, stateDec[5].location, 8, 0)
checkLocation(st, stateDec[6].location, 9, 0)
checkLocation(st, stateDec[8].location, 17, 0)
checkLocation(st, stateDec[9].location, 17, 4)
checkLocation(st, stateDec[10].location, 17, 6)
checkLocation(st, stateDec[11].location, 17, 7)
checkLocation(st, stateDec[12].location, 18, 0)
checkLocation(st, stateDec[13].location, 21, 0)
checkLocation(st, stateDec[0].storagelocation, 0, 0)
checkLocation(st, stateDec[1].storagelocation, 1, 0)
checkLocation(st, stateDec[2].storagelocation, 2, 0)
checkLocation(st, stateDec[3].storagelocation, 3, 0)
checkLocation(st, stateDec[4].storagelocation, 4, 0)
checkLocation(st, stateDec[5].storagelocation, 8, 0)
checkLocation(st, stateDec[6].storagelocation, 9, 0)
checkLocation(st, stateDec[8].storagelocation, 17, 0)
checkLocation(st, stateDec[9].storagelocation, 17, 4)
checkLocation(st, stateDec[10].storagelocation, 17, 6)
checkLocation(st, stateDec[11].storagelocation, 17, 7)
checkLocation(st, stateDec[12].storagelocation, 18, 0)
checkLocation(st, stateDec[13].storagelocation, 21, 0)
st.end()
})

Loading…
Cancel
Save