From 222a4f8363d5765fc6f35ec79a447dd463a15814 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 14 Nov 2016 12:39:00 +0100 Subject: [PATCH] add more tests --- src/solidity/decodeInfo.js | 2 +- test/solidity/contracts.js | 40 +++++++++++++++++++++++++++++++- test/solidity/storageLocation.js | 15 ++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/solidity/decodeInfo.js b/src/solidity/decodeInfo.js index 88746b2a6c..9bbfaa9050 100644 --- a/src/solidity/decodeInfo.js +++ b/src/solidity/decodeInfo.js @@ -200,7 +200,7 @@ function Struct (type, stateDefinitions) { function getEnum (type, stateDefinitions) { for (var k in stateDefinitions) { var dec = stateDefinitions[k] - if (type === 'enum ' + dec.attributes.name) { + if (dec.attributes && dec.attributes.name && type === 'enum ' + dec.attributes.name) { return dec } } diff --git a/test/solidity/contracts.js b/test/solidity/contracts.js index 61277a8df7..7e8f9214be 100644 --- a/test/solidity/contracts.js +++ b/test/solidity/contracts.js @@ -38,5 +38,43 @@ module.exports = ` int32 i32; uint ui32; int16 i16; - } + } + + contract testSimpleStorage1 { + uint32 uibase1; + } + + contract testSimpleStorage is testSimpleStorage1 { + uint ui1; + uint ui2; + uint[1] ui3; + uint[][1][4] ui4; + + int16 i16; + + struct structDef { + uint ui; + string str; + } + + structDef structDec; + + structDef[3] arrayStructDec; + + int32 i32; + int16 i16_2; + + enum enumDef { + first, + second, + third + } + + enumDef enumDec; + bool boolean; + + uint[][2][][3] ui5; + + string _string; + } ` diff --git a/test/solidity/storageLocation.js b/test/solidity/storageLocation.js index f7d7e50636..d734eedb75 100644 --- a/test/solidity/storageLocation.js +++ b/test/solidity/storageLocation.js @@ -31,6 +31,21 @@ tape('solidity', function (t) { checkLocation(st, stateDec[4].location, 1, 0) checkLocation(st, stateDec[5].location, 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) + st.end() }) })