From 53c7eaedd5f07c3e1b60aca5bf7b98142367ef37 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Tue, 28 Mar 2017 10:13:57 -0700 Subject: [PATCH] Bump solidity-parser to 0.3.0 & small fixes to accomodate it. Add tuples test. --- package.json | 2 +- parse.js | 5 ++--- test/sources/statements/tuple.sol | 7 +++++++ test/statements.js | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 test/sources/statements/tuple.sol diff --git a/package.json b/package.json index 9d82a64..25c3156 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "mkdirp": "^0.5.1", "shelljs": "^0.7.4", "sol-explore": "^1.6.2", - "solidity-parser": "0.2.0" + "solidity-parser": "0.3.0" }, "devDependencies": { "crypto-js": "^3.1.9-1", diff --git a/parse.js b/parse.js index 8c2b47c..7e92582 100644 --- a/parse.js +++ b/parse.js @@ -45,6 +45,7 @@ const instrumenter = require('./instrumenter'); 'Program', 'ReturnStatement', 'SequenceExpression', + 'StateVariableDeclaration', 'StructDeclaration', 'ThisExpression', 'ThrowStatement', @@ -188,9 +189,7 @@ parse.ContractOrLibraryStatement = function parseContractOrLibraryStatement(cont } expression.body.forEach(construct => { - if (!Array.isArray(construct)) { - parse[construct.type](contract, construct); - } + parse[construct.type](contract, construct); }); }; diff --git a/test/sources/statements/tuple.sol b/test/sources/statements/tuple.sol new file mode 100644 index 0000000..f552e79 --- /dev/null +++ b/test/sources/statements/tuple.sol @@ -0,0 +1,7 @@ +pragma solidity ^0.4.3; + +contract Test { + function a() { + var(x,y) = (10,20); + } +} \ No newline at end of file diff --git a/test/statements.js b/test/statements.js index a03f227..f8138f0 100644 --- a/test/statements.js +++ b/test/statements.js @@ -90,4 +90,24 @@ describe('generic statements', () => { done(); }).catch(done); }); + + it('should cover a tuple statement', done => { + const contract = util.getCode('statements/tuple.sol'); + const info = getInstrumentedVersion(contract, filePath); + const coverage = new CoverageMap(); + coverage.addContract(info, filePath); + + vm.execute(info.contract, 'a', []).then(events => { + const mapping = coverage.generate(events, pathPrefix); + assert.deepEqual(mapping[filePath].l, { + 5: 1, + }); + assert.deepEqual(mapping[filePath].b, {}); + assert.deepEqual(mapping[filePath].s, {}); + assert.deepEqual(mapping[filePath].f, { + 1: 1, + }); + done(); + }).catch(done); + }); });