Permit view, pure, experimental and solc 0.4.17

pull/133/head
cgewecke 7 years ago
parent 0b5775b7e7
commit 2ecbe5efc6
  1. 6
      lib/preprocessor.js
  2. 1246
      package-lock.json
  3. 7
      package.json
  4. 23
      test/app.js
  5. 17
      test/cli/pureview.js
  6. 15
      test/sources/cli/PureView.sol

@ -16,12 +16,18 @@ function blockWrap(contract, expression) {
* and brackets them. Instrumenter needs to inject events at these locations and having * and brackets them. Instrumenter needs to inject events at these locations and having
* them pre-bracketed simplifies the process. Each time a modification is made the contract * them pre-bracketed simplifies the process. Each time a modification is made the contract
* is passed back to the parser and re-walked because all the starts and ends get shifted. * is passed back to the parser and re-walked because all the starts and ends get shifted.
*
* Also removes pure and view modifiers.
*
* @param {String} contract solidity code * @param {String} contract solidity code
* @return {String} contract * @return {String} contract
*/ */
module.exports.run = function r(contract) { module.exports.run = function r(contract) {
let keepRunning = true; let keepRunning = true;
contract = contract.replace(/ pure /, ' ');
contract = contract.replace(/ view /, ' ');
while (keepRunning) { while (keepRunning) {
const ast = SolidityParser.parse(contract); const ast = SolidityParser.parse(contract);
keepRunning = false; keepRunning = false;

1246
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -21,12 +21,10 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"commander": "^2.9.0",
"death": "^1.1.0", "death": "^1.1.0",
"ethereumjs-testrpc-sc": "4.0.2", "ethereumjs-testrpc-sc": "4.0.2",
"istanbul": "^0.4.5", "istanbul": "^0.4.5",
"keccakjs": "^0.2.1", "keccakjs": "^0.2.1",
"mkdirp": "^0.5.1",
"req-cwd": "^1.0.1", "req-cwd": "^1.0.1",
"shelljs": "^0.7.4", "shelljs": "^0.7.4",
"sol-explore": "^1.6.2", "sol-explore": "^1.6.2",
@ -43,11 +41,10 @@
"ethereumjs-tx": "^1.2.2", "ethereumjs-tx": "^1.2.2",
"ethereumjs-util": "^5.0.1", "ethereumjs-util": "^5.0.1",
"ethereumjs-vm": "https://github.com/sc-forks/ethereumjs-vm-sc.git", "ethereumjs-vm": "https://github.com/sc-forks/ethereumjs-vm-sc.git",
"istanbul": "^0.4.5",
"merkle-patricia-tree": "~2.1.2", "merkle-patricia-tree": "~2.1.2",
"mocha": "^3.1.0", "mocha": "^3.1.0",
"solc": "0.4.13", "solc": "0.4.17",
"request": "^2.81.0", "request": "^2.81.0",
"truffle": "3.4.4" "truffle": "4.0.0-beta.2"
} }
} }

@ -240,6 +240,29 @@ describe('app', () => {
collectGarbage(); collectGarbage();
}); });
it('tests use pure and view modifiers', () => {
// Directory should be clean
assert(pathExists('./coverage') === false, 'should start without: coverage');
assert(pathExists('./coverage.json') === false, 'should start without: coverage.json');
// Run script (exits 0);
mock.install('PureView.sol', 'pureview.js', config);
shell.exec(script);
assert(shell.error() === null, 'script should not error');
// Directory should have coverage report
assert(pathExists('./coverage') === true, 'script should gen coverage folder');
assert(pathExists('./coverage.json') === true, 'script should gen coverage.json');
// Coverage should be real.
// This test is tightly bound to the function names in Simple.sol
const produced = JSON.parse(fs.readFileSync('./coverage.json', 'utf8'));
const path = Object.keys(produced)[0];
assert(produced[path].fnMap['1'].name === 'isPure', 'coverage.json should map "isPure"');
assert(produced[path].fnMap['2'].name === 'isView', 'coverage.json should map "isView"');
collectGarbage();
})
it('tests require assets outside of test folder: should generate coverage, cleanup & exit(0)', () => { it('tests require assets outside of test folder: should generate coverage, cleanup & exit(0)', () => {
// Directory should be clean // Directory should be clean
assert(pathExists('./coverage') === false, 'should start without: coverage'); assert(pathExists('./coverage') === false, 'should start without: coverage');

@ -0,0 +1,17 @@
/* eslint-env node, mocha */
/* global artifacts, contract, assert */
const PureView = artifacts.require('./PureView.sol');
contract('PureView', accounts => {
it('calls a pure function', async function(){
const instance = await PureView.deployed();
const value = await instance.isPure(4,5);
});
it('calls a view function', async function(){
const instance = await PureView.deployed();
const value = await instance.isView();
})
});

@ -0,0 +1,15 @@
pragma experimental "v0.5.0";
contract PureView {
// Make sure we aren't corrupting anything with the replace
uint notpureview = 5;
function isPure(uint a, uint b) pure returns (uint){
return a * b;
}
function isView() view returns (uint){
return notpureview;
}
}
Loading…
Cancel
Save