rename decode -> parseType

pull/7/head
yann300 8 years ago
parent 5b06c33d3c
commit d53d2ad36d
  1. 4
      src/solidity/decodeInfo.js
  2. 2
      src/solidity/stateDecoder.js
  3. 34
      test/solidity/decodeInfo.js

@ -263,7 +263,7 @@ function typeClass (fullType) {
* @param {Object} stateDefinitions - all state stateDefinitions given by the AST (including struct and enum type declaration)
* @return {Object} - return the corresponding decoder or null on error
*/
function decode (type, stateDefinitions) {
function parseType (type, stateDefinitions) {
var decodeInfos = {
'address': Address,
'array': ArrayType,
@ -285,7 +285,7 @@ function decode (type, stateDefinitions) {
}
module.exports = {
decode: decode,
decode: parseType,
Uint: Uint,
Address: Address,
Bool: Bool,

@ -41,7 +41,7 @@ function extractStateVariables (contractName, sourcesList) {
for (var k in stateDefinitions) {
var variable = stateDefinitions[k]
if (variable.name === 'VariableDeclaration') {
var decoded = decodeInfo.decode(variable.attributes.type, stateDefinitions)
var decoded = decodeInfo.parseType(variable.attributes.type, stateDefinitions)
var type = new types[decoded.typeName](decoded)
if (location.offset + type.storageBytes > 32) {
location.slot++

@ -9,47 +9,47 @@ tape('solidity', function (t) {
var output = compiler.compile(contracts, 0)
var stateDec = index.solidity.astHelper.extractStateVariables('contractUint', output.sources)
var decodeInfo = index.solidity.decodeInfo.decode(stateDec[0].attributes.type, stateDec)
var decodeInfo = index.solidity.decodeInfo.parseType(stateDec[0].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 1, 'uint')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[2].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[2].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 32, 'uint')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[3].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[3].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 32, 'uint')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[4].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[4].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 16, 'bytesX')
stateDec = index.solidity.astHelper.extractStateVariables('contractStructAndArray', output.sources)
decodeInfo = index.solidity.decodeInfo.decode(stateDec[1].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[1].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 2, 32, 'struct')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[2].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[2].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 6, 32, 'array')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[3].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[3].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 2, 32, 'array')
stateDec = index.solidity.astHelper.extractStateVariables('contractArray', output.sources)
decodeInfo = index.solidity.decodeInfo.decode(stateDec[0].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[0].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 32, 'array')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[1].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[1].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 32, 'array')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[2].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[2].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 4, 32, 'array')
stateDec = index.solidity.astHelper.extractStateVariables('contractEnum', output.sources)
decodeInfo = index.solidity.decodeInfo.decode(stateDec[1].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[1].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 2, 'enum')
stateDec = index.solidity.astHelper.extractStateVariables('contractSmallVariable', output.sources)
decodeInfo = index.solidity.decodeInfo.decode(stateDec[0].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[0].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 1, 'int')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[1].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[1].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 1, 'uint')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[2].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[2].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 2, 'uint')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[3].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[3].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 4, 'int')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[4].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[4].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 32, 'uint')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[5].attributes.type, stateDec)
decodeInfo = index.solidity.decodeInfo.parseType(stateDec[5].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 2, 'int')
st.end()

Loading…
Cancel
Save